mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-17 00:56:39 +00:00
fix(@desktop/communities): joinedCommunities
doesn't update underlying community
Counting mentions for community seems was not developed yet. That's added here in this commit, but instead of using "mentionsCount" we introduced on the side of nim, I found that we're receiving "unviewedMentionsCount", but only for new messages. I used it for this fix. Counting mentions and requests per community added. Fixes: #2972
This commit is contained in:
parent
2df6def7f9
commit
a530f65ada
@ -28,7 +28,6 @@ proc handleChatEvents(self: ChatController) =
|
|||||||
self.status.events.on("activityCenterNotificationsLoaded") do(e:Args):
|
self.status.events.on("activityCenterNotificationsLoaded") do(e:Args):
|
||||||
let notifications = ActivityCenterNotificationsArgs(e).activityCenterNotifications
|
let notifications = ActivityCenterNotificationsArgs(e).activityCenterNotifications
|
||||||
self.view.pushActivityCenterNotifications(notifications)
|
self.view.pushActivityCenterNotifications(notifications)
|
||||||
self.view.communities.updateNotifications(notifications)
|
|
||||||
|
|
||||||
self.status.events.on("contactBlocked") do(e: Args):
|
self.status.events.on("contactBlocked") do(e: Args):
|
||||||
var evArgs = ContactBlockedArgs(e)
|
var evArgs = ContactBlockedArgs(e)
|
||||||
@ -86,7 +85,6 @@ proc handleChatEvents(self: ChatController) =
|
|||||||
self.view.refreshPinnedMessages(evArgs.pinnedMessages)
|
self.view.refreshPinnedMessages(evArgs.pinnedMessages)
|
||||||
if (evArgs.activityCenterNotifications.len > 0):
|
if (evArgs.activityCenterNotifications.len > 0):
|
||||||
self.view.addActivityCenterNotification(evArgs.activityCenterNotifications)
|
self.view.addActivityCenterNotification(evArgs.activityCenterNotifications)
|
||||||
self.view.communities.updateNotifications(evArgs.activityCenterNotifications)
|
|
||||||
|
|
||||||
if (evArgs.deletedMessages.len > 0):
|
if (evArgs.deletedMessages.len > 0):
|
||||||
for messageId in evArgs.deletedMessages:
|
for messageId in evArgs.deletedMessages:
|
||||||
|
@ -181,6 +181,7 @@ QtObject:
|
|||||||
|
|
||||||
let index = self.createIndex(idx, 0, nil)
|
let index = self.createIndex(idx, 0, nil)
|
||||||
self.chats[idx].unviewedMessagesCount = 0
|
self.chats[idx].unviewedMessagesCount = 0
|
||||||
|
self.chats[idx].unviewedMentionsCount = 0
|
||||||
|
|
||||||
self.dataChanged(index, index, @[ChannelsRoles.UnreadMessages.int])
|
self.dataChanged(index, index, @[ChannelsRoles.UnreadMessages.int])
|
||||||
|
|
||||||
@ -191,6 +192,7 @@ QtObject:
|
|||||||
|
|
||||||
let index = self.createIndex(idx, 0, nil)
|
let index = self.createIndex(idx, 0, nil)
|
||||||
self.chats[idx].mentionsCount = 0
|
self.chats[idx].mentionsCount = 0
|
||||||
|
self.chats[idx].unviewedMentionsCount = 0
|
||||||
|
|
||||||
self.dataChanged(index, index, @[ChannelsRoles.MentionsCount.int])
|
self.dataChanged(index, index, @[ChannelsRoles.MentionsCount.int])
|
||||||
|
|
||||||
@ -205,18 +207,7 @@ QtObject:
|
|||||||
|
|
||||||
let index = self.createIndex(idx, 0, nil)
|
let index = self.createIndex(idx, 0, nil)
|
||||||
self.chats[idx].mentionsCount.dec
|
self.chats[idx].mentionsCount.dec
|
||||||
|
self.chats[idx].unviewedMentionsCount.dec
|
||||||
self.dataChanged(index, index, @[ChannelsRoles.MentionsCount.int])
|
|
||||||
|
|
||||||
proc incrementMentions*(self: ChannelsList, channelId: string) : bool =
|
|
||||||
result = false
|
|
||||||
let idx = self.chats.findIndexById(channelId)
|
|
||||||
if idx == -1:
|
|
||||||
return
|
|
||||||
|
|
||||||
let index = self.createIndex(idx, 0, nil)
|
|
||||||
self.chats[idx].mentionsCount.inc
|
|
||||||
result = true
|
|
||||||
|
|
||||||
self.dataChanged(index, index, @[ChannelsRoles.MentionsCount.int])
|
self.dataChanged(index, index, @[ChannelsRoles.MentionsCount.int])
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ proc mergeChat(community: var Community, chat: Chat): bool =
|
|||||||
if (c.id == chat.id):
|
if (c.id == chat.id):
|
||||||
chat.canPost = community.chats[i].canPost
|
chat.canPost = community.chats[i].canPost
|
||||||
chat.categoryId = community.chats[i].categoryId
|
chat.categoryId = community.chats[i].categoryId
|
||||||
chat.mentionsCount = community.chats[i].mentionsCount
|
|
||||||
community.chats[i] = chat
|
community.chats[i] = chat
|
||||||
return true
|
return true
|
||||||
|
|
||||||
@ -73,13 +72,6 @@ QtObject:
|
|||||||
self.importingCommunityState = state
|
self.importingCommunityState = state
|
||||||
self.importingCommunityStateChanged(state.int, communityImportingProcessId)
|
self.importingCommunityStateChanged(state.int, communityImportingProcessId)
|
||||||
|
|
||||||
proc calculateUnreadMessages*(self: CommunitiesView, community: var Community) =
|
|
||||||
var unreadTotal = 0
|
|
||||||
for chatItem in community.chats:
|
|
||||||
unreadTotal = unreadTotal + chatItem.unviewedMessagesCount
|
|
||||||
if unreadTotal != community.unviewedMessagesCount:
|
|
||||||
community.unviewedMessagesCount = unreadTotal
|
|
||||||
|
|
||||||
proc updateMemberVisibility*(self: CommunitiesView, statusUpdate: StatusUpdate) =
|
proc updateMemberVisibility*(self: CommunitiesView, statusUpdate: StatusUpdate) =
|
||||||
self.joinedCommunityList.updateMemberVisibility(statusUpdate)
|
self.joinedCommunityList.updateMemberVisibility(statusUpdate)
|
||||||
self.activeCommunity.setCommunityItem(self.joinedCommunityList.getCommunityById(self.activeCommunity.communityItem.id))
|
self.activeCommunity.setCommunityItem(self.joinedCommunityList.getCommunityById(self.activeCommunity.communityItem.id))
|
||||||
@ -109,7 +101,6 @@ QtObject:
|
|||||||
if (not found):
|
if (not found):
|
||||||
community.chats.add(newChat)
|
community.chats.add(newChat)
|
||||||
|
|
||||||
self.calculateUnreadMessages(community)
|
|
||||||
self.joinedCommunityList.replaceCommunity(community)
|
self.joinedCommunityList.replaceCommunity(community)
|
||||||
if (self.activeCommunity.active and self.activeCommunity.communityItem.id == community.id):
|
if (self.activeCommunity.active and self.activeCommunity.communityItem.id == community.id):
|
||||||
self.activeCommunity.changeChats(community.chats)
|
self.activeCommunity.changeChats(community.chats)
|
||||||
@ -164,6 +155,8 @@ QtObject:
|
|||||||
var communities = self.status.chat.getJoinedComunities()
|
var communities = self.status.chat.getJoinedComunities()
|
||||||
communities = self.populateChats(communities)
|
communities = self.populateChats(communities)
|
||||||
self.joinedCommunityList.setNewData(communities)
|
self.joinedCommunityList.setNewData(communities)
|
||||||
|
for c in communities:
|
||||||
|
self.addMembershipRequests(self.pendingRequestsToJoinForCommunity(c.id))
|
||||||
self.joinedCommunityList.fetched = true
|
self.joinedCommunityList.fetched = true
|
||||||
|
|
||||||
# Also fetch requests
|
# Also fetch requests
|
||||||
@ -200,7 +193,6 @@ QtObject:
|
|||||||
|
|
||||||
proc setActiveCommunity*(self: CommunitiesView, communityId: string) {.slot.} =
|
proc setActiveCommunity*(self: CommunitiesView, communityId: string) {.slot.} =
|
||||||
if(communityId == ""): return
|
if(communityId == ""): return
|
||||||
self.addMembershipRequests(self.pendingRequestsToJoinForCommunity(communityId))
|
|
||||||
self.activeCommunity.setCommunityItem(self.joinedCommunityList.getCommunityById(communityId))
|
self.activeCommunity.setCommunityItem(self.joinedCommunityList.getCommunityById(communityId))
|
||||||
self.activeCommunity.setActive(true)
|
self.activeCommunity.setActive(true)
|
||||||
self.activeCommunityChanged()
|
self.activeCommunityChanged()
|
||||||
@ -219,7 +211,8 @@ QtObject:
|
|||||||
if (not self.userCanJoin(communityId) or self.isUserMemberOfCommunity(communityId)):
|
if (not self.userCanJoin(communityId) or self.isUserMemberOfCommunity(communityId)):
|
||||||
return
|
return
|
||||||
self.status.chat.joinCommunity(communityId)
|
self.status.chat.joinCommunity(communityId)
|
||||||
self.joinedCommunityList.addCommunityItemToList(self.communityList.getCommunityById(communityId))
|
var community = self.communityList.getCommunityById(communityId)
|
||||||
|
self.joinedCommunityList.addCommunityItemToList(community)
|
||||||
if (setActive):
|
if (setActive):
|
||||||
self.setActiveCommunity(communityId)
|
self.setActiveCommunity(communityId)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -284,7 +277,7 @@ QtObject:
|
|||||||
result = ""
|
result = ""
|
||||||
try:
|
try:
|
||||||
var image = image_utils.formatImagePath(imagePath)
|
var image = image_utils.formatImagePath(imagePath)
|
||||||
let community = self.status.chat.createCommunity(name, description, access, ensOnly, color, image, aX, aY, bX, bY)
|
var community = self.status.chat.createCommunity(name, description, access, ensOnly, color, image, aX, aY, bX, bY)
|
||||||
|
|
||||||
if (community.id == ""):
|
if (community.id == ""):
|
||||||
return "Community was not created. Please try again later"
|
return "Community was not created. Please try again later"
|
||||||
@ -527,7 +520,7 @@ QtObject:
|
|||||||
of ActivityCenterNotificationType.NewPrivateGroupChat:
|
of ActivityCenterNotificationType.NewPrivateGroupChat:
|
||||||
debug "Clear all private group chat notifications"
|
debug "Clear all private group chat notifications"
|
||||||
of ActivityCenterNotificationType.Mention:
|
of ActivityCenterNotificationType.Mention:
|
||||||
self.activeCommunity.chats.clearAllMentionsFromAllChannels()
|
self.activeCommunity.clearAllMentions()
|
||||||
|
|
||||||
for c in self.joinedCommunityList.communities:
|
for c in self.joinedCommunityList.communities:
|
||||||
# We don't need to update channels from the currently active community.
|
# We don't need to update channels from the currently active community.
|
||||||
@ -549,7 +542,8 @@ QtObject:
|
|||||||
debug "Clear private group chat notification"
|
debug "Clear private group chat notification"
|
||||||
of ActivityCenterNotificationType.Mention:
|
of ActivityCenterNotificationType.Mention:
|
||||||
if (markAsReadProps.communityId == self.activeCommunity.communityItem.id):
|
if (markAsReadProps.communityId == self.activeCommunity.communityItem.id):
|
||||||
self.activeCommunity.chats.decrementMentions(markAsReadProps.channelId)
|
self.activeCommunity.decrementMentions(markAsReadProps.channelId)
|
||||||
|
self.joinedCommunityList.updateMentions(markAsReadProps.communityId)
|
||||||
else:
|
else:
|
||||||
for c in self.joinedCommunityList.communities:
|
for c in self.joinedCommunityList.communities:
|
||||||
# We don't need to update channels from the currently active community.
|
# We don't need to update channels from the currently active community.
|
||||||
@ -560,21 +554,3 @@ QtObject:
|
|||||||
debug "Clear reply notification"
|
debug "Clear reply notification"
|
||||||
else:
|
else:
|
||||||
debug "Unknown notification"
|
debug "Unknown notification"
|
||||||
|
|
||||||
proc updateNotifications*(self: CommunitiesView, notifications: seq[ActivityCenterNotification]) =
|
|
||||||
for n in notifications:
|
|
||||||
if (not n.read):
|
|
||||||
case n.notificationType:
|
|
||||||
of ActivityCenterNotificationType.NewOneToOne:
|
|
||||||
debug "Update one to one notification"
|
|
||||||
of ActivityCenterNotificationType.NewPrivateGroupChat:
|
|
||||||
debug "Update private group chat notification"
|
|
||||||
of ActivityCenterNotificationType.Mention:
|
|
||||||
let incremented = self.activeCommunity.chats.incrementMentions(n.chatId)
|
|
||||||
if (not incremented):
|
|
||||||
self.joinedCommunityList.incrementMentions(n.chatId)
|
|
||||||
|
|
||||||
of ActivityCenterNotificationType.Reply:
|
|
||||||
debug "Update reply notification"
|
|
||||||
else:
|
|
||||||
debug "Unknown notification"
|
|
||||||
|
@ -249,3 +249,14 @@ QtObject:
|
|||||||
categoryItemView.setCategoryItem(category)
|
categoryItemView.setCategoryItem(category)
|
||||||
self.categoryItemViews[id] = categoryItemView
|
self.categoryItemViews[id] = categoryItemView
|
||||||
return categoryItemView
|
return categoryItemView
|
||||||
|
|
||||||
|
proc clearAllMentions*(self: CommunityItemView) =
|
||||||
|
self.chats.clearAllMentionsFromAllChannels()
|
||||||
|
self.communityItem.unviewedMentionsCount = 0
|
||||||
|
self.chatsChanged()
|
||||||
|
|
||||||
|
proc decrementMentions*(self: CommunityItemView, channelId: string) =
|
||||||
|
self.chats.decrementMentions(channelId)
|
||||||
|
self.communityItem.unviewedMentionsCount -= 1
|
||||||
|
self.chatsChanged()
|
||||||
|
|
||||||
|
@ -10,23 +10,25 @@ import # status-desktop libs
|
|||||||
type
|
type
|
||||||
CommunityRoles {.pure.} = enum
|
CommunityRoles {.pure.} = enum
|
||||||
Id = UserRole + 1,
|
Id = UserRole + 1,
|
||||||
Name = UserRole + 2
|
Name
|
||||||
Description = UserRole + 3
|
Description
|
||||||
Access = UserRole + 4
|
Access
|
||||||
Admin = UserRole + 5
|
Admin
|
||||||
Joined = UserRole + 6
|
Joined
|
||||||
Verified = UserRole + 7
|
Verified
|
||||||
NumMembers = UserRole + 8
|
NumMembers
|
||||||
ThumbnailImage = UserRole + 9
|
ThumbnailImage
|
||||||
LargeImage = UserRole + 10
|
LargeImage
|
||||||
EnsOnly = UserRole + 11
|
EnsOnly
|
||||||
CanRequestAccess = UserRole + 12
|
CanRequestAccess
|
||||||
CanManageUsers = UserRole + 13
|
CanManageUsers
|
||||||
CanJoin = UserRole + 14
|
CanJoin
|
||||||
IsMember = UserRole + 15
|
IsMember
|
||||||
UnviewedMessagesCount = UserRole + 16
|
UnviewedMessagesCount
|
||||||
CommunityColor = UserRole + 17
|
UnviewedMentionsCount
|
||||||
Muted = UserRole + 18
|
RequestsCount
|
||||||
|
CommunityColor
|
||||||
|
Muted
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
@ -75,6 +77,8 @@ QtObject:
|
|||||||
of "isMember": result = $community.isMember
|
of "isMember": result = $community.isMember
|
||||||
of "nbMembers": result = $community.members.len
|
of "nbMembers": result = $community.members.len
|
||||||
of "unviewedMessagesCount": result = $community.unviewedMessagesCount
|
of "unviewedMessagesCount": result = $community.unviewedMessagesCount
|
||||||
|
of "unviewedMentionsCount": result = $community.unviewedMentionsCount
|
||||||
|
of "requestsCount": result = $community.membershipRequests.len
|
||||||
of "thumbnailImage":
|
of "thumbnailImage":
|
||||||
if (not community.communityImage.isNil):
|
if (not community.communityImage.isNil):
|
||||||
result = community.communityImage.thumbnail
|
result = community.communityImage.thumbnail
|
||||||
@ -111,6 +115,8 @@ QtObject:
|
|||||||
of CommunityRoles.IsMember: result = newQVariant(communityItem.isMember.bool)
|
of CommunityRoles.IsMember: result = newQVariant(communityItem.isMember.bool)
|
||||||
of CommunityRoles.NumMembers: result = newQVariant(communityItem.members.len)
|
of CommunityRoles.NumMembers: result = newQVariant(communityItem.members.len)
|
||||||
of CommunityRoles.UnviewedMessagesCount: result = newQVariant(communityItem.unviewedMessagesCount)
|
of CommunityRoles.UnviewedMessagesCount: result = newQVariant(communityItem.unviewedMessagesCount)
|
||||||
|
of CommunityRoles.UnviewedMentionsCount: result = newQVariant(communityItem.unviewedMentionsCount)
|
||||||
|
of CommunityRoles.RequestsCount: result = newQVariant(communityItem.membershipRequests.len)
|
||||||
of CommunityRoles.ThumbnailImage:
|
of CommunityRoles.ThumbnailImage:
|
||||||
if (not communityItem.communityImage.isNil):
|
if (not communityItem.communityImage.isNil):
|
||||||
result = newQVariant(communityItem.communityImage.thumbnail)
|
result = newQVariant(communityItem.communityImage.thumbnail)
|
||||||
@ -145,17 +151,26 @@ QtObject:
|
|||||||
CommunityRoles.Muted.int: "muted",
|
CommunityRoles.Muted.int: "muted",
|
||||||
CommunityRoles.NumMembers.int: "nbMembers",
|
CommunityRoles.NumMembers.int: "nbMembers",
|
||||||
CommunityRoles.UnviewedMessagesCount.int: "unviewedMessagesCount",
|
CommunityRoles.UnviewedMessagesCount.int: "unviewedMessagesCount",
|
||||||
|
CommunityRoles.UnviewedMentionsCount.int: "unviewedMentionsCount",
|
||||||
|
CommunityRoles.RequestsCount.int: "requestsCount",
|
||||||
CommunityRoles.ThumbnailImage.int:"thumbnailImage",
|
CommunityRoles.ThumbnailImage.int:"thumbnailImage",
|
||||||
CommunityRoles.LargeImage.int:"largeImage",
|
CommunityRoles.LargeImage.int:"largeImage",
|
||||||
CommunityRoles.CommunityColor.int:"communityColor"
|
CommunityRoles.CommunityColor.int:"communityColor"
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
proc setNewData*(self: CommunityList, communityList: seq[Community]) =
|
proc setNewData*(self: CommunityList, communityList: var seq[Community]) =
|
||||||
|
for c in communityList.mitems:
|
||||||
|
c.recalculateUnviewedMessages()
|
||||||
|
c.recalculateMentions()
|
||||||
|
|
||||||
self.beginResetModel()
|
self.beginResetModel()
|
||||||
self.communities = communityList
|
self.communities = communityList
|
||||||
self.endResetModel()
|
self.endResetModel()
|
||||||
|
|
||||||
proc addCommunityItemToList*(self: CommunityList, community: Community) =
|
proc addCommunityItemToList*(self: CommunityList, community: var Community) =
|
||||||
|
community.recalculateUnviewedMessages()
|
||||||
|
community.recalculateMentions()
|
||||||
|
|
||||||
self.beginInsertRows(newQModelIndex(), self.communities.len, self.communities.len)
|
self.beginInsertRows(newQModelIndex(), self.communities.len, self.communities.len)
|
||||||
self.communities.add(community)
|
self.communities.add(community)
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
@ -218,8 +233,16 @@ QtObject:
|
|||||||
let bottomRight = self.createIndex(index, index, nil)
|
let bottomRight = self.createIndex(index, index, nil)
|
||||||
var oldCommunity = self.communities[index]
|
var oldCommunity = self.communities[index]
|
||||||
community.memberStatus = oldCommunity.memberStatus
|
community.memberStatus = oldCommunity.memberStatus
|
||||||
|
|
||||||
|
community.recalculateUnviewedMessages()
|
||||||
|
community.recalculateMentions()
|
||||||
|
|
||||||
self.communities[index] = community
|
self.communities[index] = community
|
||||||
self.dataChanged(topLeft, bottomRight, @[CommunityRoles.Name.int, CommunityRoles.Description.int, CommunityRoles.UnviewedMessagesCount.int, CommunityRoles.ThumbnailImage.int])
|
self.dataChanged(topLeft, bottomRight, @[CommunityRoles.Name.int,
|
||||||
|
CommunityRoles.Description.int,
|
||||||
|
CommunityRoles.UnviewedMessagesCount.int,
|
||||||
|
CommunityRoles.UnviewedMentionsCount.int,
|
||||||
|
CommunityRoles.ThumbnailImage.int])
|
||||||
|
|
||||||
proc removeCategoryFromCommunity*(self: CommunityList, communityId: string, categoryId:string) =
|
proc removeCategoryFromCommunity*(self: CommunityList, communityId: string, categoryId:string) =
|
||||||
var community = self.getCommunityById(communityId)
|
var community = self.getCommunityById(communityId)
|
||||||
@ -238,11 +261,14 @@ QtObject:
|
|||||||
# Clear unread messages for each channel in community.
|
# Clear unread messages for each channel in community.
|
||||||
for c in self.communities[idx].chats:
|
for c in self.communities[idx].chats:
|
||||||
c.unviewedMessagesCount = 0
|
c.unviewedMessagesCount = 0
|
||||||
|
c.unviewedMentionsCount = 0
|
||||||
|
|
||||||
let index = self.createIndex(idx, 0, nil)
|
let index = self.createIndex(idx, 0, nil)
|
||||||
self.communities[idx].unviewedMessagesCount = 0
|
self.communities[idx].unviewedMessagesCount = 0
|
||||||
|
self.communities[idx].unviewedMentionsCount = 0
|
||||||
|
|
||||||
self.dataChanged(index, index, @[CommunityRoles.UnviewedMessagesCount.int])
|
self.dataChanged(index, index, @[CommunityRoles.UnviewedMessagesCount.int,
|
||||||
|
CommunityRoles.UnviewedMentionsCount.int])
|
||||||
|
|
||||||
proc clearAllMentions*(self: CommunityList, communityId: string, clearFromChannels : bool) =
|
proc clearAllMentions*(self: CommunityList, communityId: string, clearFromChannels : bool) =
|
||||||
let idx = self.communities.findIndexById(communityId)
|
let idx = self.communities.findIndexById(communityId)
|
||||||
@ -254,6 +280,13 @@ QtObject:
|
|||||||
# as mentins are not exposed to qml using roles from this model.
|
# as mentins are not exposed to qml using roles from this model.
|
||||||
for c in self.communities[idx].chats:
|
for c in self.communities[idx].chats:
|
||||||
c.mentionsCount = 0
|
c.mentionsCount = 0
|
||||||
|
c.unviewedMentionsCount = 0
|
||||||
|
|
||||||
|
self.communities[idx].unviewedMentionsCount = 0
|
||||||
|
|
||||||
|
let index = self.createIndex(idx, 0, nil)
|
||||||
|
self.dataChanged(index, index, @[CommunityRoles.UnviewedMentionsCount.int,
|
||||||
|
CommunityRoles.ThumbnailImage.int])
|
||||||
|
|
||||||
# If we decide in one moment to expose mention role we should do that here.
|
# If we decide in one moment to expose mention role we should do that here.
|
||||||
|
|
||||||
@ -267,9 +300,17 @@ QtObject:
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.communities[comIndex].chats[chatIndex].mentionsCount.dec
|
self.communities[comIndex].chats[chatIndex].mentionsCount.dec
|
||||||
|
self.communities[comIndex].chats[chatIndex].unviewedMentionsCount.dec
|
||||||
|
|
||||||
proc incrementMentions*(self: CommunityList, channelId : string) =
|
self.communities[comIndex].unviewedMentionsCount.dec
|
||||||
for c in self.communities:
|
|
||||||
let chatIndex = c.chats.findIndexById(channelId)
|
let index = self.createIndex(comIndex, 0, nil)
|
||||||
if (chatIndex != -1):
|
self.dataChanged(index, index, @[CommunityRoles.UnviewedMentionsCount.int])
|
||||||
c.chats[chatIndex].mentionsCount.inc
|
|
||||||
|
proc updateMentions*(self: CommunityList, communityId : string) =
|
||||||
|
let comIndex = self.communities.findIndexById(communityId)
|
||||||
|
if (comIndex == -1):
|
||||||
|
return
|
||||||
|
self.communities[comIndex].recalculateMentions()
|
||||||
|
let index = self.createIndex(comIndex, 0, nil)
|
||||||
|
self.dataChanged(index, index, @[CommunityRoles.UnviewedMentionsCount.int])
|
@ -80,10 +80,11 @@ type Chat* = ref object
|
|||||||
lastClockValue*: int64 # indicates the last clock value to be used when sending messages
|
lastClockValue*: int64 # indicates the last clock value to be used when sending messages
|
||||||
deletedAtClockValue*: int64 # indicates the clock value at time of deletion, messages with lower clock value of this should be discarded
|
deletedAtClockValue*: int64 # indicates the clock value at time of deletion, messages with lower clock value of this should be discarded
|
||||||
unviewedMessagesCount*: int
|
unviewedMessagesCount*: int
|
||||||
|
unviewedMentionsCount*: int
|
||||||
lastMessage*: Message
|
lastMessage*: Message
|
||||||
members*: seq[ChatMember]
|
members*: seq[ChatMember]
|
||||||
membershipUpdateEvents*: seq[ChatMembershipEvent]
|
membershipUpdateEvents*: seq[ChatMembershipEvent]
|
||||||
mentionsCount*: int
|
mentionsCount*: int # Using this is not a good approach, we should instead use unviewedMentionsCount and refer to it always.
|
||||||
muted*: bool
|
muted*: bool
|
||||||
canPost*: bool
|
canPost*: bool
|
||||||
ensName*: string
|
ensName*: string
|
||||||
@ -128,6 +129,7 @@ type Community* = object
|
|||||||
members*: seq[string]
|
members*: seq[string]
|
||||||
access*: int
|
access*: int
|
||||||
unviewedMessagesCount*: int
|
unviewedMessagesCount*: int
|
||||||
|
unviewedMentionsCount*: int
|
||||||
admin*: bool
|
admin*: bool
|
||||||
joined*: bool
|
joined*: bool
|
||||||
verified*: bool
|
verified*: bool
|
||||||
@ -235,3 +237,18 @@ proc isAdmin*(self: Chat, pubKey: string): bool =
|
|||||||
if member.id == pubKey:
|
if member.id == pubKey:
|
||||||
return member.joined and member.admin
|
return member.joined and member.admin
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
proc recalculateUnviewedMessages*(community: var Community) =
|
||||||
|
var total = 0
|
||||||
|
for chat in community.chats:
|
||||||
|
total += chat.unviewedMessagesCount
|
||||||
|
|
||||||
|
community.unviewedMessagesCount = total
|
||||||
|
|
||||||
|
proc recalculateMentions*(community: var Community) =
|
||||||
|
echo "(recalculateMentions) chatId: ", community.id, " before: ", community.unviewedMentionsCount
|
||||||
|
var total = 0
|
||||||
|
for chat in community.chats:
|
||||||
|
total += chat.unviewedMentionsCount
|
||||||
|
|
||||||
|
community.unviewedMentionsCount = total
|
||||||
|
@ -174,6 +174,7 @@ proc toChat*(jsonChat: JsonNode): Chat =
|
|||||||
lastClockValue: jsonChat{"lastClockValue"}.getBiggestInt,
|
lastClockValue: jsonChat{"lastClockValue"}.getBiggestInt,
|
||||||
deletedAtClockValue: jsonChat{"deletedAtClockValue"}.getBiggestInt,
|
deletedAtClockValue: jsonChat{"deletedAtClockValue"}.getBiggestInt,
|
||||||
unviewedMessagesCount: jsonChat{"unviewedMessagesCount"}.getInt,
|
unviewedMessagesCount: jsonChat{"unviewedMessagesCount"}.getInt,
|
||||||
|
unviewedMentionsCount: jsonChat{"unviewedMentionsCount"}.getInt,
|
||||||
mentionsCount: 0,
|
mentionsCount: 0,
|
||||||
muted: false,
|
muted: false,
|
||||||
ensName: "",
|
ensName: "",
|
||||||
|
@ -171,7 +171,8 @@ StatusAppLayout {
|
|||||||
icon.color: model.communityColor
|
icon.color: model.communityColor
|
||||||
icon.source: model.thumbnailImage
|
icon.source: model.thumbnailImage
|
||||||
|
|
||||||
badge.visible: !checked && model.unviewedMessagesCount > 0
|
badge.value: model.unviewedMentionsCount + model.requestsCount
|
||||||
|
badge.visible: badge.value > 0 || (!checked && model.unviewedMessagesCount > 0)
|
||||||
badge.border.color: hovered ? Theme.palette.statusBadge.hoverBorderColor : Theme.palette.statusBadge.borderColor
|
badge.border.color: hovered ? Theme.palette.statusBadge.hoverBorderColor : Theme.palette.statusBadge.borderColor
|
||||||
badge.border.width: 2
|
badge.border.width: 2
|
||||||
badge.anchors.rightMargin: 4
|
badge.anchors.rightMargin: 4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user