From 6b9b5f20a807e38c3b76f3d81807d2874baae4ed Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 20 Jun 2022 13:39:40 +0200 Subject: [PATCH] fix(@community): Fix community join bubble fixes #6133 When restarting the app, the community is not in the list and data needs to be requested --- .../service/community/async_tasks.nim | 3 +-- src/app_service/service/community/service.nim | 23 +++++++++------- src/backend/communities.nim | 2 +- ui/app/AppLayouts/Chat/stores/RootStore.qml | 4 +++ .../views/chat/InvitationBubbleView.qml | 27 +++++++++++++------ 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/app_service/service/community/async_tasks.nim b/src/app_service/service/community/async_tasks.nim index 486b58eca1..6492d6330c 100644 --- a/src/app_service/service/community/async_tasks.nim +++ b/src/app_service/service/community/async_tasks.nim @@ -8,5 +8,4 @@ type const asyncRequestCommunityInfoTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = let arg = decode[AsyncRequestCommunityInfoTaskArg](argEncoded) let response = status_go.requestCommunityInfo(arg.communityId) - - arg.finish(response) + arg.finish(response) \ No newline at end of file diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index a22c38769e..be98f12491 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -132,6 +132,7 @@ QtObject: chatService: chat_service.Service ): Service = result = Service() + result.QObject.setup result.events = events result.threadpool = threadpool result.chatService = chatService @@ -938,24 +939,26 @@ QtObject: error "Error reordering category channel", msg = e.msg, communityId, categoryId, position - proc asyncActivityNotificationLoad*(self: Service, communityId: string) = - let arg = AsyncRequestCommunityInfoTaskArg( - tptr: cast[ByteAddress](asyncRequestCommunityInfoTask), - vptr: cast[ByteAddress](self.vptr), - slot: "asyncCommunityInfoLoaded", - communityId: communityId - ) - self.threadpool.start(arg) - proc asyncCommunityInfoLoaded*(self: Service, rpcResponse: string) {.slot.} = let rpcResponseObj = rpcResponse.parseJson if (rpcResponseObj{"error"}.kind != JNull): let error = Json.decode($rpcResponseObj["error"], RpcError) error "Error requesting community info", msg = error.message + return + + let community = rpcResponseObj{"result"}.toCommunityDto() + self.allCommunities[community.id] = community + self.events.emit(SIGNAL_COMMUNITY_DATA_IMPORTED, CommunityArgs(community: community)) proc requestCommunityInfo*(self: Service, communityId: string) = try: - self.asyncActivityNotificationLoad(communityId) + let arg = AsyncRequestCommunityInfoTaskArg( + tptr: cast[ByteAddress](asyncRequestCommunityInfoTask), + vptr: cast[ByteAddress](self.vptr), + slot: "asyncCommunityInfoLoaded", + communityId: communityId + ) + self.threadpool.start(arg) except Exception as e: error "Error requesting community info", msg = e.msg, communityId diff --git a/src/backend/communities.nim b/src/backend/communities.nim index 47413c4647..bde2c25995 100644 --- a/src/backend/communities.nim +++ b/src/backend/communities.nim @@ -232,7 +232,7 @@ proc deleteCommunityCategory*( }]) proc requestCommunityInfo*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} = - result = callPrivateRPC("requestCommunityInfoFromMailserverAsync".prefix, %*[communityId]) + result = callPrivateRPC("requestCommunityInfoFromMailserver".prefix, %*[communityId]) proc importCommunity*(communityKey: string): RpcResponse[JsonNode] {.raises: [Exception].} = result = callPrivateRPC("importCommunity".prefix, %*[communityKey]) diff --git a/ui/app/AppLayouts/Chat/stores/RootStore.qml b/ui/app/AppLayouts/Chat/stores/RootStore.qml index c8c03f5173..b9cc33c246 100644 --- a/ui/app/AppLayouts/Chat/stores/RootStore.qml +++ b/ui/app/AppLayouts/Chat/stores/RootStore.qml @@ -359,6 +359,10 @@ QtObject { return communitiesList.getSectionByIdJson(id) } + function requestCommunityInfo(id) { + communitiesModuleInst.requestCommunityInfo(id) + } + function getLinkTitleAndCb(link) { const result = { title: "Status", diff --git a/ui/imports/shared/views/chat/InvitationBubbleView.qml b/ui/imports/shared/views/chat/InvitationBubbleView.qml index 970c0c26c8..5b9b836bab 100644 --- a/ui/imports/shared/views/chat/InvitationBubbleView.qml +++ b/ui/imports/shared/views/chat/InvitationBubbleView.qml @@ -26,7 +26,9 @@ Item { function getCommunity() { try { const communityJson = root.store.getSectionByIdJson(communityId) + if (!communityJson) { + root.store.requestCommunityInfo(communityId) return null } @@ -42,14 +44,23 @@ Item { root.invitedCommunity = getCommunity() } - Connections { - target: root.store.communitiesModuleInst - onCommunityChanged: function (communityId) { - if (communityId === root.communityId) { - root.invitedCommunity = getCommunity() - } - } - } + Connections { + target: root.store.communitiesModuleInst + onCommunityChanged: function (communityId) { + if (communityId === root.communityId) { + root.invitedCommunity = getCommunity() + } + } + } + + Connections { + target: root.store.communitiesModuleInst + onCommunityAdded: function (communityId) { + if (communityId === root.communityId) { + root.invitedCommunity = getCommunity() + } + } + } Component { id: communityIntroDialog