diff --git a/src/app/modules/main/chat_section/base_item.nim b/src/app/modules/main/chat_section/base_item.nim index 8e34d03f8f..bd75c2298d 100644 --- a/src/app/modules/main/chat_section/base_item.nim +++ b/src/app/modules/main/chat_section/base_item.nim @@ -15,10 +15,11 @@ type active: bool position: int categoryId: string + highlight: bool proc setup*(self: BaseItem, id, name, icon: string, isIdenticon: bool, color, description: string, `type`: int, amIChatAdmin: bool, hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool, - position: int, categoryId: string = "") = + position: int, categoryId: string = "", highlight: bool = false) = self.id = id self.name = name self.amIChatAdmin = amIChatAdmin @@ -34,13 +35,14 @@ proc setup*(self: BaseItem, id, name, icon: string, isIdenticon: bool, color, de self.active = active self.position = position self.categoryId = categoryId + self.highlight = highlight proc initBaseItem*(id, name, icon: string, isIdenticon: bool, color, description: string, `type`: int, amIChatAdmin: bool, hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool, - position: int, categoryId: string = ""): BaseItem = + position: int, categoryId: string = "", highlight: bool = false): BaseItem = result = BaseItem() result.setup(id, name, icon, isIdenticon, color, description, `type`, amIChatAdmin, hasUnreadMessages, - notificationsCount, muted, blocked, active, position, categoryId) + notificationsCount, muted, blocked, active, position, categoryId, highlight) proc delete*(self: BaseItem) = discard @@ -122,3 +124,9 @@ method categoryId*(self: BaseItem): string {.inline base.} = method `categoryId=`*(self: var BaseItem, value: string) {.inline base.} = self.categoryId = value + +method highlight*(self: BaseItem): bool {.inline base.} = + self.highlight + +method `highlight=`*(self: var BaseItem, value: bool) {.inline base.} = + self.highlight = value diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index 49a7d37313..4065e9edb2 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -94,6 +94,12 @@ method init*(self: Controller) = var args = ContactArgs(e) self.delegate.onContactUnblocked(args.contactId) + 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) + + if (self.isCommunitySection): self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args): let args = CommunityChatArgs(e) diff --git a/src/app/modules/main/chat_section/item.nim b/src/app/modules/main/chat_section/item.nim index 4ab26e3484..2d5e77256a 100644 --- a/src/app/modules/main/chat_section/item.nim +++ b/src/app/modules/main/chat_section/item.nim @@ -6,10 +6,10 @@ type subItems: SubModel proc initItem*(id, name, icon: string, isIdenticon: bool, color, description: string, `type`: int, amIChatAdmin: bool, - hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool, position: int, categoryId: string): Item = + hasUnreadMessages: bool, notificationsCount: int, muted, blocked, active: bool, position: int, categoryId: string, highlight: bool = false): Item = result = Item() result.setup(id, name, icon, isIdenticon, color, description, `type`, amIChatAdmin, hasUnreadMessages, - notificationsCount, muted, blocked, active, position, categoryId) + notificationsCount, muted, blocked, active, position, categoryId, highlight) result.subItems = newSubModel() proc delete*(self: Item) = @@ -36,6 +36,7 @@ proc `$`*(self: Item): string = active: {self.active}, position: {self.position}, categoryId: {self.categoryId}, + highlight: {self.highlight}, subItems:[ {$self.subItems} ]""" @@ -56,7 +57,8 @@ proc toJsonNode*(self: Item): JsonNode = "blocked": self.blocked, "active": self.active, "position": self.position, - "categoryId": self.categoryId + "categoryId": self.categoryId, + "highlight": self.highlight } proc appendSubItems*(self: Item, items: seq[SubItem]) = diff --git a/src/app/modules/main/chat_section/model.nim b/src/app/modules/main/chat_section/model.nim index 026f9ca781..ad4e03e9b8 100644 --- a/src/app/modules/main/chat_section/model.nim +++ b/src/app/modules/main/chat_section/model.nim @@ -21,6 +21,7 @@ type SubItems IsCategory CategoryId + Highlight QtObject: type @@ -85,7 +86,8 @@ QtObject: ModelRole.Position.int:"position", ModelRole.SubItems.int:"subItems", ModelRole.IsCategory.int:"isCategory", - ModelRole.CategoryId.int:"categoryId" + ModelRole.CategoryId.int:"categoryId", + ModelRole.Highlight.int:"highlight" }.toTable method data(self: Model, index: QModelIndex, role: int): QVariant = @@ -133,6 +135,8 @@ QtObject: result = newQVariant(item.`type` == ChatType.Unknown.int) of ModelRole.CategoryId: result = newQVariant(item.categoryId) + of ModelRole.Highlight: + result = newQVariant(item.highlight) proc appendItem*(self: Model, item: Item) = let parentModelIndex = newQModelIndex() @@ -182,6 +186,12 @@ QtObject: return self.items[index] + proc isItemWithIdAdded*(self: Model, id: string): bool = + for it in self.items: + if(it.id == id): + return true + return false + proc getItemById*(self: Model, id: string): Item = for it in self.items: if(it.id == id): diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index 200ef31c0e..dbe5cf13e6 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -385,7 +385,8 @@ method addNewChat*( communityService: community_service.Service, messageService: message_service.Service, gifService: gif_service.Service, - mailserversService: mailservers_service.Service) = + mailserversService: mailservers_service.Service, + setChatAsActive: bool = true) = let hasNotification = chatDto.unviewedMessagesCount > 0 or chatDto.unviewedMentionsCount > 0 let notificationsCount = chatDto.unviewedMentionsCount var chatName = chatDto.name @@ -404,13 +405,14 @@ method addNewChat*( if chatDto.categoryId == "": 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) + blocked=false, active=false, position = 0, chatDto.categoryId, chatDto.highlight) self.addSubmodule(chatDto.id, belongsToCommunity, isUsersListAvailable, events, settingsService, contactService, chatService, communityService, messageService, gifService, mailserversService) self.chatContentModules[chatDto.id].load() self.view.chatsModel().appendItem(item) # make new added chat active one - self.setActiveItemSubItem(item.id, "") + if setChatAsActive: + self.setActiveItemSubItem(item.id, "") else: let categoryItem = self.view.chatsModel().getItemById(chatDto.categoryId) let channelItem = initSubItem(chatDto.id, chatDto.categoryId, chatDto.name, chatDto.identicon, false, chatDto.color, @@ -422,6 +424,9 @@ method addNewChat*( categoryItem.appendSubItem(channelItem) self.setActiveItemSubItem(categoryItem.id, channelItem.id) +method doesChatExist*(self: Module, chatId: string): bool = + return self.view.chatsModel().isItemWithIdAdded(chatId) + method removeCommunityChat*(self: Module, chatId: string) = if(not self.chatContentModules.contains(chatId)): return @@ -691,3 +696,20 @@ method reorderCommunityChat*(self: Module, categoryId: string, chatId: string, p method setLoadingHistoryMessagesInProgress*(self: Module, isLoading: bool) = self.view.setLoadingHistoryMessagesInProgress(isLoading) + +method addChatIfDontExist*(self: Module, + chats: seq[ChatDto], + belongsToCommunity: bool, + events: EventEmitter, + settingsService: settings_service.ServiceInterface, + contactService: contact_service.Service, + chatService: chat_service.Service, + communityService: community_service.Service, + messageService: message_service.Service, + 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) 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 06c5fa7047..dc5fa407f1 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 @@ -8,7 +8,24 @@ method addNewChat*(self: AccessInterface, chatDto: ChatDto, belongsToCommunity: settingsService: settings_service.ServiceInterface, contactService: contact_service.Service, chatService: chat_service.Service, communityService: community_service.Service, messageService: message_service.Service, gifService: gif_service.Service, - mailserversService: mailservers_service.Service) {.base.} = + mailserversService: mailservers_service.Service, setChatAsActive: bool = true) {.base.} = + raise newException(ValueError, "No implementation available") + +method doesChatExist*(self: AccessInterface, chatId: string): bool {.base.} = + raise newException(ValueError, "No implementation available") + +method addChatIfDontExist*(self: AccessInterface, + chats: seq[ChatDto], + belongsToCommunity: bool, + events: EventEmitter, + settingsService: settings_service.ServiceInterface, + contactService: contact_service.Service, + chatService: chat_service.Service, + communityService: community_service.Service, + messageService: message_service.Service, + gifService: gif_service.Service, + mailserversService: mailservers_service.Service, + setChatAsActive: bool = true) {.base.} = raise newException(ValueError, "No implementation available") method onNewMessagesReceived*(self: AccessInterface, chatId: string, unviewedMessagesCount: int, diff --git a/src/app_service/service/chat/dto/chat.nim b/src/app_service/service/chat/dto/chat.nim index f2dca71be5..a80141b62d 100644 --- a/src/app_service/service/chat/dto/chat.nim +++ b/src/app_service/service/chat/dto/chat.nim @@ -47,6 +47,7 @@ type ChatDto* = object canPost*: bool position*: int categoryId*: string + highlight*: bool proc `$`*(self: ChatDto): string = result = fmt"""ChatDto( @@ -72,7 +73,8 @@ proc `$`*(self: ChatDto): string = syncedTo: {self.syncedTo}, syncedFrom: {self.syncedFrom}, categoryId: {self.categoryId}, - position: {self.position} + position: {self.position}, + highlight: {self.highlight} )""" proc toChatMember(jsonObj: JsonNode): ChatMember = @@ -103,6 +105,7 @@ proc toChatDto*(jsonObj: JsonNode): ChatDto = discard jsonObj.getProp("joined", result.joined) discard jsonObj.getProp("syncedTo", result.syncedTo) discard jsonObj.getProp("syncedFrom", result.syncedFrom) + discard jsonObj.getProp("highlight", result.highlight) result.chatType = ChatType.Unknown var chatTypeInt: int diff --git a/src/app_service/service/chat/service.nim b/src/app_service/service/chat/service.nim index a0919221e3..29cc065632 100644 --- a/src/app_service/service/chat/service.nim +++ b/src/app_service/service/chat/service.nim @@ -8,6 +8,7 @@ import ../../../backend/chat as status_chat import ../../../backend/chatCommands as status_chat_commands import ../../../app/global/global_singleton import ../../../app/core/eventemitter +import ../../../app/core/signals/types import ../../../constants import ../../common/message as message_common @@ -94,7 +95,22 @@ QtObject: result.contactService = contactService result.chats = initTable[string, ChatDto]() - proc init*(self: Service) = + # Forward declarations + proc updateOrAddChat*(self: Service, chat: ChatDto) + + proc doConnect(self: Service) = + self.events.on(SignalType.Message.event) do(e: Args): + var receivedData = MessageSignal(e) + + # Handling chat updates + if (receivedData.chats.len > 0): + for chatDto in receivedData.chats: + self.updateOrAddChat(chatDto) + self.events.emit(SIGNAL_CHAT_UPDATE, ChatUpdateArgsNew(messages: receivedData.messages, chats: receivedData.chats)) + + proc init*(self: Service) = + self.doConnect() + try: let response = status_chat.getChats() diff --git a/ui/StatusQ b/ui/StatusQ index 5780f183c7..ccfe8cc0ff 160000 --- a/ui/StatusQ +++ b/ui/StatusQ @@ -1 +1 @@ -Subproject commit 5780f183c7b3cf63c3abbc584daa72078241e917 +Subproject commit ccfe8cc0ff7f32993f0aef996fe45fa6960b1e3e