Update presence dynamically and reduce allocations
2 files changed, 25 insertions, 4 deletions
diff --git a/resources/qml/Avatar.qml b/resources/qml/Avatar.qml
index 27d139d4..b055d452 100644
--- a/resources/qml/Avatar.qml
+++ b/resources/qml/Avatar.qml
@@ -87,14 +87,18 @@ Rectangle {
}
Rectangle {
+ id: onlineIndicator
+
anchors.bottom: avatar.bottom
anchors.right: avatar.right
visible: !!userid
height: avatar.height / 6
width: height
radius: Settings.avatarCircles ? height / 2 : height / 8
- color: {
- switch (TimelineManager.userPresence(userid)) {
+ color: updatePresence()
+
+ function updatePresence() {
+ switch (Presence.userPresence(userid)) {
case "online":
return "#00cc66";
case "unavailable":
@@ -102,7 +106,15 @@ Rectangle {
case "offline":
default:
// return "#a82353" don't show anything if offline, since it is confusing, if presence is disabled
- "transparent";
+ return "transparent";
+ }
+ }
+
+ Connections {
+ target: Presence
+
+ function onPresenceChanged(id) {
+ if (id == userid) onlineIndicator.color = onlineIndicator.updatePresence();
}
}
}
diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml
index 62f7735b..adbc9d70 100644
--- a/resources/qml/MessageView.qml
+++ b/resources/qml/MessageView.qml
@@ -329,12 +329,21 @@ ScrollView {
}
Label {
+ id: statusMsg
color: Nheko.colors.buttonText
- text: TimelineManager.userStatus(userId)
+ text: Presence.userStatus(userId)
textFormat: Text.PlainText
elide: Text.ElideRight
width: chat.delegateMaxWidth - parent.spacing * 2 - userName.implicitWidth - Nheko.avatarSize
font.italic: true
+
+ Connections {
+ target: Presence
+
+ function onPresenceChanged(id) {
+ if (id == userId) statusMsg.text = Presence.userStatus(userId);
+ }
+ }
}
}
|