diff --git a/src/app/chat/views/communities.nim b/src/app/chat/views/communities.nim index 6a2416ac82..ac96c7f929 100644 --- a/src/app/chat/views/communities.nim +++ b/src/app/chat/views/communities.nim @@ -39,6 +39,13 @@ QtObject: result.joinedCommunityList = newCommunityList(status) result.setup + 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 updateCommunityChat*(self: CommunitiesView, newChat: Chat) = var community = self.joinedCommunityList.getCommunityById(newChat.communityId) if (community.id == ""): @@ -53,6 +60,7 @@ QtObject: if (not found): community.chats.add(newChat) + self.calculateUnreadMessages(community) self.joinedCommunityList.replaceCommunity(community) if (self.activeCommunity.active and self.activeCommunity.communityItem.id == community.id): self.activeCommunity.changeChats(community.chats) diff --git a/src/app/chat/views/community_list.nim b/src/app/chat/views/community_list.nim index 34c6cb8dfd..2037ad310b 100644 --- a/src/app/chat/views/community_list.nim +++ b/src/app/chat/views/community_list.nim @@ -21,6 +21,7 @@ type CanManageUsers = UserRole + 13 CanJoin = UserRole + 14 IsMember = UserRole + 15 + UnviewedMessagesCount = UserRole + 16 QtObject: type @@ -65,6 +66,7 @@ QtObject: of CommunityRoles.CanJoin: result = newQVariant(communityItem.canJoin.bool) of CommunityRoles.IsMember: result = newQVariant(communityItem.isMember.bool) of CommunityRoles.NumMembers: result = newQVariant(communityItem.members.len) + of CommunityRoles.UnviewedMessagesCount: result = newQVariant(communityItem.unviewedMessagesCount) of CommunityRoles.ThumbnailImage: if (not communityItem.communityImage.isNil): result = newQVariant(communityItem.communityImage.thumbnail) @@ -91,6 +93,7 @@ QtObject: CommunityRoles.CanJoin.int: "canJoin", CommunityRoles.IsMember.int: "isMember", CommunityRoles.NumMembers.int: "nbMembers", + CommunityRoles.UnviewedMessagesCount.int: "unviewedMessagesCount", CommunityRoles.ThumbnailImage.int:"thumbnailImage", CommunityRoles.LargeImage.int:"largeImage" }.toTable @@ -130,4 +133,4 @@ QtObject: let topLeft = self.createIndex(index, index, nil) let bottomRight = self.createIndex(index, index, nil) self.communities[index] = community - self.dataChanged(topLeft, bottomRight, @[CommunityRoles.Name.int, CommunityRoles.Description.int]) \ No newline at end of file + self.dataChanged(topLeft, bottomRight, @[CommunityRoles.Name.int, CommunityRoles.Description.int, CommunityRoles.UnviewedMessagesCount.int]) \ No newline at end of file diff --git a/src/status/chat/chat.nim b/src/status/chat/chat.nim index 7c53bf8da1..28f723ade7 100644 --- a/src/status/chat/chat.nim +++ b/src/status/chat/chat.nim @@ -100,6 +100,7 @@ type Community* = object chats*: seq[Chat] members*: seq[string] access*: int + unviewedMessagesCount*: int admin*: bool joined*: bool verified*: bool diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityButton.qml b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityButton.qml index 569b6009ac..2375b2fa4b 100644 --- a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityButton.qml +++ b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityButton.qml @@ -8,7 +8,7 @@ import "../components" StatusIconTabButton { property string communityId: "" property string name: "channelName" - property string unviewedMessagesCount: "0" + property int unviewedMessagesCount: 0 property string image property bool hasMentions: false diff --git a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityList.qml b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityList.qml index 18b1e90be9..d5f077bccd 100644 --- a/ui/app/AppLayouts/Chat/CommunityComponents/CommunityList.qml +++ b/ui/app/AppLayouts/Chat/CommunityComponents/CommunityList.qml @@ -19,5 +19,6 @@ ListView { communityId: model.id name: model.name image: model.thumbnailImage + unviewedMessagesCount: model.unviewedMessagesCount } }