From 3fa315c3a89e611180a11366b39ade85c0386393 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 23 Aug 2023 13:22:54 -0400 Subject: [PATCH] chore: clean up modules and controllers by removing the useless function --- .../main/chat_section/chat_content/controller.nim | 3 --- .../chat_content/messages/controller.nim | 3 --- .../chat_section/chat_content/messages/module.nim | 14 ++++---------- .../main/chat_section/chat_content/module.nim | 6 ++---- src/app/modules/main/chat_section/controller.nim | 9 +++------ src/app/modules/main/chat_section/module.nim | 10 +++++----- 6 files changed, 14 insertions(+), 31 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 955a9007c4..ff43ae5b1c 100644 --- a/src/app/modules/main/chat_section/chat_content/controller.nim +++ b/src/app/modules/main/chat_section/chat_content/controller.nim @@ -190,9 +190,6 @@ proc getChatDetails*(self: Controller): ChatDto = proc getCommunityDetails*(self: Controller): CommunityDto = return self.communityService.getCommunityById(self.sectionId) -proc getCommunityById*(self: Controller, communityId: string): CommunityDto = - return self.communityService.getCommunityById(communityId) - proc getOneToOneChatNameAndImage*(self: Controller): tuple[name: string, image: string, largeImage: string] = return self.chatService.getOneToOneChatNameAndImage(self.chatId) diff --git a/src/app/modules/main/chat_section/chat_content/messages/controller.nim b/src/app/modules/main/chat_section/chat_content/messages/controller.nim index cb1fdd959e..5031e45128 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/controller.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/controller.nim @@ -242,9 +242,6 @@ proc getChatDetails*(self: Controller): ChatDto = proc getCommunityDetails*(self: Controller): CommunityDto = return self.communityService.getCommunityById(self.sectionId) -proc getCommunityById*(self: Controller, communityId: string): CommunityDto = - return self.communityService.getCommunityById(communityId) - proc getOneToOneChatNameAndImage*(self: Controller): tuple[name: string, image: string, largeImage: string] = return self.chatService.getOneToOneChatNameAndImage(self.chatId) diff --git a/src/app/modules/main/chat_section/chat_content/messages/module.nim b/src/app/modules/main/chat_section/chat_content/messages/module.nim index c8fdbff2fe..b7b0cfcc0b 100644 --- a/src/app/modules/main/chat_section/chat_content/messages/module.nim +++ b/src/app/modules/main/chat_section/chat_content/messages/module.nim @@ -237,8 +237,6 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se if message.deleted or message.deletedForMe: continue - let chatDetails = self.controller.getChatDetails() - let sender = self.controller.getContactDetails(message.`from`) var quotedMessageAuthorDetails = ContactDetails() if message.quotedMessage.`from` != "": @@ -248,8 +246,7 @@ method newMessagesLoaded*(self: Module, messages: seq[MessageDto], reactions: se quotedMessageAuthorDetails = self.controller.getContactDetails(message.quotedMessage.`from`) var communityChats: seq[ChatDto] - if chatDetails.communityId != "": - communityChats = self.controller.getCommunityById(chatDetails.communityId).chats + communityChats = self.controller.getCommunityDetails().chats var renderedMessageText = self.controller.getRenderedText(message.parsedText, communityChats) @@ -367,8 +364,7 @@ method messagesAdded*(self: Module, messages: seq[MessageDto]) = for message in messages: let sender = self.controller.getContactDetails(message.`from`) - let chatDetails = self.controller.getChatDetails() - let communityChats = self.controller.getCommunityById(chatDetails.communityId).chats + let communityChats = self.controller.getCommunityDetails().chats var quotedMessageAuthorDetails = ContactDetails() if message.quotedMessage.`from` != "": if(message.`from` == message.quotedMessage.`from`): @@ -597,8 +593,7 @@ method updateContactDetails*(self: Module, contactId: string) = item.quotedMessageAuthorAvatar = updatedContact.icon if item.messageContainsMentions and item.mentionedUsersPks.anyIt(it == contactId): - let chatDetails = self.controller.getChatDetails() - let communityChats = self.controller.getCommunityById(chatDetails.communityId).chats + let communityChats = self.controller.getCommunityDetails().chats item.messageText = self.controller.getRenderedText(item.parsedText, communityChats) method deleteMessage*(self: Module, messageId: string) = @@ -616,8 +611,7 @@ method onMessageEdited*(self: Module, message: MessageDto) = return let mentionedUsersPks = itemBeforeChange.mentionedUsersPks - let chatDetails = self.controller.getChatDetails() - let communityChats = self.controller.getCommunityById(chatDetails.communityId).chats + let communityChats = self.controller.getCommunityDetails().chats self.view.model().updateEditedMsg( message.id, diff --git a/src/app/modules/main/chat_section/chat_content/module.nim b/src/app/modules/main/chat_section/chat_content/module.nim index 902e577607..c2d32ba84b 100644 --- a/src/app/modules/main/chat_section/chat_content/module.nim +++ b/src/app/modules/main/chat_section/chat_content/module.nim @@ -153,8 +153,7 @@ proc buildPinnedMessageItem(self: Module, message: MessageDto, actionInitiatedBy item: var pinned_msg_item.Item):bool = let contactDetails = self.controller.getContactDetails(message.`from`) - let chatDetails = self.controller.getChatDetails() - let communityChats = self.controller.getCommunityById(chatDetails.communityId).chats + let communityChats = self.controller.getCommunityDetails().chats var quotedMessageAuthorDetails = ContactDetails() if message.quotedMessage.`from` != "": if(message.`from` == message.quotedMessage.`from`): @@ -342,8 +341,7 @@ method onContactDetailsUpdated*(self: Module, contactId: string) = item.quotedMessageAuthorAvatar = updatedContact.icon if item.messageContainsMentions and item.mentionedUsersPks.anyIt(it == contactId): - let chatDetails = self.controller.getChatDetails() - let communityChats = self.controller.getCommunityById(chatDetails.communityId).chats + let communityChats = self.controller.getCommunityDetails().chats item.messageText = self.controller.getRenderedText(item.parsedText, communityChats) if(self.controller.getMyChatId() == contactId): diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index 0de91a6b08..d4f2227ddc 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -263,7 +263,6 @@ proc init*(self: Controller) = self.delegate.onCommunityTokenPermissionUpdated(args.communityId, args.tokenPermission) self.asyncCheckPermissions() - self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_UPDATE_FAILED) do(e: Args): let args = CommunityTokenPermissionArgs(e) if (args.communityId == self.sectionId): @@ -326,7 +325,8 @@ proc init*(self: Controller) = self.events.on(SIGNAL_ACCEPT_REQUEST_TO_JOIN_FAILED_NO_PERMISSION) do(e: Args): var args = CommunityMemberArgs(e) - self.delegate.onAcceptRequestToJoinFailedNoPermission(args.communityId, args.pubKey, args.requestId) + if (args.communityId == self.sectionId): + self.delegate.onAcceptRequestToJoinFailedNoPermission(args.communityId, args.pubKey, args.requestId) self.events.on(SIGNAL_CONTACT_NICKNAME_CHANGED) do(e: Args): var args = ContactArgs(e) @@ -380,11 +380,8 @@ proc init*(self: Controller) = proc isCommunity*(self: Controller): bool = return self.isCommunitySection -proc getCommunityById*(self: Controller, communityId: string): CommunityDto = - return self.communityService.getCommunityById(communityId) - proc getMyCommunity*(self: Controller): CommunityDto = - return self.getCommunityById(self.sectionId) + return self.communityService.getCommunityById(self.sectionId) proc getCategories*(self: Controller, communityId: string): seq[Category] = return self.communityService.getCategories(communityId) diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index 0d708c9132..800def853e 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -662,7 +662,7 @@ method onCommunityCategoryCreated*(self: Module, cat: Category, chats: seq[ChatD if (self.doesCatOrChatExist(cat.id)): return - let community = self.controller.getCommunityById(communityId) + let community = self.controller.getMyCommunity() discard self.addCategoryItem(cat, community.memberRole, communityId) # Update chat items that now belong to that category self.view.chatsModel().updateItemsWithCategoryDetailsById( @@ -763,7 +763,7 @@ method onCommunityTokenPermissionDeleted*(self: Module, communityId: string, per singletonInstance.globalEvents.showCommunityTokenPermissionDeletedNotification(communityId, "Community permission deleted", "A token permission has been removed") method onCommunityTokenPermissionCreated*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) = - let community = self.controller.getCommunityById(communityId) + let community = self.controller.getMyCommunity() let chats = community.getCommunityChats(tokenPermission.chatIds) let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats) @@ -847,7 +847,7 @@ method onCommunityCheckPermissionsToJoinResponse*(self: Module, checkPermissions self.setPermissionsToJoinCheckOngoing(false) method onCommunityTokenPermissionUpdated*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) = - let community = self.controller.getCommunityById(communityId) + let community = self.controller.getMyCommunity() let chats = community.getCommunityChats(tokenPermission.chatIds) let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats) self.view.tokenPermissionsModel.updateItem(tokenPermission.id, tokenPermissionItem) @@ -979,7 +979,7 @@ method onNewMessagesReceived*(self: Module, sectionIdMsgBelongsTo: string, chatI notificationType = notification_details.NotificationType.NewMessageWithGlobalMention let contactDetails = self.controller.getContactDetails(message.`from`) - let communityChats = self.controller.getCommunityById(chatDetails.communityId).chats + let communityChats = self.controller.getMyCommunity().chats let renderedMessageText = self.controller.getRenderedText(message.parsedText, communityChats) var plainText = singletonInstance.utils.plainText(renderedMessageText) if message.contentType == ContentType.Sticker or (message.contentType == ContentType.Image and len(plainText) == 0): @@ -1048,7 +1048,7 @@ method declineRequestToJoinCommunity*(self: Module, requestId: string, community self.controller.declineRequestToJoinCommunity(requestId, communityId) method onAcceptRequestToJoinFailedNoPermission*(self: Module, communityId: string, memberKey: string, requestId: string) = - let community = self.controller.getCommunityById(communityId) + let community = self.controller.getMyCommunity() let contact = self.controller.getContactById(memberKey) self.view.emitOpenNoPermissionsToJoinPopupSignal(community.name, contact.displayName, community.id, requestId)