Add users currently typing in room bar

This commit is contained in:
miruka
2019-04-14 16:12:07 -04:00
parent 14a76b710b
commit 8a3189df15
9 changed files with 85 additions and 21 deletions

View File

@@ -6,11 +6,13 @@ ColumnLayout {
property var user_id: null
property var room: null
id: chatPage
spacing: 0
onFocusChanged: sendBox.setFocus()
RoomHeader {}
MessageList {}
TypingUsersBar {}
SendBox { id: sendBox }
}

View File

@@ -0,0 +1,31 @@
import QtQuick 2.7
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.4
import "../base" as Base
import "utils.js" as ChatJS
Rectangle {
id: root
Layout.fillWidth: true
Layout.minimumHeight: usersLabel.text ? usersLabel.implicitHeight : 0
Layout.maximumHeight: Layout.minimumHeight
color: "#BBB"
Base.HLabel {
id: "usersLabel"
anchors.fill: parent
Timer {
interval: 500
repeat: true
running: true
triggeredOnStart: true
onTriggered: usersLabel.text = ChatJS.get_typing_users_text(
chatPage.user_id, chatPage.room.room_id
)
}
elide: Text.ElideMiddle
maximumLineCount: 1
}
}

View File

@@ -124,3 +124,21 @@ function get_member_event_text(dict) {
return ""
}
function get_typing_users_text(account_id, room_id) {
var names = []
var room = Backend.models.rooms.get(account_id)
.getWhere("room_id", room_id)
for (var i = 0; i < room.typing_users.length; i++) {
names.push(Backend.getUser(room.typing_users[i]).display_name)
}
if (names.length < 1) { return "" }
return "🖋 " +
[names.slice(0, -1).join(", "), names.slice(-1)[0]]
.join(names.length < 2 ? "" : " and ") +
(names.length > 1 ? " are" : " is") + " typing…"
}