From b02fc11903bf06da845a5a29fe3e42997cb78bb2 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 7 Jul 2019 22:19:17 -0400 Subject: [PATCH] Remove forgotten rooms from the view --- TODO.md | 4 ++++ src/python/events/rooms.py | 3 +-- src/python/matrix_client.py | 5 +++++ src/qml/Base/HRoomAvatar.qml | 6 ++++-- src/qml/Chat/Banners/LeftBanner.qml | 7 ++----- src/qml/Chat/Chat.qml | 1 + src/qml/EventHandlers/rooms.js | 5 ++--- src/qml/Models/RoomCategories.qml | 9 +-------- src/qml/SidePane/RoomCategoriesList.qml | 6 ++++++ 9 files changed, 26 insertions(+), 20 deletions(-) diff --git a/TODO.md b/TODO.md index eae32b81..150fffd1 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,6 @@ +- room doesn't change category when accept/reject invite +- forget doesn't delete + - "rejoin" leftbanner button if room is public - daybreak color - html links color @@ -14,6 +17,7 @@ sticky avatar at top ability to cancel message being sent nio +set typing fix `RoomForgetResponse.create_error` OLD diff --git a/src/python/events/rooms.py b/src/python/events/rooms.py index 48f909c3..f95efd87 100644 --- a/src/python/events/rooms.py +++ b/src/python/events/rooms.py @@ -60,9 +60,8 @@ class RoomUpdated(Event): @dataclass -class RoomDeleted(Event): +class RoomForgotten(Event): user_id: str = field() - category: str = field() room_id: str = field() diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index f7c41706..94060ef1 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -188,6 +188,11 @@ class MatrixClient(nio.AsyncClient): return more_to_load + async def room_forget(self, room_id: str) -> None: + await super().room_forget(room_id) + rooms.RoomForgotten(user_id=self.user_id, room_id=room_id) + + # Callbacks for nio responses async def onSyncResponse(self, resp: nio.SyncResponse) -> None: diff --git a/src/qml/Base/HRoomAvatar.qml b/src/qml/Base/HRoomAvatar.qml index 3c6ab625..0c259368 100644 --- a/src/qml/Base/HRoomAvatar.qml +++ b/src/qml/Base/HRoomAvatar.qml @@ -3,8 +3,10 @@ import QtQuick 2.7 HAvatar { property string roomId: "" + // roomInfo ? → Avoid error messages when a room is forgotten readonly property var roomInfo: rooms.getWhere({"roomId": roomId}, 1)[0] - readonly property var dname: roomInfo.displayName + readonly property var dname: roomInfo ? roomInfo.displayName : "" + name: dname[0] == "#" && dname.length > 1 ? dname.substring(1) : dname - imageUrl: roomInfo.avatarUrl + imageUrl: roomInfo ? roomInfo.avatarUrl : null } diff --git a/src/qml/Chat/Banners/LeftBanner.qml b/src/qml/Chat/Banners/LeftBanner.qml index 7d534bab..ec45ae68 100644 --- a/src/qml/Chat/Banners/LeftBanner.qml +++ b/src/qml/Chat/Banners/LeftBanner.qml @@ -25,11 +25,8 @@ Banner { button.loading = true py.callClientCoro( chatPage.userId, "room_forget", [chatPage.roomId], {}, - function() { - button.loading = false - pageStack.clear() - } + function() { button.loading = false } ) - }, + } } } diff --git a/src/qml/Chat/Chat.qml b/src/qml/Chat/Chat.qml index a1a6bc46..98cae3d6 100644 --- a/src/qml/Chat/Chat.qml +++ b/src/qml/Chat/Chat.qml @@ -7,6 +7,7 @@ import "RoomSidePane" HColumnLayout { property var roomInfo: null + onRoomInfoChanged: if (! roomInfo) { pageStack.showPage("Default") } readonly property string userId: roomInfo.userId readonly property string category: roomInfo.category diff --git a/src/qml/EventHandlers/rooms.js b/src/qml/EventHandlers/rooms.js index 9f969830..7b02b747 100644 --- a/src/qml/EventHandlers/rooms.js +++ b/src/qml/EventHandlers/rooms.js @@ -79,9 +79,8 @@ function onRoomUpdated( } -function onRoomDeleted(user_id, category, room_id) { - var roles = {"userId": user_id, "roomId": room_id, "category": category} - rooms.popWhere(roles, 1) +function onRoomForgotten(user_id, room_id) { + rooms.popWhere({"userId": user_id, "roomId": room_id}) } diff --git a/src/qml/Models/RoomCategories.qml b/src/qml/Models/RoomCategories.qml index bacfe547..34799f47 100644 --- a/src/qml/Models/RoomCategories.qml +++ b/src/qml/Models/RoomCategories.qml @@ -1,11 +1,4 @@ import QtQuick 2.7 -import SortFilterProxyModel 0.2 import "../Base" -HListModel { - sorters: FilterSorter { - ValueFilter { roleName: "name"; value: "Invites" } - ValueFilter { roleName: "name"; value: "Rooms" } - ValueFilter { roleName: "name"; value: "Left" } - } -} +HListModel {} diff --git a/src/qml/SidePane/RoomCategoriesList.qml b/src/qml/SidePane/RoomCategoriesList.qml index 624db118..bda8af24 100644 --- a/src/qml/SidePane/RoomCategoriesList.qml +++ b/src/qml/SidePane/RoomCategoriesList.qml @@ -14,6 +14,12 @@ HListView { roleName: "userId" value: userId } + + sorters: FilterSorter { + ValueFilter { roleName: "name"; value: "Invites" } + ValueFilter { roleName: "name"; value: "Rooms" } + ValueFilter { roleName: "name"; value: "Left" } + } } delegate: RoomCategoryDelegate {}