refactor(messages-service): methods for mark all and mark certain messages as read added
This commit is contained in:
parent
5b58bbcc7a
commit
97fa526c5e
|
@ -92,3 +92,50 @@ const asyncSearchMessagesInChatsAndCommunitiesTask: Task = proc(argEncoded: stri
|
||||||
"messages": response.result
|
"messages": response.result
|
||||||
}
|
}
|
||||||
arg.finish(responseJson)
|
arg.finish(responseJson)
|
||||||
|
|
||||||
|
#################################################
|
||||||
|
# Async mark all messages read
|
||||||
|
#################################################
|
||||||
|
type
|
||||||
|
AsyncMarkAllMessagesReadTaskArg = ref object of QObjectTaskArg
|
||||||
|
chatId: string
|
||||||
|
|
||||||
|
const asyncMarkAllMessagesReadTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||||
|
let arg = decode[AsyncMarkAllMessagesReadTaskArg](argEncoded)
|
||||||
|
|
||||||
|
discard status_go.markAllMessagesFromChatWithIdAsRead(arg.chatId)
|
||||||
|
|
||||||
|
let responseJson = %*{
|
||||||
|
"chatId": arg.chatId,
|
||||||
|
"error": ""
|
||||||
|
}
|
||||||
|
arg.finish(responseJson)
|
||||||
|
#################################################
|
||||||
|
|
||||||
|
#################################################
|
||||||
|
# Async mark certain messages read
|
||||||
|
#################################################
|
||||||
|
type
|
||||||
|
AsyncMarkCertainMessagesReadTaskArg = ref object of QObjectTaskArg
|
||||||
|
chatId: string
|
||||||
|
messagesIds: seq[string]
|
||||||
|
|
||||||
|
const asyncMarkCertainMessagesReadTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||||
|
let arg = decode[AsyncMarkCertainMessagesReadTaskArg](argEncoded)
|
||||||
|
|
||||||
|
let response = status_go.markCertainMessagesFromChatWithIdAsRead(arg.chatId, arg.messagesIds)
|
||||||
|
|
||||||
|
var numberOfAffectedMessages: int
|
||||||
|
discard response.result.getProp("count", numberOfAffectedMessages)
|
||||||
|
|
||||||
|
var error = ""
|
||||||
|
if(numberOfAffectedMessages == 0):
|
||||||
|
error = "no message has updated"
|
||||||
|
|
||||||
|
let responseJson = %*{
|
||||||
|
"chatId": arg.chatId,
|
||||||
|
"messagesIds": arg.messagesIds,
|
||||||
|
"error": error
|
||||||
|
}
|
||||||
|
arg.finish(responseJson)
|
||||||
|
#################################################
|
|
@ -25,6 +25,7 @@ const SIGNAL_MESSAGES_LOADED* = "new-messagesLoaded" #Once we are done with refa
|
||||||
const SIGNAL_MESSAGE_PINNED* = "new-messagePinned"
|
const SIGNAL_MESSAGE_PINNED* = "new-messagePinned"
|
||||||
const SIGNAL_MESSAGE_UNPINNED* = "new-messageUnpinned"
|
const SIGNAL_MESSAGE_UNPINNED* = "new-messageUnpinned"
|
||||||
const SIGNAL_SEARCH_MESSAGES_LOADED* = "new-searchMessagesLoaded"
|
const SIGNAL_SEARCH_MESSAGES_LOADED* = "new-searchMessagesLoaded"
|
||||||
|
const SIGNAL_MESSAGES_MARKED_AS_READ* = "new-messagesMarkedAsRead"
|
||||||
|
|
||||||
type
|
type
|
||||||
SearchMessagesLoadedArgs* = ref object of Args
|
SearchMessagesLoadedArgs* = ref object of Args
|
||||||
|
@ -40,6 +41,11 @@ type
|
||||||
chatId*: string
|
chatId*: string
|
||||||
messageId*: string
|
messageId*: string
|
||||||
|
|
||||||
|
MessagesMarkedAsReadArgs = ref object of Args
|
||||||
|
chatId*: string
|
||||||
|
allMessagesMarked*: bool
|
||||||
|
messagesIds*: seq[string]
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type Service* = ref object of QObject
|
type Service* = ref object of QObject
|
||||||
events: EventEmitter
|
events: EventEmitter
|
||||||
|
@ -283,3 +289,68 @@ QtObject:
|
||||||
caseSensitive: caseSensitive
|
caseSensitive: caseSensitive
|
||||||
)
|
)
|
||||||
self.threadpool.start(arg)
|
self.threadpool.start(arg)
|
||||||
|
|
||||||
|
proc onMarkAllMessagesRead*(self: Service, response: string) {.slot.} =
|
||||||
|
let responseObj = response.parseJson
|
||||||
|
|
||||||
|
var error: string
|
||||||
|
discard responseObj.getProp("error", error)
|
||||||
|
if(error.len > 0):
|
||||||
|
error "error: ", methodName="onMarkCertainMessagesRead", errDescription=error
|
||||||
|
return
|
||||||
|
|
||||||
|
var chatId: string
|
||||||
|
discard responseObj.getProp("chatId", chatId)
|
||||||
|
|
||||||
|
let data = MessagesMarkedAsReadArgs(chatId: chatId, allMessagesMarked: true)
|
||||||
|
self.events.emit(SIGNAL_MESSAGES_MARKED_AS_READ, data)
|
||||||
|
|
||||||
|
proc markAllMessagesRead*(self: Service, chatId: string) =
|
||||||
|
if (chatId.len == 0):
|
||||||
|
error "empty chat id", methodName="markAllMessagesRead"
|
||||||
|
return
|
||||||
|
|
||||||
|
let arg = AsyncMarkAllMessagesReadTaskArg(
|
||||||
|
tptr: cast[ByteAddress](asyncMarkAllMessagesReadTask),
|
||||||
|
vptr: cast[ByteAddress](self.vptr),
|
||||||
|
slot: "onMarkAllMessagesRead",
|
||||||
|
chatId: chatId
|
||||||
|
)
|
||||||
|
|
||||||
|
self.threadpool.start(arg)
|
||||||
|
|
||||||
|
proc onMarkCertainMessagesRead*(self: Service, response: string) {.slot.} =
|
||||||
|
let responseObj = response.parseJson
|
||||||
|
|
||||||
|
var error: string
|
||||||
|
discard responseObj.getProp("error", error)
|
||||||
|
if(error.len > 0):
|
||||||
|
error "error: ", methodName="onMarkCertainMessagesRead", errDescription=error
|
||||||
|
return
|
||||||
|
|
||||||
|
var chatId: string
|
||||||
|
discard responseObj.getProp("chatId", chatId)
|
||||||
|
|
||||||
|
var messagesIdsArr: JsonNode
|
||||||
|
var messagesIds: seq[string]
|
||||||
|
if(responseObj.getProp("messagesIds", messagesIdsArr)):
|
||||||
|
for id in messagesIdsArr:
|
||||||
|
messagesIds.add(id.getStr)
|
||||||
|
|
||||||
|
let data = MessagesMarkedAsReadArgs(chatId: chatId, allMessagesMarked: false, messagesIds: messagesIds)
|
||||||
|
self.events.emit(SIGNAL_MESSAGES_MARKED_AS_READ, data)
|
||||||
|
|
||||||
|
proc markCertainMessagesRead*(self: Service, chatId: string, messagesIds: seq[string]) =
|
||||||
|
if (chatId.len == 0):
|
||||||
|
error "empty chat id", methodName="markCertainMessagesRead"
|
||||||
|
return
|
||||||
|
|
||||||
|
let arg = AsyncMarkCertainMessagesReadTaskArg(
|
||||||
|
tptr: cast[ByteAddress](asyncMarkCertainMessagesReadTask),
|
||||||
|
vptr: cast[ByteAddress](self.vptr),
|
||||||
|
slot: "onMarkCertainMessagesRead",
|
||||||
|
chatId: chatId,
|
||||||
|
messagesIds: messagesIds
|
||||||
|
)
|
||||||
|
|
||||||
|
self.threadpool.start(arg)
|
Loading…
Reference in New Issue