diff --git a/TODO.md b/TODO.md index 6b3d4690..8ab0c92c 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,4 @@ +- "rejoin" leftbanner button if room is public - daybreak color - html links color - invite/leave/forget backend funcs @@ -82,6 +83,7 @@ OLD - `org.matrix.room.preview_urls` event - `m.room.aliases` event - Support "Empty room (was ...)" after peer left + - Previewing room without joining - Distribution - List dependencies diff --git a/src/python/events/rooms.py b/src/python/events/rooms.py index c1e8ac8c..3fb9d4d1 100644 --- a/src/python/events/rooms.py +++ b/src/python/events/rooms.py @@ -1,6 +1,6 @@ from datetime import datetime from enum import auto -from typing import Dict, List, Optional, Sequence, Type, Union +from typing import List, Sequence, Type, Union from dataclasses import dataclass, field @@ -19,9 +19,7 @@ class RoomUpdated(Event): avatar_url: str = "" topic: str = "" typing_members: Sequence[str] = () - - inviter_id: str = "" - left_event: Optional[nio.RoomMemberEvent] = None + inviter_id: str = "" @classmethod @@ -29,8 +27,7 @@ class RoomUpdated(Event): user_id: str, category: str, room: MatrixRoom, - info: nio.RoomInfo, - **fields) -> "RoomUpdated": + info: nio.RoomInfo) -> "RoomUpdated": typing: List[str] = [] @@ -54,7 +51,6 @@ class RoomUpdated(Event): topic = room.topic or "", inviter_id = getattr(room, "inviter", "") or "", typing_members = typing, - **fields ) diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index c61d4977..2c5d93ee 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -198,15 +198,17 @@ class MatrixClient(nio.AsyncClient): up(self.user_id, "Rooms", self.rooms[room_id], info) for room_id, info in resp.rooms.leave.items(): - lev = None + # TODO: handle in nio, these are rooms that were left before + # starting the client. + if room_id not in self.rooms: + continue + # TODO: handle left events in nio async client for ev in info.timeline.events: - is_member_ev = isinstance(ev, nio.RoomMemberEvent) + if isinstance(ev, nio.RoomMemberEvent): + await self.onRoomMemberEvent(self.rooms[room_id], ev) - if is_member_ev and ev.membership in ("leave", "ban"): - lev = ev - - up(self.user_id, "Left", self.rooms[room_id], info, left_event=lev) + up(self.user_id, "Left", self.rooms[room_id], info) async def onErrorResponse(self, resp: nio.ErrorResponse) -> None: @@ -273,7 +275,7 @@ class MatrixClient(nio.AsyncClient): TimelineEventReceived.from_nio(room, ev, content=co) - async def _get_room_member_event_content(self, ev) -> Optional[str]: + async def get_room_member_event_content(self, ev) -> Optional[str]: prev = ev.prev_content now = ev.content membership = ev.membership @@ -345,7 +347,7 @@ class MatrixClient(nio.AsyncClient): status_message = "", # TODO ) - co = await self._get_room_member_event_content(ev) + co = await self.get_room_member_event_content(ev) if co is not None: TimelineEventReceived.from_nio(room, ev, content=co) diff --git a/src/qml/Base/HAvatar.qml b/src/qml/Base/HAvatar.qml index e35f6000..62f0a4f9 100644 --- a/src/qml/Base/HAvatar.qml +++ b/src/qml/Base/HAvatar.qml @@ -30,9 +30,10 @@ Rectangle { HImage { z: 2 anchors.fill: parent - visible: ! hidden && imageUrl + //visible: ! hidden && imageUrl + visible: false - Component.onCompleted: if (imageUrl) { source = imageUrl } + //Component.onCompleted: if (imageUrl) { source = imageUrl } fillMode: Image.PreserveAspectCrop sourceSize.width: dimension } diff --git a/src/qml/Chat/Banners/InviteBanner.qml b/src/qml/Chat/Banners/InviteBanner.qml index 3e14c389..0e078354 100644 --- a/src/qml/Chat/Banners/InviteBanner.qml +++ b/src/qml/Chat/Banners/InviteBanner.qml @@ -10,7 +10,8 @@ Banner { color: theme.chat.inviteBanner.background - avatar.name: inviterId ? inviterInfo.displayName : "" + avatar.name: inviterId ? (inviterInfo.displayName || + Utils.stripUserId(inviterId)) : "" avatar.imageUrl: inviterId ? inviterInfo.avatarUrl : "" labelText: qsTr("%1 invited you to join the room.").arg( diff --git a/src/qml/Chat/Banners/LeftBanner.qml b/src/qml/Chat/Banners/LeftBanner.qml index 7f4a0ff8..f1ae03c6 100644 --- a/src/qml/Chat/Banners/LeftBanner.qml +++ b/src/qml/Chat/Banners/LeftBanner.qml @@ -1,14 +1,17 @@ import QtQuick 2.7 import "../../Base" -import "../utils.js" as ChatJS +import "../../utils.js" as Utils Banner { - property var leftEvent: null + property string userId: "" + readonly property var userInfo: users.getUser(userId) color: theme.chat.leftBanner.background - avatar.name: ChatJS.getLeftBannerAvatarName(leftEvent, chatPage.userId) - labelText: ChatJS.getLeftBannerText(leftEvent) + // TODO: avatar func auto + avatar.name: userInfo.displayName || Utils.stripUserId(userId) + avatar.imageUrl: users.getUser(userId).avatarUrl + labelText: qsTr("You are not part of this room anymore.") buttonModel: [ { @@ -21,8 +24,13 @@ Banner { buttonCallbacks: { "forget": function(button) { button.loading = true - Backend.clients.get(chatPage.userId).forgetRoom(chatPage.roomId) - pageStack.clear() + py.callClientCoro( + chatPage.userId, "room_forget", [chatPage.roomId], {}, + function() { + button.loading = false + pageStack.clear() + } + ) }, } } diff --git a/src/qml/Chat/Chat.qml b/src/qml/Chat/Chat.qml index 1b694582..d841a368 100644 --- a/src/qml/Chat/Chat.qml +++ b/src/qml/Chat/Chat.qml @@ -14,8 +14,8 @@ HColumnLayout { {"userId": userId, "roomId": roomId, "category": category}, 1 )[0] - readonly property var sender: - users.getWhere({"userId": userId}, 1)[0] + readonly property var sender: //TODO: info$ + users.getUser(userId) readonly property bool hasUnknownDevices: false //category == "Rooms" ? @@ -73,10 +73,10 @@ HColumnLayout { visible: category == "Rooms" && ! hasUnknownDevices } - //LeftBanner { - //visible: category == "Left" - //leftEvent: roomInfo.leftEvent - //} + LeftBanner { + visible: category == "Left" + userId: chatPage.userId + } } // RoomSidePane { diff --git a/src/qml/EventHandlers/rooms.js b/src/qml/EventHandlers/rooms.js index 82634560..9686084f 100644 --- a/src/qml/EventHandlers/rooms.js +++ b/src/qml/EventHandlers/rooms.js @@ -25,7 +25,7 @@ function typingTextFor(members, our_user_id) { function onRoomUpdated( user_id, category, room_id, display_name, avatar_url, topic, - typing_members, inviter_id, left_event + typing_members, inviter_id ) { roomCategories.upsert({"userId": user_id, "name": category}, { "userId": user_id, @@ -50,8 +50,7 @@ function onRoomUpdated( "avatarUrl": avatar_url, "topic": topic, "typingText": typingTextFor(typing_members, user_id), - "inviterId": inviter_id, - "leftEvent": left_event ? py.getattr(left_event, "__dict__") : {}, + "inviterId": inviter_id }) }