From 7421967d96aa09845fa47cf0e6496e788ac8ceee Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Tue, 25 Jan 2022 19:39:41 +0100 Subject: [PATCH] fix(@desktop/chat-content): [base_bc] can't select a community channel Fixes #4538 --- .../chat_section/chat_content/controller.nim | 2 +- .../module_access_interface.nim | 3 + .../module_controller_delegate_interface.nim | 5 +- .../modules/main/chat_section/controller.nim | 4 +- src/app_service/service/community/service.nim | 96 ++++++------------- 5 files changed, 38 insertions(+), 72 deletions(-) diff --git a/src/app/modules/main/chat_section/chat_content/controller.nim b/src/app/modules/main/chat_section/chat_content/controller.nim index 444b112753..4374a27854 100644 --- a/src/app/modules/main/chat_section/chat_content/controller.nim +++ b/src/app/modules/main/chat_section/chat_content/controller.nim @@ -115,7 +115,7 @@ method init*(self: Controller) = self.events.on(SIGNAL_COMMUNITY_CHANNEL_EDITED) do(e:Args): let args = CommunityChatArgs(e) - if(args.communityId != self.sectionId or self.chatId != args.chat.id or not self.belongsToCommunity): + if(args.chat.communityId != self.sectionId or args.chat.id != self.chatId): return self.delegate.onChatEdited(args.chat) diff --git a/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_access_interface.nim b/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_access_interface.nim index ef768276d9..2155623e8f 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_access_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_access_interface.nim @@ -10,4 +10,7 @@ method isLoaded*(self: AccessInterface): bool {.base.} = raise newException(ValueError, "No implementation available") method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} = + raise newException(ValueError, "No implementation available") + +method updateChatIdentifier*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_controller_delegate_interface.nim b/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_controller_delegate_interface.nim index 456d9144a7..a177edeb2a 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_controller_delegate_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/private_interfaces/module_controller_delegate_interface.nim @@ -35,8 +35,5 @@ method updateContactDetails*(self: AccessInterface, contactId: string) {.base.} method onMessageEdited*(self: AccessInterface, message: MessageDto) {.base.} = raise newException(ValueError, "No implementation available") -method updateChatIdentifier*(self: AccessInterface) {.base.} = - raise newException(ValueError, "No implementation available") - method setLoadingHistoryMessagesInProgress*(self: AccessInterface, isLoading: bool) {.base.} = - raise newException(ValueError, "No implementation available") + raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index ba98c74524..b30ff2556c 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -88,7 +88,7 @@ method init*(self: Controller) = if (self.isCommunitySection): self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args): let args = CommunityChatArgs(e) - if (args.communityId == self.sectionId): + if (args.chat.communityId == self.sectionId): self.chatService.updateOrAddChat(args.chat) self.delegate.addNewChat( args.chat, @@ -109,7 +109,7 @@ method init*(self: Controller) = self.events.on(SIGNAL_COMMUNITY_CHANNEL_EDITED) do(e:Args): let args = CommunityChatArgs(e) - if (args.communityId == self.sectionId): + if (args.chat.communityId == self.sectionId): self.chatService.updateOrAddChat(args.chat) self.delegate.onCommunityChannelEdited(args.chat) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index f477fe550d..c812dc711e 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -22,7 +22,6 @@ type communities*: seq[CommunityDto] CommunityChatArgs* = ref object of Args - communityId*: string chat*: ChatDto CommunityIdArgs* = ref object of Args @@ -100,13 +99,9 @@ QtObject: # Handling community updates if (receivedData.communities.len > 0): # Channel added removed is notified in the chats param - if (receivedData.chats.len > 0): - self.handleCommunityUpdates(receivedData.communities, receivedData.chats) + self.handleCommunityUpdates(receivedData.communities, receivedData.chats) - self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: receivedData.communities)) - - self.events.on(SignalType.Message.event) do(e:Args): - var receivedData = MessageSignal(e) + # Handling membership requests if(receivedData.membershipRequests.len > 0): for membershipRequest in receivedData.membershipRequests: if (not self.joinedCommunities.contains(membershipRequest.communityId)): @@ -120,6 +115,7 @@ QtObject: proc mapChatToChatDto(chat: Chat, communityId: string): ChatDto = result = ChatDto() result.id = chat.id + result.communityId = communityId result.name = chat.name result.chatType = ChatType.CommunityChat result.color = chat.color @@ -149,6 +145,7 @@ QtObject: return let prev_community = self.joinedCommunities[community.id] + self.joinedCommunities[community.id] = community # channel was added if(community.chats.len > prev_community.chats.len): @@ -160,22 +157,21 @@ QtObject: chat_to_be_added.id = community.id&chat.id chat_to_be_added.color = updated_chat.color - self.events.emit( - SIGNAL_COMMUNITY_CHANNEL_CREATED, - CommunityChatArgs(communityId: community.id, chat: mapChatToChatDto(chat_to_be_added, community.id))) + let data = CommunityChatArgs(chat: mapChatToChatDto(chat_to_be_added, community.id)) + self.events.emit(SIGNAL_COMMUNITY_CHANNEL_CREATED, data) # channel was removed elif(community.chats.len < prev_community.chats.len): for prv_chat in prev_community.chats: if findIndexById(prv_chat.id, community.chats) == -1: - self.events.emit(SIGNAL_COMMUNITY_CHANNEL_DELETED, CommunityChatIdArgs(communityId: community.id, chatId: community.id&prv_chat.id)) + self.events.emit(SIGNAL_COMMUNITY_CHANNEL_DELETED, CommunityChatIdArgs(communityId: community.id, + chatId: community.id&prv_chat.id)) # some property has changed else: for chat in community.chats: # id is present if findIndexById(chat.id, prev_community.chats) == -1: - error "error: chat not present" - return + continue # but something is different for prev_chat in prev_community.chats: @@ -184,7 +180,8 @@ QtObject: # Handle position changes if(chat.id == prev_chat.id and chat.position != prev_chat.position): - self.events.emit(SIGNAL_COMMUNITY_CHANNEL_REORDERED, CommunityChatOrderArgs(communityId: community.id, chatId: community.id&chat.id, categoryId: chat.categoryId, position: chat.position)) + self.events.emit(SIGNAL_COMMUNITY_CHANNEL_REORDERED, CommunityChatOrderArgs(communityId: community.id, + chatId: community.id&chat.id, categoryId: chat.categoryId, position: chat.position)) # Handle name/description changes if(chat.id == prev_chat.id and (chat.name != prev_chat.name or chat.description != prev_chat.description)): @@ -195,11 +192,10 @@ QtObject: if(updated_chat.color != ""): chat_to_be_edited.color = updated_chat.color - self.events.emit( - SIGNAL_COMMUNITY_CHANNEL_EDITED, - CommunityChatArgs(communityId: community.id, chat: mapChatToChatDto(chat_to_be_edited, community.id))) + let data = CommunityChatArgs(chat: mapChatToChatDto(chat_to_be_edited, community.id)) + self.events.emit(SIGNAL_COMMUNITY_CHANNEL_EDITED, data) - self.joinedCommunities[community.id].chats = community.chats + self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: communities)) proc init*(self: Service) = self.doConnect() @@ -458,22 +454,15 @@ QtObject: try: let response = status_go.createCommunityChannel(communityId, name, description) - if response.error != nil: + if not response.error.isNil: let error = Json.decode($response.error, RpcError) raise newException(RpcException, "Error creating community channel: " & error.message) + + if response.result.isNil or response.result.kind == JNull: + error "response is invalid", methodName="createCommunityChannel" - if response.result != nil and response.result.kind != JNull: - let chat = response.result["chats"][0].toChat() - - # update the joined communities - self.joinedCommunities[communityId].chats.add(chat) - - self.events.emit(SIGNAL_COMMUNITY_CHANNEL_CREATED, CommunityChatArgs( - communityId: communityId, - chat: mapChatToChatDto(chat, communityId)) - ) except Exception as e: - error "Error creating community channel", msg = e.msg, communityId, name, description + error "Error creating community channel", msg = e.msg, communityId, name, description, methodName="createCommunityChannel" proc editCommunityChannel*( self: Service, @@ -496,17 +485,11 @@ QtObject: let error = Json.decode($response.error, RpcError) raise newException(RpcException, "Error editing community channel: " & error.message) - if response.result != nil and response.result.kind != JNull: - let chat = response.result["chats"][0].toChat() + if response.result.isNil or response.result.kind == JNull: + error "response is invalid", methodName="editCommunityChannel" - # update the joined communities - let idx = self.joinedCommunities[communityId].chats.find(chat) - if(idx != -1): - self.joinedCommunities[communityId].chats[idx] = chat - - self.events.emit(SIGNAL_COMMUNITY_CHANNEL_EDITED, CommunityChatArgs(chat: mapChatToChatDto(chat, communityId))) except Exception as e: - error "Error editing community channel", msg = e.msg, communityId, channelId + error "Error editing community channel", msg = e.msg, communityId, channelId, methodName="editCommunityChannel" proc reorderCommunityChat*( self: Service, @@ -521,46 +504,29 @@ QtObject: chatId, position) - if response.error != nil: + if not response.error.isNil: let error = Json.decode($response.error, RpcError) raise newException(RpcException, "Error reordering community channel: " & error.message) - self.events.emit(SIGNAL_COMMUNITY_CHANNEL_REORDERED, - CommunityChatOrderArgs( - communityId: communityId, - categoryId: categoryId, - chatId: chatId, - position: position - ) - ) + if response.result.isNil or response.result.kind == JNull: + error "response is invalid", methodName="reorderCommunityChat" + except Exception as e: - error "Error reordering community channel", msg = e.msg, communityId, chatId, position + error "Error reordering community channel", msg = e.msg, communityId, chatId, position, methodName="reorderCommunityChat" proc deleteCommunityChat*(self: Service, communityId: string, chatId: string) = try: let response = status_go.deleteCommunityChat(communityId, chatId) - if response.error != nil: + if not response.error.isNil: let error = Json.decode($response.error, RpcError) raise newException(RpcException, "Error deleting community chat: " & error.message) - if response.result == nil or response.result.kind == JNull: - error "response is invalid" - return + if response.result.isNil or response.result.kind == JNull: + error "response is invalid", methodName="deleteCommunityChat" - let community = response.result["communities"][0].toCommunityDto() - - # update the joined communities - self.joinedCommunities[community.id].chats = community.chats - - self.events.emit(SIGNAL_COMMUNITY_CHANNEL_DELETED, - CommunityChatIdArgs( - communityId: communityId, - chatId: chatId - ) - ) except Exception as e: - error "Error deleting community channel", msg = e.msg, communityId, chatId + error "Error deleting community channel", msg = e.msg, communityId, chatId, methodName="deleteCommunityChat" proc createCommunityCategory*( self: Service,