fix(Chat): Replace chat fetching in CR flows with message parsing (#13361)
Close #11854
This commit is contained in:
parent
1ef6c53fc6
commit
752eda50a4
|
@ -55,8 +55,9 @@ type
|
|||
RpcResponseArgs* = ref object of Args
|
||||
response*: RpcResponse[JsonNode]
|
||||
|
||||
ReloadOneToOneArgs* = ref object of Args
|
||||
sectionId*: string
|
||||
AppendChatMessagesArgs* = ref object of Args
|
||||
chatId*: string
|
||||
messages*: JsonNode
|
||||
|
||||
# Signals which may be emitted by this service:
|
||||
const SIGNAL_ENS_RESOLVED* = "ensResolved"
|
||||
|
@ -80,7 +81,7 @@ const SIGNAL_CONTACT_VERIFICATION_ACCEPTED* = "contactVerificationRequestAccepte
|
|||
const SIGNAL_CONTACT_VERIFICATION_ADDED* = "contactVerificationRequestAdded"
|
||||
const SIGNAL_CONTACT_VERIFICATION_UPDATED* = "contactVerificationRequestUpdated"
|
||||
const SIGNAL_CONTACT_INFO_REQUEST_FINISHED* = "contactInfoRequestFinished"
|
||||
const SIGNAL_RELOAD_ONE_TO_ONE_CHAT* = "reloadOneToOneChat"
|
||||
const SIGNAL_APPEND_CHAT_MESSAGES* = "appendChatMessages"
|
||||
|
||||
type
|
||||
ContactsGroup* {.pure.} = enum
|
||||
|
@ -470,7 +471,10 @@ QtObject:
|
|||
return
|
||||
|
||||
self.parseContactsResponse(response)
|
||||
self.events.emit(SIGNAL_RELOAD_ONE_TO_ONE_CHAT, ReloadOneToOneArgs(sectionId: publicKey))
|
||||
self.events.emit(SIGNAL_APPEND_CHAT_MESSAGES, AppendChatMessagesArgs(
|
||||
chatId: publicKey,
|
||||
messages: response.result{"messages"}
|
||||
))
|
||||
checkAndEmitACNotificationsFromResponse(self.events, response.result{"activityCenterNotifications"})
|
||||
|
||||
except Exception as e:
|
||||
|
@ -490,7 +494,10 @@ QtObject:
|
|||
return
|
||||
|
||||
self.parseContactsResponse(response)
|
||||
self.events.emit(SIGNAL_RELOAD_ONE_TO_ONE_CHAT, ReloadOneToOneArgs(sectionId: publicKey))
|
||||
self.events.emit(SIGNAL_APPEND_CHAT_MESSAGES, AppendChatMessagesArgs(
|
||||
chatId: publicKey,
|
||||
messages: response.result{"messages"}
|
||||
))
|
||||
checkAndEmitACNotificationsFromResponse(self.events, response.result{"activityCenterNotifications"})
|
||||
|
||||
except Exception as e:
|
||||
|
@ -556,7 +563,10 @@ QtObject:
|
|||
error "error removing contact ", msg = response.error.message
|
||||
return
|
||||
|
||||
self.events.emit(SIGNAL_RELOAD_ONE_TO_ONE_CHAT, ReloadOneToOneArgs(sectionId: publicKey))
|
||||
self.events.emit(SIGNAL_APPEND_CHAT_MESSAGES, AppendChatMessagesArgs(
|
||||
chatId: publicKey,
|
||||
messages: response.result{"messages"}
|
||||
))
|
||||
self.parseContactsResponse(response)
|
||||
checkAndEmitACNotificationsFromResponse(self.events, response.result{"activityCenterNotifications"})
|
||||
|
||||
|
|
|
@ -398,10 +398,20 @@ QtObject:
|
|||
let data = EnvelopeExpiredArgs(messagesIds: receivedData.messageIds)
|
||||
self.events.emit(SIGNAL_ENVELOPE_EXPIRED, data)
|
||||
|
||||
self.events.on(SIGNAL_RELOAD_ONE_TO_ONE_CHAT) do(e: Args):
|
||||
let args = ReloadOneToOneArgs(e)
|
||||
self.resetMessageCursor(args.sectionId)
|
||||
self.asyncLoadMoreMessagesForChat(args.sectionId)
|
||||
self.events.on(SIGNAL_APPEND_CHAT_MESSAGES) do(e: Args):
|
||||
let args = AppendChatMessagesArgs(e)
|
||||
|
||||
if args.messages != nil and args.messages.kind != JNull:
|
||||
var messages: seq[MessageDto]
|
||||
messages = map(args.messages.getElems(), proc(x: JsonNode): MessageDto = x.toMessageDto())
|
||||
|
||||
self.bulkReplacePubKeysWithDisplayNames(messages)
|
||||
|
||||
self.events.emit(SIGNAL_MESSAGES_LOADED, MessagesLoadedArgs(
|
||||
chatId: args.chatId,
|
||||
messages: messages,
|
||||
reactions: @[],
|
||||
))
|
||||
|
||||
self.events.on(SignalType.Message.event) do(e: Args):
|
||||
var receivedData = MessageSignal(e)
|
||||
|
|
Loading…
Reference in New Issue