feat: show unviewed count on the community button

This commit is contained in:
Jonathan Rainville 2021-02-22 13:53:47 -05:00 committed by Iuri Matias
parent b76cb5682c
commit f8704d7b64
5 changed files with 15 additions and 2 deletions

View File

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

View File

@ -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])
self.dataChanged(topLeft, bottomRight, @[CommunityRoles.Name.int, CommunityRoles.Description.int, CommunityRoles.UnviewedMessagesCount.int])

View File

@ -100,6 +100,7 @@ type Community* = object
chats*: seq[Chat]
members*: seq[string]
access*: int
unviewedMessagesCount*: int
admin*: bool
joined*: bool
verified*: bool

View File

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

View File

@ -19,5 +19,6 @@ ListView {
communityId: model.id
name: model.name
image: model.thumbnailImage
unviewedMessagesCount: model.unviewedMessagesCount
}
}