From cc1a89efefac83245af3fe3297f2e9ed85b53bf8 Mon Sep 17 00:00:00 2001 From: Pascal Precht <445106+0x-r4bbit@users.noreply.github.com> Date: Thu, 16 Mar 2023 11:58:39 +0100 Subject: [PATCH] fix(JoinCommunityView): update amIMember state when kicked and joined Also add handlers to JoinCommunityView for requesting and cancelling requests. These will be extended in follow up commits to included authentication modals --- src/app/modules/main/chat_section/controller.nim | 9 +++++++++ src/app/modules/main/chat_section/io_interface.nim | 6 ++++++ src/app/modules/main/chat_section/module.nim | 6 ++++++ src/app_service/service/community/service.nim | 3 +++ ui/app/AppLayouts/Chat/ChatLayout.qml | 7 +++++++ 5 files changed, 31 insertions(+) diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index 38e59ae2bf..3e08ae9606 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -253,6 +253,15 @@ proc init*(self: Controller) = self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e: Args): self.delegate.onWalletAccountTokensRebuilt() + self.events.on(SIGNAL_COMMUNITY_KICKED) do (e: Args): + let args = CommunityArgs(e) + if (args.community.id == self.sectionId): + self.delegate.onKickedFromCommunity() + + self.events.on(SIGNAL_COMMUNITY_JOINED) do (e: Args): + let args = CommunityArgs(e) + if (args.community.id == self.sectionId): + self.delegate.onJoinedCommunity() self.events.on(SIGNAL_CONTACT_NICKNAME_CHANGED) do(e: Args): var args = ContactArgs(e) diff --git a/src/app/modules/main/chat_section/io_interface.nim b/src/app/modules/main/chat_section/io_interface.nim index 8988a66ca7..94a83f250e 100644 --- a/src/app/modules/main/chat_section/io_interface.nim +++ b/src/app/modules/main/chat_section/io_interface.nim @@ -358,3 +358,9 @@ method onCommunityTokenMetadataAdded*(self: AccessInterface, communityId: string method onWalletAccountTokensRebuilt*(self: AccessInterface) = raise newException(ValueError, "No implementation available") + +method onKickedFromCommunity*(self: AccessInterface) = + raise newException(ValueError, "No implementation available") + +method onJoinedCommunity*(self: AccessInterface) = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index e8467d4620..89ac881db1 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -811,6 +811,12 @@ method onCommunityTokenMetadataAdded*(self: Module, communityId: string, tokenMe if tokenMetadata.tokenType == community_dto.TokenType.ERC20 and not self.view.tokenListModel().hasItem(tokenMetadata.symbol): self.view.tokenListModel.addItems(@[tokenListItem]) +method onKickedFromCommunity*(self: Module) = + self.view.setAmIMember(false) + +method onJoinedCommunity*(self: Module) = + self.view.setAmIMember(true) + method onMarkAllMessagesRead*(self: Module, chatId: string) = self.updateBadgeNotifications(chatId, hasUnreadMessages=false, unviewedMentionsCount=0) let chatDetails = self.controller.getChatDetails(chatId) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index 3b2a6a1cc6..a5bed7447d 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -134,6 +134,7 @@ const SIGNAL_COMMUNITY_CHANNEL_CATEGORY_CHANGED* = "communityChannelCategoryChan const SIGNAL_COMMUNITY_MEMBER_APPROVED* = "communityMemberApproved" const SIGNAL_COMMUNITY_MEMBER_REMOVED* = "communityMemberRemoved" const SIGNAL_COMMUNITY_MEMBERS_CHANGED* = "communityMembersChanged" +const SIGNAL_COMMUNITY_KICKED* = "communityKicked" const SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY* = "newRequestToJoinCommunity" const SIGNAL_REQUEST_TO_JOIN_COMMUNITY_CANCELED* = "requestToJoinCommunityCanceled" const SIGNAL_CURATED_COMMUNITY_FOUND* = "curatedCommunityFound" @@ -576,6 +577,8 @@ QtObject: self.events.emit(SIGNAL_COMMUNITY_JOINED, CommunityArgs(community: community, fromUserAction: false)) self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[community])) + if wasJoined and not community.joined and not community.isMember: + self.events.emit(SIGNAL_COMMUNITY_KICKED, CommunityArgs(community: community)) except Exception as e: error "Error handling community updates", msg = e.msg, communities, updatedChats, removedChats diff --git a/ui/app/AppLayouts/Chat/ChatLayout.qml b/ui/app/AppLayouts/Chat/ChatLayout.qml index 93ca68045e..8635a7ae6b 100644 --- a/ui/app/AppLayouts/Chat/ChatLayout.qml +++ b/ui/app/AppLayouts/Chat/ChatLayout.qml @@ -66,6 +66,13 @@ StackLayout { assetsModel: root.rootStore.assetsModel collectiblesModel: root.rootStore.collectiblesModel isInvitationPending: root.rootStore.isCommunityRequestPending(communityData.id) + onRevealAddressClicked: { + root.rootStore.requestToJoinCommunity(communityData.id, root.rootStore.userProfileInst.name) + } + onInvitationPendingClicked: { + root.rootStore.cancelPendingRequest(communityData.id) + joinCommunityView.isInvitationPending = root.rootStore.isCommunityRequestPending(communityData.id) + } Connections { target: root.rootStore.communitiesModuleInst