fix(Communities): ensure community chats exist in memory upon spectating

When a community link is shared with a user and that user visits that community, it turns out that the chat objects for that community have not been created yet.

This results in chat data being malformed/non-existent until another message signal is processed that updates the chats in memory. This update can someimes occur earlier, sometimes later, which is why the issue isn't always reproducible.

This commit ensures we're loading chats from status-go again upon spectating, to ensure they exist in memory when we try to access the data in the UI.

Closes #8361
This commit is contained in:
Pascal Precht 2023-02-09 13:05:38 +01:00 committed by Jonathan Rainville
parent 723bc4f387
commit a97d32346a
2 changed files with 31 additions and 19 deletions

View File

@ -129,6 +129,7 @@ QtObject:
# Forward declarations
proc updateOrAddChat*(self: Service, chat: ChatDto)
proc hydrateChats*(self: Service, data: JsonNode)
proc updateOrAddChannelGroup*(self: Service, channelGroup: ChannelGroupDto)
proc doConnect(self: Service) =
@ -163,6 +164,14 @@ QtObject:
proc getChannelGroups*(self: Service): seq[ChannelGroupDto] =
return toSeq(self.channelGroups.values)
proc loadChats*(self: Service) =
try:
let response = status_chat.getChats()
self.hydrateChats(response.result)
except Exception as e:
let errDesription = e.msg
error "error: ", errDesription
proc asyncGetChats*(self: Service) =
let arg = AsyncGetChatsTaskArg(
tptr: cast[ByteAddress](asyncGetChatsTask),
@ -176,15 +185,9 @@ QtObject:
if (y[1].channelGroupType == Personal): return 1
return 0
proc onAsyncGetChatsResponse*(self: Service, response: string) {.slot.} =
try:
let rpcResponseObj = response.parseJson
if(rpcResponseObj["channelGroups"].kind == JNull):
raise newException(RpcException, "No channel groups returned")
proc hydrateChats(self: Service, data: JsonNode) =
var chats: seq[ChatDto] = @[]
for (sectionId, section) in rpcResponseObj["channelGroups"].pairs:
for (sectionId, section) in data.pairs:
var channelGroup = section.toChannelGroupDto()
channelGroup.id = sectionId
self.channelGroups[sectionId] = channelGroup
@ -202,6 +205,14 @@ QtObject:
else:
self.chats[chat.id] = chat
proc onAsyncGetChatsResponse*(self: Service, response: string) {.slot.} =
try:
let rpcResponseObj = response.parseJson
if(rpcResponseObj["channelGroups"].kind == JNull):
raise newException(RpcException, "No channel groups returned")
self.hydrateChats(rpcResponseObj["channelGroups"])
self.events.emit(SIGNAL_CHATS_LOADED, ChannelGroupsArgs(channelGroups: self.getChannelGroups()))
except Exception as e:
let errDesription = e.msg

View File

@ -702,6 +702,7 @@ QtObject:
updatedCommunity.settings = communitySettings
self.allCommunities[communityId] = updatedCommunity
self.chatService.loadChats()
for k, chat in updatedCommunity.chats:
let fullChatId = communityId & chat.id