diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index 3697676b1b..95896ce6c4 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -97,26 +97,19 @@ method init*(self: Controller) = self.events.on(SIGNAL_CHAT_UPDATE) do(e: Args): var args = ChatUpdateArgsNew(e) - self.delegate.addChatIfDontExist(args.chats, false, self.events, self.settingsService, self.contactService, self.chatService, - self.communityService, self.messageService, self.gifService, self.mailserversService, setChatAsActive = false) - + for chat in args.chats: + let belongsToCommunity = chat.communityId.len > 0 + self.delegate.addChatIfDontExist(chat, belongsToCommunity, self.events, self.settingsService, + self.contactService, self.chatService, self.communityService, self.messageService, self.gifService, + self.mailserversService, setChatAsActive = false) if (self.isCommunitySection): self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args): let args = CommunityChatArgs(e) - if (args.chat.communityId == self.sectionId): - self.delegate.addNewChat( - args.chat, - true, - self.events, - self.settingsService, - self.contactService, - self.chatService, - self.communityService, - self.messageService, - self.gifService, - self.mailserversService - ) + let belongsToCommunity = args.chat.communityId.len > 0 + self.delegate.addChatIfDontExist(args.chat, belongsToCommunity, self.events, self.settingsService, + self.contactService, self.chatService, self.communityService, self.messageService, self.gifService, + self.mailserversService, setChatAsActive = true) self.events.on(SIGNAL_COMMUNITY_CHANNEL_DELETED) do(e:Args): let args = CommunityChatIdArgs(e) diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index b310399a83..b1924c7732 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -413,7 +413,7 @@ method addNewChat*( else: amIChatAdmin = self.amIMarkedAsAdminUser(chatDto.members) - if chatDto.categoryId == "": + if chatDto.categoryId.len == 0: let item = initItem(chatDto.id, chatName, chatImage, isIdenticon, chatDto.color, chatDto.description, chatDto.chatType.int, amIChatAdmin, hasNotification, notificationsCount, chatDto.muted, blocked=false, active=false, position = 0, chatDto.categoryId, chatDto.highlight) @@ -426,6 +426,10 @@ method addNewChat*( self.setActiveItemSubItem(item.id, "") else: let categoryItem = self.view.chatsModel().getItemById(chatDto.categoryId) + if(categoryItem.isNil): + error "A category you're trying to add channel to doesn't exist", categoryId=chatDto.categoryId + return + let channelItem = initSubItem(chatDto.id, chatDto.categoryId, chatDto.name, chatDto.identicon, false, chatDto.color, chatDto.description, chatDto.chatType.int, amIChatAdmin, hasNotification, notificationsCount, chatDto.muted, blocked=false, active=false, chatDto.position) @@ -730,7 +734,7 @@ method setLoadingHistoryMessagesInProgress*(self: Module, isLoading: bool) = self.view.setLoadingHistoryMessagesInProgress(isLoading) method addChatIfDontExist*(self: Module, - chats: seq[ChatDto], + chat: ChatDto, belongsToCommunity: bool, events: EventEmitter, settingsService: settings_service.ServiceInterface, @@ -741,7 +745,13 @@ method addChatIfDontExist*(self: Module, gifService: gif_service.Service, mailserversService: mailservers_service.Service, setChatAsActive: bool = true) = - for chatDto in chats: - if not self.doesChatExist(chatDto.id): - self.addNewChat(chatDto, belongsToCommunity, events, settingsService, contactService, chatService, - communityService, messageService, gifService, mailserversService, setChatAsActive) + + if(belongsToCommunity and self.controller.getMySectionId() != chat.communityId or + not belongsToCommunity and self.controller.getMySectionId() != conf.CHAT_SECTION_ID): + return + + if self.doesChatExist(chat.id): + return + + self.addNewChat(chat, belongsToCommunity, events, settingsService, contactService, chatService, + communityService, messageService, gifService, mailserversService, setChatAsActive) diff --git a/src/app/modules/main/chat_section/private_interfaces/module_controller_delegate_interface.nim b/src/app/modules/main/chat_section/private_interfaces/module_controller_delegate_interface.nim index dc5fa407f1..a929a2d58e 100644 --- a/src/app/modules/main/chat_section/private_interfaces/module_controller_delegate_interface.nim +++ b/src/app/modules/main/chat_section/private_interfaces/module_controller_delegate_interface.nim @@ -15,7 +15,7 @@ method doesChatExist*(self: AccessInterface, chatId: string): bool {.base.} = raise newException(ValueError, "No implementation available") method addChatIfDontExist*(self: AccessInterface, - chats: seq[ChatDto], + chat: ChatDto, belongsToCommunity: bool, events: EventEmitter, settingsService: settings_service.ServiceInterface,