Update chatPage properly when roomCategory changes
This commit is contained in:
parent
cdf6190cba
commit
d6714141e0
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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()
|
||||
},
|
||||
|
|
|
@ -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 || ""
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user