refactor(@desktop/chat): loading messages on join public chat
- received new messages are now filtered by the chat id they belong to - mailserver actions are added to the log
This commit is contained in:
parent
4d042f80aa
commit
051142cf3b
|
@ -57,4 +57,3 @@ when isMainModule:
|
||||||
var args = ReadyArgs(a)
|
var args = ReadyArgs(a)
|
||||||
echo args.text, ": from [2nd] handler"
|
echo args.text, ": from [2nd] handler"
|
||||||
evts.emit("ready", ReadyArgs(text:"Hello, World"))
|
evts.emit("ready", ReadyArgs(text:"Hello, World"))
|
||||||
evts.emit("ready", ReadyArgs(text:"Hello, World"))
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ method delete*(self: Controller) =
|
||||||
method init*(self: Controller) =
|
method init*(self: Controller) =
|
||||||
self.events.on(SIGNAL_MESSAGES_LOADED) do(e:Args):
|
self.events.on(SIGNAL_MESSAGES_LOADED) do(e:Args):
|
||||||
let args = MessagesLoadedArgs(e)
|
let args = MessagesLoadedArgs(e)
|
||||||
if(self.chatId != args.chatId):
|
if(self.chatId != args.chatId or args.pinnedMessages.len == 0):
|
||||||
return
|
return
|
||||||
self.delegate.newPinnedMessagesLoaded(args.pinnedMessages)
|
self.delegate.newPinnedMessagesLoaded(args.pinnedMessages)
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,10 @@ method init*(self: Controller) =
|
||||||
self.delegate.newMessagesLoaded(args.messages, args.reactions, args.pinnedMessages)
|
self.delegate.newMessagesLoaded(args.messages, args.reactions, args.pinnedMessages)
|
||||||
|
|
||||||
self.events.on(SIGNAL_NEW_MESSAGE_RECEIVED) do(e: Args):
|
self.events.on(SIGNAL_NEW_MESSAGE_RECEIVED) do(e: Args):
|
||||||
var evArgs = MessagesArgs(e)
|
var args = MessagesArgs(e)
|
||||||
for message in evArgs.messages:
|
if(self.chatId != args.chatId):
|
||||||
|
return
|
||||||
|
for message in args.messages:
|
||||||
self.delegate.messageAdded(message)
|
self.delegate.messageAdded(message)
|
||||||
|
|
||||||
self.events.on(SIGNAL_SENDING_SUCCESS) do(e:Args):
|
self.events.on(SIGNAL_SENDING_SUCCESS) do(e:Args):
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import NimQml, Tables, json, sequtils, strutils, system, uuids, chronicles
|
import NimQml, Tables, json, sequtils, strutils, system, uuids, chronicles
|
||||||
|
|
||||||
import ./dto/mailserver as mailserver_dto
|
import ./dto/mailserver as mailserver_dto
|
||||||
|
import ../../../app/core/signals/types
|
||||||
import ../../../app/core/fleets/fleet_configuration
|
import ../../../app/core/fleets/fleet_configuration
|
||||||
import ../../../app/core/[main]
|
import ../../../app/core/[main]
|
||||||
import ../../../app/core/tasks/marathon/mailserver/events
|
import ../../../app/core/tasks/marathon/mailserver/events
|
||||||
|
@ -56,10 +57,26 @@ QtObject:
|
||||||
self.events.on("mailserver:changed") do(e: Args):
|
self.events.on("mailserver:changed") do(e: Args):
|
||||||
let receivedData = MailserverArgs(e)
|
let receivedData = MailserverArgs(e)
|
||||||
let peer = receivedData.peer
|
let peer = receivedData.peer
|
||||||
debug "Mailserver changed to ", peer
|
info "mailserver changed to ", peer
|
||||||
let data = ActiveMailserverChangedArgs(nodeAddress: peer)
|
let data = ActiveMailserverChangedArgs(nodeAddress: peer)
|
||||||
self.events.emit(SIGNAL_ACTIVE_MAILSERVER_CHANGED, data)
|
self.events.emit(SIGNAL_ACTIVE_MAILSERVER_CHANGED, data)
|
||||||
|
|
||||||
|
self.events.on(SignalType.HistoryRequestStarted.event) do(e: Args):
|
||||||
|
let h = HistoryRequestStartedSignal(e)
|
||||||
|
info "history request started", requestId=h.requestId, numBatches=h.numBatches
|
||||||
|
|
||||||
|
self.events.on(SignalType.HistoryRequestBatchProcessed.event) do(e: Args):
|
||||||
|
let h = HistoryRequestBatchProcessedSignal(e)
|
||||||
|
info "history batch processed", requestId=h.requestId, batchIndex=h.batchIndex
|
||||||
|
|
||||||
|
self.events.on(SignalType.HistoryRequestCompleted.event) do(e: Args):
|
||||||
|
let h = HistoryRequestCompletedSignal(e)
|
||||||
|
info "history request completed", requestId=h.requestId
|
||||||
|
|
||||||
|
self.events.on(SignalType.HistoryRequestFailed.event) do(e: Args):
|
||||||
|
let h = HistoryRequestFailedSignal(e)
|
||||||
|
info "history request failed", requestId=h.requestId, errorMessage=h.errorMessage
|
||||||
|
|
||||||
proc initMailservers(self: Service) =
|
proc initMailservers(self: Service) =
|
||||||
let wakuVersion = self.nodeConfigurationService.getWakuVersion()
|
let wakuVersion = self.nodeConfigurationService.getWakuVersion()
|
||||||
let isWakuV2 = wakuVersion == WAKU_VERSION_2
|
let isWakuV2 = wakuVersion == WAKU_VERSION_2
|
||||||
|
|
|
@ -8,6 +8,7 @@ import status/statusgo_backend_new/messages as status_go
|
||||||
import ./dto/message as message_dto
|
import ./dto/message as message_dto
|
||||||
import ./dto/pinned_message as pinned_msg_dto
|
import ./dto/pinned_message as pinned_msg_dto
|
||||||
import ./dto/reaction as reaction_dto
|
import ./dto/reaction as reaction_dto
|
||||||
|
import ../chat/dto/chat as chat_dto
|
||||||
|
|
||||||
export message_dto
|
export message_dto
|
||||||
export pinned_msg_dto
|
export pinned_msg_dto
|
||||||
|
@ -33,6 +34,7 @@ include async_tasks
|
||||||
|
|
||||||
type
|
type
|
||||||
MessagesArgs* = ref object of Args
|
MessagesArgs* = ref object of Args
|
||||||
|
chatId*: string
|
||||||
messages*: seq[MessageDto]
|
messages*: seq[MessageDto]
|
||||||
|
|
||||||
MessagesLoadedArgs* = ref object of Args
|
MessagesLoadedArgs* = ref object of Args
|
||||||
|
@ -85,8 +87,13 @@ QtObject:
|
||||||
var receivedData = MessageSignal(e)
|
var receivedData = MessageSignal(e)
|
||||||
|
|
||||||
# Handling messages updates
|
# Handling messages updates
|
||||||
if (receivedData.messages.len > 0):
|
if (receivedData.messages.len > 0 and receivedData.chats.len > 0):
|
||||||
self.events.emit(SIGNAL_NEW_MESSAGE_RECEIVED, MessagesArgs(messages: receivedData.messages))
|
# We included `chats` in this condition cause that's the form how `status-go` sends updates.
|
||||||
|
# The first element from the `receivedData.chats` array contains details about the chat a messages received in
|
||||||
|
# `receivedData.messages` refer to.
|
||||||
|
let chatId = receivedData.chats[0].id
|
||||||
|
let data = MessagesArgs(chatId: chatId, messages: receivedData.messages)
|
||||||
|
self.events.emit(SIGNAL_NEW_MESSAGE_RECEIVED, data)
|
||||||
# Handling pinned messages updates
|
# Handling pinned messages updates
|
||||||
if (receivedData.pinnedMessages.len > 0):
|
if (receivedData.pinnedMessages.len > 0):
|
||||||
for pm in receivedData.pinnedMessages:
|
for pm in receivedData.pinnedMessages:
|
||||||
|
@ -299,33 +306,36 @@ QtObject:
|
||||||
result.error = e.msg
|
result.error = e.msg
|
||||||
error "error: ", methodName="getDetailsForMessage", errName = e.name, errDesription = e.msg
|
error "error: ", methodName="getDetailsForMessage", errName = e.name, errDesription = e.msg
|
||||||
|
|
||||||
proc finishAsyncSearchMessagesWithError*(self: Service, errorMessage: string) =
|
proc finishAsyncSearchMessagesWithError*(self: Service, chatId, errorMessage: string) =
|
||||||
error "error: ", methodName="onAsyncSearchMessages", errDescription = errorMessage
|
error "error: ", methodName="onAsyncSearchMessages", errDescription = errorMessage
|
||||||
self.events.emit(SIGNAL_SEARCH_MESSAGES_LOADED, MessagesArgs())
|
self.events.emit(SIGNAL_SEARCH_MESSAGES_LOADED, MessagesArgs(chatId: chatId))
|
||||||
|
|
||||||
proc onAsyncSearchMessages*(self: Service, response: string) {.slot.} =
|
proc onAsyncSearchMessages*(self: Service, response: string) {.slot.} =
|
||||||
let responseObj = response.parseJson
|
let responseObj = response.parseJson
|
||||||
if (responseObj.kind != JObject):
|
if (responseObj.kind != JObject):
|
||||||
self.finishAsyncSearchMessagesWithError("search messages response is not an json object")
|
self.finishAsyncSearchMessagesWithError("", "search messages response is not an json object")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
var chatId: string
|
||||||
|
discard responseObj.getProp("chatId", chatId)
|
||||||
|
|
||||||
var messagesObj: JsonNode
|
var messagesObj: JsonNode
|
||||||
if (not responseObj.getProp("messages", messagesObj)):
|
if (not responseObj.getProp("messages", messagesObj)):
|
||||||
self.finishAsyncSearchMessagesWithError("search messages response doesn't contain messages property")
|
self.finishAsyncSearchMessagesWithError(chatId, "search messages response doesn't contain messages property")
|
||||||
return
|
return
|
||||||
|
|
||||||
var messagesArray: JsonNode
|
var messagesArray: JsonNode
|
||||||
if (not messagesObj.getProp("messages", messagesArray)):
|
if (not messagesObj.getProp("messages", messagesArray)):
|
||||||
self.finishAsyncSearchMessagesWithError("search messages response doesn't contain messages array")
|
self.finishAsyncSearchMessagesWithError(chatId, "search messages response doesn't contain messages array")
|
||||||
return
|
return
|
||||||
|
|
||||||
if (messagesArray.kind != JArray):
|
if (messagesArray.kind != JArray):
|
||||||
self.finishAsyncSearchMessagesWithError("expected messages json array is not of JArray type")
|
self.finishAsyncSearchMessagesWithError(chatId, "expected messages json array is not of JArray type")
|
||||||
return
|
return
|
||||||
|
|
||||||
var messages = map(messagesArray.getElems(), proc(x: JsonNode): MessageDto = x.toMessageDto())
|
var messages = map(messagesArray.getElems(), proc(x: JsonNode): MessageDto = x.toMessageDto())
|
||||||
|
|
||||||
let data = MessagesArgs(messages: messages)
|
let data = MessagesArgs(chatId: chatId, messages: messages)
|
||||||
self.events.emit(SIGNAL_SEARCH_MESSAGES_LOADED, data)
|
self.events.emit(SIGNAL_SEARCH_MESSAGES_LOADED, data)
|
||||||
|
|
||||||
proc asyncSearchMessages*(self: Service, chatId: string, searchTerm: string, caseSensitive: bool) =
|
proc asyncSearchMessages*(self: Service, chatId: string, searchTerm: string, caseSensitive: bool) =
|
||||||
|
|
Loading…
Reference in New Issue