Addressed PR comments
This commit is contained in:
parent
8e0db42cde
commit
99bdfc65ed
|
@ -42,7 +42,7 @@ QtObject:
|
|||
self.communityItem = communityItem
|
||||
self.chats.setChats(communityItem.chats)
|
||||
self.categories.setCategories(communityItem.categories)
|
||||
self.members.setMembers(communityItem.members)
|
||||
self.members.setCommunity(communityItem)
|
||||
self.nbMembersChanged()
|
||||
self.communityMembershipRequestList.setNewData(communityItem.membershipRequests)
|
||||
|
||||
|
@ -138,7 +138,7 @@ QtObject:
|
|||
QtProperty[bool] isMember:
|
||||
read = isMember
|
||||
|
||||
proc nbMembers*(self: CommunityItemView): int {.slot.} = result = ?.self.members.members.len
|
||||
proc nbMembers*(self: CommunityItemView): int {.slot.} = result = ?.self.communityItem.members.len
|
||||
|
||||
QtProperty[int] nbMembers:
|
||||
read = nbMembers
|
||||
|
@ -208,7 +208,7 @@ QtObject:
|
|||
result = self.communityItem.memberStatus[pubKey].statusType.int
|
||||
|
||||
proc hasMember*(self: CommunityItemView, pubKey: string): bool {.slot.} =
|
||||
result = self.members.members.contains(pubKey)
|
||||
result = self.communityItem.members.contains(pubKey)
|
||||
|
||||
QtProperty[QVariant] members:
|
||||
read = getMembers
|
||||
|
|
|
@ -1,37 +1,43 @@
|
|||
import NimQml, Tables,
|
||||
../../../status/[status, ens]
|
||||
import NimQml, Tables
|
||||
import ../../../status/types as status_types
|
||||
import ../../../status/[chat/chat, ens, status, settings]
|
||||
|
||||
type
|
||||
CommunityMembersRoles {.pure.} = enum
|
||||
UserName = UserRole + 1,
|
||||
PubKey = UserRole + 2,
|
||||
Identicon = UserRole + 3
|
||||
Identicon = UserRole + 3,
|
||||
LastSeen = UserRole + 4,
|
||||
StatusType = UserRole + 5,
|
||||
Online = UserRole + 6,
|
||||
SortKey = UserRole + 7
|
||||
|
||||
QtObject:
|
||||
type
|
||||
CommunityMembersView* = ref object of QAbstractListModel
|
||||
status: Status
|
||||
members*: seq[string]
|
||||
myPubKey: string
|
||||
community*: Community
|
||||
|
||||
proc setup(self: CommunityMembersView) = self.QAbstractListModel.setup
|
||||
|
||||
proc delete(self: CommunityMembersView) =
|
||||
self.members = @[]
|
||||
self.QAbstractListModel.delete
|
||||
|
||||
proc newCommunityMembersView*(status: Status): CommunityMembersView =
|
||||
new(result, delete)
|
||||
result.members = @[]
|
||||
result.status = status
|
||||
result.setup()
|
||||
|
||||
proc setMembers*(self: CommunityMembersView, members: seq[string]) =
|
||||
proc setCommunity*(self: CommunityMembersView, community: Community) =
|
||||
self.beginResetModel()
|
||||
self.members = members
|
||||
self.community = community
|
||||
self.myPubKey = self.status.settings.getSetting[:string](Setting.PublicKey, "0x0")
|
||||
self.endResetModel()
|
||||
|
||||
proc getIndexFromPubKey*(self: CommunityMembersView, pubKey: string): int =
|
||||
var i = 0
|
||||
for memberPubKey in self.members:
|
||||
for memberPubKey in self.community.members:
|
||||
if (memberPubKey == pubKey):
|
||||
return i
|
||||
i = i + 1
|
||||
|
@ -42,10 +48,11 @@ QtObject:
|
|||
if (memberIndex == -1):
|
||||
return
|
||||
self.beginRemoveRows(newQModelIndex(), memberIndex, memberIndex)
|
||||
self.members.delete(memberIndex)
|
||||
self.community.members.delete(memberIndex)
|
||||
self.endRemoveRows()
|
||||
|
||||
method rowCount(self: CommunityMembersView, index: QModelIndex = nil): int = self.members.len
|
||||
method rowCount(self: CommunityMembersView, index: QModelIndex = nil): int =
|
||||
self.community.members.len
|
||||
|
||||
proc userName(self: CommunityMembersView, pk: string, alias: string): string =
|
||||
if self.status.chat.contacts.hasKey(pk):
|
||||
|
@ -69,23 +76,49 @@ QtObject:
|
|||
if self.status.chat.contacts.hasKey(pk):
|
||||
result = self.status.chat.contacts[pk].localNickname
|
||||
|
||||
proc memberLastSeen(self: CommunityMembersView, pk: string): string =
|
||||
if self.community.memberStatus.hasKey(pk):
|
||||
result = $self.community.memberStatus[pk].clock
|
||||
else:
|
||||
result = "0"
|
||||
|
||||
proc memberStatus(self: CommunityMembersView, pk: string): int =
|
||||
if self.community.memberStatus.hasKey(pk):
|
||||
result = self.community.memberStatus[pk].statusType.int
|
||||
|
||||
proc isOnline(self: CommunityMembersView, pk: string): bool =
|
||||
if self.myPubKey == pk:
|
||||
return true
|
||||
if self.community.memberStatus.hasKey(pk):
|
||||
result = self.community.memberStatus[pk].statusType.int == StatusUpdateType.Online.int
|
||||
|
||||
proc sortKey(self: CommunityMembersView, pk: string): string =
|
||||
let name = self.userName(pk, self.alias(pk))
|
||||
if self.isOnline(pk):
|
||||
return "A" & name
|
||||
return "B" & name
|
||||
|
||||
method data(self: CommunityMembersView, index: QModelIndex, role: int): QVariant =
|
||||
if not index.isValid:
|
||||
return
|
||||
if index.row < 0 or index.row >= self.members.len:
|
||||
if index.row < 0 or index.row >= self.community.members.len:
|
||||
return
|
||||
|
||||
let communityMemberPubkey = self.members[index.row]
|
||||
let communityMemberPubkey = self.community.members[index.row]
|
||||
let communityMemberRole = role.CommunityMembersRoles
|
||||
case communityMemberRole:
|
||||
of CommunityMembersRoles.UserName: result = newQVariant(self.userName(communityMemberPubkey, self.alias(communityMemberPubkey)))
|
||||
of CommunityMembersRoles.PubKey: result = newQVariant(communityMemberPubkey)
|
||||
of CommunityMembersRoles.Identicon: result = newQVariant(self.identicon(communityMemberPubkey))
|
||||
of CommunityMembersRoles.LastSeen: result = newQVariant(self.memberLastSeen(communityMemberPubkey))
|
||||
of CommunityMembersRoles.StatusType: result = newQVariant(self.memberStatus(communityMemberPubkey))
|
||||
of CommunityMembersRoles.Online: result = newQVariant(self.isOnline(communityMemberPubkey))
|
||||
of CommunityMembersRoles.SortKey: result = newQVariant(self.sortKey(communityMemberPubkey))
|
||||
|
||||
proc rowData(self: CommunityMembersView, index: int, column: string): string {.slot.} =
|
||||
if (index >= self.members.len):
|
||||
if (index >= self.community.members.len):
|
||||
return
|
||||
let communityMemberPubkey = self.members[index]
|
||||
let communityMemberPubkey = self.community.members[index]
|
||||
case column:
|
||||
of "alias": result = self.alias(communityMemberPubkey)
|
||||
of "address": result = communityMemberPubkey
|
||||
|
@ -97,7 +130,11 @@ QtObject:
|
|||
{
|
||||
CommunityMembersRoles.UserName.int:"userName",
|
||||
CommunityMembersRoles.PubKey.int:"pubKey",
|
||||
CommunityMembersRoles.Identicon.int:"identicon"
|
||||
CommunityMembersRoles.Identicon.int:"identicon",
|
||||
CommunityMembersRoles.LastSeen.int:"lastSeen",
|
||||
CommunityMembersRoles.StatusType.int:"statusType",
|
||||
CommunityMembersRoles.Online.int:"online",
|
||||
CommunityMembersRoles.SortKey.int:"sortKey"
|
||||
}.toTable
|
||||
|
||||
proc triggerUpdate*(self: CommunityMembersView) =
|
||||
|
|
|
@ -27,31 +27,6 @@ Item {
|
|||
|
||||
property QtObject community: chatsModel.communities.activeCommunity
|
||||
|
||||
onCommunityChanged: {
|
||||
proxyModel.clear()
|
||||
for (let r = 0; r < community.members.rowCount(); r++) {
|
||||
const pubKey = community.members.rowData(r, "address")
|
||||
const nickname = appMain.getUserNickname(pubKey)
|
||||
const identicon = community.members.rowData(r, "identicon")
|
||||
const ensName = community.members.rowData(r, "ensName")
|
||||
const name = !ensName.endsWith(".eth") && !!nickname ? nickname : Utils.removeStatusEns(ensName)
|
||||
const statusType = chatsModel.communities.activeCommunity.memberStatus(pubKey)
|
||||
const lastSeen = chatsModel.communities.activeCommunity.memberLastSeen(pubKey)
|
||||
const lastSeenMinutesAgo = (currentTime / 1000 - parseInt(lastSeen)) / 60
|
||||
const online = (pubKey === profileModel.profile.pubKey) || (lastSeenMinutesAgo < 7)
|
||||
|
||||
proxyModel.append({
|
||||
pubKey: pubKey,
|
||||
name: name,
|
||||
identicon: identicon,
|
||||
lastSeen: lastSeen,
|
||||
statusType: statusType,
|
||||
online: online,
|
||||
sortKey: "%1%2".arg(online ? "A" : "B").arg(name)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
StyledText {
|
||||
id: titleText
|
||||
anchors.top: parent.top
|
||||
|
@ -103,12 +78,10 @@ Item {
|
|||
return left.sortKey.localeCompare(right.sortKey) < 0
|
||||
}
|
||||
]
|
||||
model: ListModel {
|
||||
id: proxyModel
|
||||
}
|
||||
model: community.members
|
||||
delegate: User {
|
||||
publicKey: model.pubKey
|
||||
name: model.name
|
||||
name: model.userName
|
||||
identicon: model.identicon
|
||||
lastSeen: model.lastSeen
|
||||
statusType: model.statusType
|
||||
|
|
Loading…
Reference in New Issue