Update chatPage properly when roomCategory changes

This commit is contained in:
miruka 2019-05-06 14:06:28 -04:00
parent cdf6190cba
commit d6714141e0
6 changed files with 46 additions and 14 deletions

View File

@ -51,6 +51,10 @@ class Backend(QObject):
def roomEvents(self): def roomEvents(self):
return self._room_events return self._room_events
@pyqtProperty("QVariant", constant=True)
def signals(self):
return self._signal_manager
@pyqtSlot(str, result="QVariant") @pyqtSlot(str, result="QVariant")
@pyqtSlot(str, bool, result="QVariant") @pyqtSlot(str, bool, result="QVariant")
@ -110,7 +114,7 @@ class Backend(QObject):
ac = self.accounts ac = self.accounts
re = self.roomEvents re = self.roomEvents
tcl = lambda user: c[f"@test_{user}:matrix.org"] tcl = lambda user: cl[f"@test_{user}:matrix.org"]
import pdb import pdb
from PyQt5.QtCore import pyqtRemoveInputHook from PyQt5.QtCore import pyqtRemoveInputHook

View File

@ -155,6 +155,7 @@ class ListModel(QAbstractListModel):
raise ValueError(f"No item in model data with " raise ValueError(f"No item in model data with "
f"property {prop!r} set to {is_value!r}.") 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") @pyqtSlot(int, result="QVariant")

View File

@ -4,7 +4,7 @@
from threading import Lock from threading import Lock
from typing import Any, Deque, Dict, List, Optional 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 import nio
from nio.rooms import MatrixRoom from nio.rooms import MatrixRoom
@ -19,6 +19,8 @@ LeftEvent = Optional[Dict[str, str]]
class SignalManager(QObject): class SignalManager(QObject):
roomCategoryChanged = pyqtSignal(str, str, str, str)
_lock: Lock = Lock() _lock: Lock = Lock()
def __init__(self, backend: Backend) -> None: def __init__(self, backend: Backend) -> None:
@ -92,8 +94,8 @@ class SignalManager(QObject):
nio_room = client.nio.invited_rooms[room_id] nio_room = client.nio.invited_rooms[room_id]
categories = self.backend.accounts[client.userId].roomCategories categories = self.backend.accounts[client.userId].roomCategories
categories["Rooms"].rooms.pop(room_id, None) previous_room = categories["Rooms"].rooms.pop(room_id, None)
categories["Left"].rooms.pop(room_id, None) previous_left = categories["Left"].rooms.pop(room_id, None)
categories["Invites"].rooms.upsert( categories["Invites"].rooms.upsert(
where_main_key_is = room_id, where_main_key_is = room_id,
@ -108,13 +110,19 @@ class SignalManager(QObject):
ignore_roles = ("typingUsers"), 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: def onRoomJoined(self, client: Client, room_id: str) -> None:
nio_room = client.nio.rooms[room_id] nio_room = client.nio.rooms[room_id]
categories = self.backend.accounts[client.userId].roomCategories categories = self.backend.accounts[client.userId].roomCategories
categories["Invites"].rooms.pop(room_id, None) previous_invite = categories["Invites"].rooms.pop(room_id, None)
categories["Left"].rooms.pop(room_id, None) previous_left = categories["Left"].rooms.pop(room_id, None)
categories["Rooms"].rooms.upsert( categories["Rooms"].rooms.upsert(
where_main_key_is = room_id, where_main_key_is = room_id,
@ -127,6 +135,12 @@ class SignalManager(QObject):
ignore_roles = ("typingUsers", "lastEventDateTime"), 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, def onRoomLeft(self,
client: Client, client: Client,
@ -134,9 +148,10 @@ class SignalManager(QObject):
left_event: LeftEvent = None) -> None: left_event: LeftEvent = None) -> None:
categories = self.backend.accounts[client.userId].roomCategories categories = self.backend.accounts[client.userId].roomCategories
previous = categories["Rooms"].rooms.pop(room_id, None) previous_room = categories["Rooms"].rooms.pop(room_id, None)
previous = previous or categories["Invites"].rooms.pop(room_id, None) previous_invite = categories["Invites"].rooms.pop(room_id, None)
previous = previous or categories["Left"].rooms.get(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 left_time = left_event.get("server_timestamp") if left_event else None
@ -156,6 +171,14 @@ class SignalManager(QObject):
ignore_roles = ("typingUsers", "lastEventDateTime"), 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, def onRoomSyncPrevBatchTokenReceived(self,
_: Client, _: Client,
room_id: str, room_id: str,

View File

@ -21,7 +21,6 @@ Banner {
buttonCallbacks: { buttonCallbacks: {
"forget": function(button) { "forget": function(button) {
button.loading = true button.loading = true
chatPage.canLoadPastEvents = false
Backend.clients.get(chatPage.userId).forgetRoom(chatPage.roomId) Backend.clients.get(chatPage.userId).forgetRoom(chatPage.roomId)
pageStack.clear() pageStack.clear()
}, },

View File

@ -14,11 +14,17 @@ HColumnLayout {
.roomCategories.get(category) .roomCategories.get(category)
.rooms.get(roomId) .rooms.get(roomId)
property bool canLoadPastEvents: true
id: chatPage id: chatPage
onFocusChanged: sendBox.setFocus() onFocusChanged: sendBox.setFocus()
Component.onCompleted: Backend.signals.roomCategoryChanged.connect(
function(forUserId, forRoomId, previous, now) {
if (chatPage && forUserId == userId && forRoomId == roomId) {
chatPage.category = now
}
}
)
RoomHeader { RoomHeader {
displayName: roomInfo.displayName displayName: roomInfo.displayName
topic: roomInfo.topic || "" topic: roomInfo.topic || ""

View File

@ -2,7 +2,6 @@ import QtQuick 2.7
import "../../Base" import "../../Base"
HGlassRectangle { HGlassRectangle {
property bool canLoadPastEvents: true
property int space: 8 property int space: 8
color: HStyle.chat.roomEventList.background color: HStyle.chat.roomEventList.background
@ -29,7 +28,7 @@ HGlassRectangle {
property real yPos: visibleArea.yPosition property real yPos: visibleArea.yPosition
onYPosChanged: { onYPosChanged: {
if (chatPage.canLoadPastEvents && yPos <= 0.1) { if (chatPage.category != "Invites" && yPos <= 0.1) {
Backend.loadPastEvents(chatPage.roomId) Backend.loadPastEvents(chatPage.roomId)
} }
} }