fix(@desktop/communities): improve member list sorting

This commit is contained in:
Andrei Smirnov 2021-08-18 12:33:49 +03:00 committed by Iuri Matias
parent a3ab31edba
commit 754e49bf0f
3 changed files with 56 additions and 14 deletions

View File

@ -11,6 +11,7 @@ Item {
property string lastSeen: ""
property string identicon
property int statusType: Constants.statusType_Online
property color offlineColor: Style.current.darkGrey
property bool hovered: false
property bool enableMouseArea: true
property var currentTime
@ -54,11 +55,10 @@ Item {
chatType: Constants.chatTypeOneToOne
identicon: wrapper.profileImage || wrapper.identicon
anchors.left: parent.left
anchors.leftMargin: Style.current.smallPadding
anchors.leftMargin: Style.current.padding
anchors.verticalCenter: parent.verticalCenter
}
StyledText {
id: contactInfo
text: Emoji.parse(Utils.removeStatusEns(Utils.filterXSS(wrapper.name))) + (isCurrentUser ? " " + qsTrId("(you)") : "")
@ -83,7 +83,7 @@ Item {
color: {
let lastSeenMinutesAgo = (currentTime/1000 - parseInt(lastSeen)) / 60
if (!chatsModel.isOnline) {
return Style.current.darkGrey
return offlineColor
}
if (isCurrentUser || lastSeenMinutesAgo < 5.5){
@ -92,7 +92,7 @@ Item {
return statusType == Constants.statusType_DoNotDisturb ? Style.current.red : Style.current.orange;
}
return Style.current.darkGrey
return offlineColor
}
}

View File

@ -27,6 +27,31 @@ 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
@ -36,6 +61,7 @@ Item {
opacity: (root.width > 50) ? 1.0 : 0.0
visible: (opacity > 0.1)
font.pixelSize: Style.current.primaryTextFontSize
font.bold: true
//% "Members"
text: qsTrId("members-label")
}
@ -49,31 +75,47 @@ Item {
topMargin: Style.current.padding
left: parent.left
right: parent.right
rightMargin: Style.current.halfPadding
rightMargin: Style.current.padding
bottom: parent.bottom
bottomMargin: Style.current.bigPadding
}
boundsBehavior: Flickable.StopAtBounds
model: userListDelegate
section.property: "online"
section.delegate: Item {
id: sectionItem
property bool online: !!section
width: parent.width
height: 24
StyledText {
anchors.fill: parent
anchors.leftMargin: Style.current.padding
font.pixelSize: Style.current.additionalTextSize
color: Style.current.darkGrey
text: sectionItem.online ? qsTr("Online") : qsTr("Offline")
}
}
}
DelegateModelGeneralized {
id: userListDelegate
lessThan: [
function(left, right) {
return left.lastSeen > right.lastSeen
return left.sortKey.localeCompare(right.sortKey) < 0
}
]
model: community.members
model: ListModel {
id: proxyModel
}
delegate: User {
property string nickname: appMain.getUserNickname(model.pubKey)
publicKey: model.pubKey
name: !model.userName.endsWith(".eth") && !!nickname ? nickname : Utils.removeStatusEns(model.userName)
name: model.name
identicon: model.identicon
lastSeen: chatsModel.communities.activeCommunity.memberLastSeen(model.pubKey)
statusType: chatsModel.communities.activeCommunity.memberStatus(model.pubKey)
lastSeen: model.lastSeen
statusType: model.statusType
currentTime: root.currentTime
offlineColor: "transparent"
}
}
}

View File

@ -42,8 +42,8 @@ StatusWindow {
objectName: "mainWindow"
minimumWidth: 900
minimumHeight: 600
width: 1232
height: 770
width: Math.min(1232, Screen.desktopAvailableWidth - 64)
height: Math.min(770, Screen.desktopAvailableHeight - 64)
color: Style.current.background
title: {
// Set application settings