fix(@desktop/notifications): fixing wrong mentions counting

This commit is contained in:
Andrei Smirnov 2021-09-20 17:26:40 +03:00 committed by Iuri Matias
parent c392a473b9
commit d6d4ae5c79
4 changed files with 22 additions and 6 deletions

View File

@ -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()

View File

@ -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] = @[]

View File

@ -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)

View File

@ -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])