Working typing users bar
This commit is contained in:
parent
d28b95f7b7
commit
4c4603691f
|
@ -3,7 +3,9 @@ QT = quick
|
|||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
CONFIG += warn_off c++11 release
|
||||
dev {
|
||||
CONFIG -= warn_off release
|
||||
CONFIG += debug
|
||||
message($$CONFIG)
|
||||
}
|
||||
|
||||
BUILD_DIR = build
|
||||
|
|
|
@ -17,6 +17,7 @@ class RoomUpdated(Event):
|
|||
display_name: str = ""
|
||||
avatar_url: str = ""
|
||||
topic: str = ""
|
||||
typing_members: Sequence[str] = ()
|
||||
|
||||
inviter_id: str = ""
|
||||
left_event: Dict[str, str] = field(default_factory=dict)
|
||||
|
|
|
@ -7,7 +7,7 @@ import platform
|
|||
from contextlib import suppress
|
||||
from datetime import datetime
|
||||
from types import ModuleType
|
||||
from typing import DefaultDict, Dict, Optional, Type
|
||||
from typing import DefaultDict, Dict, List, Optional, Type
|
||||
from uuid import uuid4
|
||||
|
||||
import nio
|
||||
|
@ -216,6 +216,11 @@ class MatrixClient(nio.AsyncClient):
|
|||
if room_id not in self.backend.past_tokens:
|
||||
self.backend.past_tokens[room_id] = info.timeline.prev_batch
|
||||
|
||||
typing: List[str] = []
|
||||
for ev in info.ephemeral:
|
||||
if isinstance(ev, nio.TypingNoticeEvent):
|
||||
typing = ev.users
|
||||
|
||||
rooms.RoomUpdated(
|
||||
user_id = self.user_id,
|
||||
category = "Rooms",
|
||||
|
@ -223,6 +228,7 @@ class MatrixClient(nio.AsyncClient):
|
|||
display_name = self._get_room_name(room) or "",
|
||||
avatar_url = room.gen_avatar_url or "",
|
||||
topic = room.topic or "",
|
||||
typing_members = typing,
|
||||
)
|
||||
|
||||
for room_id, _ in resp.rooms.leave.items():
|
||||
|
|
|
@ -55,7 +55,7 @@ HColumnLayout {
|
|||
Layout.fillHeight: true
|
||||
}
|
||||
|
||||
//TypingMembersBar {}
|
||||
TypingMembersBar {}
|
||||
|
||||
InviteBanner {
|
||||
visible: category === "Invites"
|
||||
|
|
|
@ -1,22 +1,18 @@
|
|||
import QtQuick 2.7
|
||||
import QtQuick.Layouts 1.3
|
||||
import "../Base"
|
||||
import "utils.js" as ChatJS
|
||||
|
||||
HRectangle {
|
||||
property var typingMembers: chatPage.roomInfo.typingMembers
|
||||
|
||||
color: HStyle.chat.typingMembers.background
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumHeight: usersLabel.text ? usersLabel.implicitHeight : 0
|
||||
Layout.maximumHeight: Layout.minimumHeight
|
||||
Layout.preferredHeight: usersLabel.text ? usersLabel.implicitHeight : 0
|
||||
|
||||
HLabel {
|
||||
id: usersLabel
|
||||
anchors.fill: parent
|
||||
|
||||
text: ChatJS.getTypingMembersText(typingMembers, chatPage.userId)
|
||||
text: chatPage.roomInfo.typingText
|
||||
elide: Text.ElideMiddle
|
||||
maximumLineCount: 1
|
||||
}
|
||||
|
|
|
@ -39,21 +39,3 @@ function getLeftBannerAvatarName(leftEvent, accountId) {
|
|||
|
||||
return Backend.users.get(leftEvent.sender).displayName.value
|
||||
}
|
||||
|
||||
|
||||
function getTypingMembersText(users, ourAccountId) {
|
||||
var names = []
|
||||
|
||||
for (var i = 0; i < users.length; i++) {
|
||||
if (users[i] !== ourAccountId) {
|
||||
names.push(Backend.users.get(users[i]).displayName.value)
|
||||
}
|
||||
}
|
||||
|
||||
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…"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,27 @@
|
|||
function onRoomUpdated(user_id, category, room_id, display_name, avatar_url,
|
||||
topic, inviter_id, left_event) {
|
||||
function typingTextFor(members, our_user_id) {
|
||||
var names = []
|
||||
|
||||
for (var i = 0; i < members.length; i++) {
|
||||
if (members[i] != our_user_id) {
|
||||
names.push(users.getUser(members[i]).displayName)
|
||||
}
|
||||
}
|
||||
|
||||
if (names.length == 0) { return "" }
|
||||
if (names.length == 1) { return qsTr("%1 is typing...").arg(names[0]) }
|
||||
|
||||
var text = qsTr("%1 and %2 are typing...")
|
||||
|
||||
if (names.length == 2) { return text.arg(names[0]).arg(names[1]) }
|
||||
|
||||
return text.arg(names.slice(0, -1).join(", ")).arg(names.slice(-1)[0])
|
||||
}
|
||||
|
||||
|
||||
function onRoomUpdated(
|
||||
user_id, category, room_id, display_name, avatar_url, topic,
|
||||
typing_members, inviter_id, left_event
|
||||
) {
|
||||
roomCategories.upsert({"userId": user_id, "name": category}, {
|
||||
"userId": user_id,
|
||||
"name": category
|
||||
|
@ -37,8 +58,9 @@ function onRoomUpdated(user_id, category, room_id, display_name, avatar_url,
|
|||
"displayName": display_name,
|
||||
"avatarUrl": avatar_url,
|
||||
"topic": topic,
|
||||
"typingText": typingTextFor(typing_members, user_id),
|
||||
"inviterId": inviter_id,
|
||||
"leftEvent": left_event
|
||||
"leftEvent": left_event,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -98,3 +120,7 @@ function onTimelineEventReceived(
|
|||
|
||||
|
||||
var onTimelineMessageReceived = onTimelineEventReceived
|
||||
|
||||
|
||||
function onTypingNoticeEvent(room_id, members) {
|
||||
}
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
function arrayToModelItem(keys_name, array) {
|
||||
// Convert an array to an object suitable to be in a model, example:
|
||||
// [1, 2, 3] → [{keys_name: 1}, {keys_name: 2}, {keys_name: 3}]
|
||||
var items = []
|
||||
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
var obj = {}
|
||||
obj[keys_name] = array[i]
|
||||
items.push(obj)
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
|
||||
function stripUserId(user_id) {
|
||||
// Remove leading @
|
||||
return user_id.substring(1)
|
||||
|
|
Loading…
Reference in New Issue
Block a user