From d6d4ae5c799a675c9a467cd16041616d84bae907 Mon Sep 17 00:00:00 2001 From: Andrei Smirnov Date: Mon, 20 Sep 2021 17:26:40 +0300 Subject: [PATCH] fix(@desktop/notifications): fixing wrong mentions counting --- src/app/chat/view.nim | 9 +++++++-- src/app/chat/views/activity_notification_list.nim | 5 +++++ src/app/chat/views/channel.nim | 13 ++++++++++--- src/app/chat/views/channels_list.nim | 1 - 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index 9c5d703fe4..eda0a06d6f 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -115,12 +115,12 @@ QtObject: result.formatInputView = newFormatInputView() result.ensView = newEnsView(status, appService) result.communities = newCommunitiesView(status) - result.channelView = newChannelView(status, appService, result.communities) + result.activityNotificationList = newActivityNotificationList(status) + result.channelView = newChannelView(status, appService, result.communities, result.activityNotificationList) result.messageView = newMessageView(status, appService, result.channelView, result.communities) result.messageSearchViewController = newMessageSearchViewController(status, appService, result.channelView, result.communities) result.connected = false - result.activityNotificationList = newActivityNotificationList(status) result.reactions = newReactionView( status, result.messageView.messageList.addr, @@ -236,6 +236,11 @@ QtObject: proc addActivityCenterNotification*(self:ChatsView, activityCenterNotifications: seq[ActivityCenterNotification]) = for activityCenterNotification in activityCenterNotifications: + if self.channelView.activeChannel.id == activityCenterNotification.chatId: + activityCenterNotification.read = true + let communityId = self.status.chat.getCommunityIdForChat(activityCenterNotification.chatId) + if communityId != "": + self.communities.joinedCommunityList.decrementMentions(communityId, activityCenterNotification.chatId) self.activityNotificationList.addActivityNotificationItemToList(activityCenterNotification) self.activityNotificationsChanged() diff --git a/src/app/chat/views/activity_notification_list.nim b/src/app/chat/views/activity_notification_list.nim index 813bf50814..4f8e36311f 100644 --- a/src/app/chat/views/activity_notification_list.nim +++ b/src/app/chat/views/activity_notification_list.nim @@ -159,6 +159,11 @@ QtObject: self.dataChanged(index, index, @[NotifRoles.Read.int]) i.inc + proc markAllChatMentionsAsRead*(self: ActivityNotificationList, communityId: string, chatId: string) = + for motification in self.activityCenterNotifications: + if (motification.chatId == chatId and not motification.read): + self.markActivityCenterNotificationRead(motification.id, communityId, chatId, ActivityCenterNotificationType.Mention.int) + proc removeNotifications(self: ActivityNotificationList, ids: seq[string]) = var i = 0 var indexesToDelete: seq[int] = @[] diff --git a/src/app/chat/views/channel.nim b/src/app/chat/views/channel.nim index 96538e7e05..d993e29408 100644 --- a/src/app/chat/views/channel.nim +++ b/src/app/chat/views/channel.nim @@ -6,7 +6,7 @@ import status/chat as status_chat import status/chat/[chat] import ../../../app_service/[main] -import communities, chat_item, channels_list, communities, community_list +import communities, chat_item, channels_list, communities, community_list, activity_notification_list logScope: topics = "channel-view" @@ -20,6 +20,7 @@ QtObject: activeChannel*: ChatItemView previousActiveChannelIndex*: int contextChannel*: ChatItemView + activityNotificationList*: ActivityNotificationList proc setup(self: ChannelView) = self.QObject.setup proc delete*(self: ChannelView) = @@ -28,7 +29,7 @@ QtObject: self.contextChannel.delete self.QObject.delete - proc newChannelView*(status: Status, appService: AppService, communities: CommunitiesView): ChannelView = + proc newChannelView*(status: Status, appService: AppService, communities: CommunitiesView, activityNotificationList: ActivityNotificationList): ChannelView = new(result, delete) result.status = status result.appService = appService @@ -37,6 +38,7 @@ QtObject: result.contextChannel = newChatItemView(status) result.communities = communities result.previousActiveChannelIndex = -1 + result.activityNotificationList = activityNotificationList result.setup proc getChannel*(self: ChannelView, index: int): Chat = @@ -114,7 +116,8 @@ QtObject: generateAlias(pubKey) proc setActiveChannelByIndexWithForce*(self: ChannelView, index: int, forceUpdate: bool) {.slot.} = - if((self.communities.activeCommunity.active and self.communities.activeCommunity.chats.chats.len == 0) or (not self.communities.activeCommunity.active and self.chats.chats.len == 0)): return + if((self.communities.activeCommunity.active and self.communities.activeCommunity.chats.chats.len == 0) or (not self.communities.activeCommunity.active and self.chats.chats.len == 0)): + return var selectedChannel = self.getChannel(index) @@ -155,6 +158,10 @@ QtObject: if (channel.len == 0): return + let communityId = self.status.chat.getCommunityIdForChat(channel) + if communityId != "": + self.activityNotificationList.markAllChatMentionsAsRead(communityId, channel) + if (channel == backToFirstChat): if (self.activeChannel.id.len == 0): self.setActiveChannelByIndex(0) diff --git a/src/app/chat/views/channels_list.nim b/src/app/chat/views/channels_list.nim index 43f8fad1d5..37949b3335 100644 --- a/src/app/chat/views/channels_list.nim +++ b/src/app/chat/views/channels_list.nim @@ -200,7 +200,6 @@ QtObject: let index = self.createIndex(idx, 0, nil) self.chats[idx].unviewedMessagesCount = 0 - self.chats[idx].unviewedMentionsCount = 0 self.dataChanged(index, index, @[ChannelsRoles.UnreadMessages.int])