From d6714141e0a68a148cd54355926bf59d4bf0dafb Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 6 May 2019 14:06:28 -0400 Subject: [PATCH] Update chatPage properly when roomCategory changes --- harmonyqml/backend/backend.py | 6 ++- harmonyqml/backend/model/list_model.py | 1 + harmonyqml/backend/signal_manager.py | 39 +++++++++++++++---- .../components/Chat/Banners/LeftBanner.qml | 1 - harmonyqml/components/Chat/Chat.qml | 10 ++++- .../Chat/RoomEventList/RoomEventList.qml | 3 +- 6 files changed, 46 insertions(+), 14 deletions(-) diff --git a/harmonyqml/backend/backend.py b/harmonyqml/backend/backend.py index f5bc02fa..3e3735cf 100644 --- a/harmonyqml/backend/backend.py +++ b/harmonyqml/backend/backend.py @@ -51,6 +51,10 @@ class Backend(QObject): def roomEvents(self): return self._room_events + @pyqtProperty("QVariant", constant=True) + def signals(self): + return self._signal_manager + @pyqtSlot(str, result="QVariant") @pyqtSlot(str, bool, result="QVariant") @@ -110,7 +114,7 @@ class Backend(QObject): ac = self.accounts re = self.roomEvents - tcl = lambda user: c[f"@test_{user}:matrix.org"] + tcl = lambda user: cl[f"@test_{user}:matrix.org"] import pdb from PyQt5.QtCore import pyqtRemoveInputHook diff --git a/harmonyqml/backend/model/list_model.py b/harmonyqml/backend/model/list_model.py index a9556d52..9a38b43f 100644 --- a/harmonyqml/backend/model/list_model.py +++ b/harmonyqml/backend/model/list_model.py @@ -155,6 +155,7 @@ class ListModel(QAbstractListModel): raise ValueError(f"No item in model data with " f"property {prop!r} set to {is_value!r}.") + from PyQt5.QtCore import pyqtRemoveInputHook as PRI; import pdb; PRI(); pdb.set_trace() @pyqtSlot(int, result="QVariant") diff --git a/harmonyqml/backend/signal_manager.py b/harmonyqml/backend/signal_manager.py index 53c0fcf6..97caf45c 100644 --- a/harmonyqml/backend/signal_manager.py +++ b/harmonyqml/backend/signal_manager.py @@ -4,7 +4,7 @@ from threading import Lock from typing import Any, Deque, Dict, List, Optional -from PyQt5.QtCore import QDateTime, QObject, pyqtBoundSignal +from PyQt5.QtCore import QDateTime, QObject, pyqtBoundSignal, pyqtSignal import nio from nio.rooms import MatrixRoom @@ -19,6 +19,8 @@ LeftEvent = Optional[Dict[str, str]] class SignalManager(QObject): + roomCategoryChanged = pyqtSignal(str, str, str, str) + _lock: Lock = Lock() def __init__(self, backend: Backend) -> None: @@ -92,8 +94,8 @@ class SignalManager(QObject): nio_room = client.nio.invited_rooms[room_id] categories = self.backend.accounts[client.userId].roomCategories - categories["Rooms"].rooms.pop(room_id, None) - categories["Left"].rooms.pop(room_id, None) + previous_room = categories["Rooms"].rooms.pop(room_id, None) + previous_left = categories["Left"].rooms.pop(room_id, None) categories["Invites"].rooms.upsert( where_main_key_is = room_id, @@ -108,13 +110,19 @@ class SignalManager(QObject): ignore_roles = ("typingUsers"), ) + signal = self.roomCategoryChanged + if previous_room: + signal.emit(client.userId, room_id, "Rooms", "Invites") + elif previous_left: + signal.emit(client.userId, room_id, "Left", "Invites") + def onRoomJoined(self, client: Client, room_id: str) -> None: nio_room = client.nio.rooms[room_id] categories = self.backend.accounts[client.userId].roomCategories - categories["Invites"].rooms.pop(room_id, None) - categories["Left"].rooms.pop(room_id, None) + previous_invite = categories["Invites"].rooms.pop(room_id, None) + previous_left = categories["Left"].rooms.pop(room_id, None) categories["Rooms"].rooms.upsert( where_main_key_is = room_id, @@ -127,6 +135,12 @@ class SignalManager(QObject): ignore_roles = ("typingUsers", "lastEventDateTime"), ) + signal = self.roomCategoryChanged + if previous_invite: + signal.emit(client.userId, room_id, "Invites", "Rooms") + elif previous_left: + signal.emit(client.userId, room_id, "Left", "Rooms") + def onRoomLeft(self, client: Client, @@ -134,9 +148,10 @@ class SignalManager(QObject): left_event: LeftEvent = None) -> None: categories = self.backend.accounts[client.userId].roomCategories - previous = categories["Rooms"].rooms.pop(room_id, None) - previous = previous or categories["Invites"].rooms.pop(room_id, None) - previous = previous or categories["Left"].rooms.get(room_id, None) + previous_room = categories["Rooms"].rooms.pop(room_id, None) + previous_invite = categories["Invites"].rooms.pop(room_id, None) + previous = previous_room or previous_invite or \ + categories["Left"].rooms.get(room_id, None) left_time = left_event.get("server_timestamp") if left_event else None @@ -156,6 +171,14 @@ class SignalManager(QObject): ignore_roles = ("typingUsers", "lastEventDateTime"), ) + signal = self.roomCategoryChanged + if previous_room: + signal.emit(client.userId, room_id, "Rooms", "Left") + elif previous_invite: + signal.emit(client.userId, room_id, "Invites", "Left") + + + def onRoomSyncPrevBatchTokenReceived(self, _: Client, room_id: str, diff --git a/harmonyqml/components/Chat/Banners/LeftBanner.qml b/harmonyqml/components/Chat/Banners/LeftBanner.qml index 57612fe2..1676333d 100644 --- a/harmonyqml/components/Chat/Banners/LeftBanner.qml +++ b/harmonyqml/components/Chat/Banners/LeftBanner.qml @@ -21,7 +21,6 @@ Banner { buttonCallbacks: { "forget": function(button) { button.loading = true - chatPage.canLoadPastEvents = false Backend.clients.get(chatPage.userId).forgetRoom(chatPage.roomId) pageStack.clear() }, diff --git a/harmonyqml/components/Chat/Chat.qml b/harmonyqml/components/Chat/Chat.qml index 1033ff42..d353e78b 100644 --- a/harmonyqml/components/Chat/Chat.qml +++ b/harmonyqml/components/Chat/Chat.qml @@ -14,11 +14,17 @@ HColumnLayout { .roomCategories.get(category) .rooms.get(roomId) - property bool canLoadPastEvents: true - id: chatPage onFocusChanged: sendBox.setFocus() + Component.onCompleted: Backend.signals.roomCategoryChanged.connect( + function(forUserId, forRoomId, previous, now) { + if (chatPage && forUserId == userId && forRoomId == roomId) { + chatPage.category = now + } + } + ) + RoomHeader { displayName: roomInfo.displayName topic: roomInfo.topic || "" diff --git a/harmonyqml/components/Chat/RoomEventList/RoomEventList.qml b/harmonyqml/components/Chat/RoomEventList/RoomEventList.qml index caaf8073..5cfe501e 100644 --- a/harmonyqml/components/Chat/RoomEventList/RoomEventList.qml +++ b/harmonyqml/components/Chat/RoomEventList/RoomEventList.qml @@ -2,7 +2,6 @@ import QtQuick 2.7 import "../../Base" HGlassRectangle { - property bool canLoadPastEvents: true property int space: 8 color: HStyle.chat.roomEventList.background @@ -29,7 +28,7 @@ HGlassRectangle { property real yPos: visibleArea.yPosition onYPosChanged: { - if (chatPage.canLoadPastEvents && yPos <= 0.1) { + if (chatPage.category != "Invites" && yPos <= 0.1) { Backend.loadPastEvents(chatPage.roomId) } }