Add sortedMembers to Room ListItems
This commit is contained in:
parent
c67e1bfc79
commit
68b6899de1
|
@ -1,11 +1,12 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
from PyQt5.QtCore import QDateTime, QSortFilterProxyModel
|
from PyQt5.QtCore import QDateTime
|
||||||
|
|
||||||
from ..pyqt_future import PyQtFuture
|
from ..pyqt_future import PyQtFuture
|
||||||
from .list_item import ListItem
|
from .list_item import ListItem
|
||||||
from .list_model import ListModel
|
from .list_model import ListModel
|
||||||
|
from .sort_filter_proxy import SortFilterProxy
|
||||||
|
|
||||||
|
|
||||||
class Account(ListItem):
|
class Account(ListItem):
|
||||||
|
@ -22,19 +23,22 @@ class RoomCategory(ListItem):
|
||||||
|
|
||||||
name: str = ""
|
name: str = ""
|
||||||
rooms: ListModel = ListModel()
|
rooms: ListModel = ListModel()
|
||||||
sortedRooms: QSortFilterProxyModel = QSortFilterProxyModel()
|
sortedRooms: SortFilterProxy = SortFilterProxy(ListModel(), "", "")
|
||||||
|
|
||||||
|
|
||||||
class Room(ListItem):
|
class Room(ListItem):
|
||||||
_required_init_values = {"roomId", "displayName", "members"}
|
_required_init_values = {"roomId", "displayName", "members",
|
||||||
_constant = {"roomId", "members"}
|
"sortedMembers"}
|
||||||
|
_constant = {"roomId", "members", "sortedMembers"}
|
||||||
|
|
||||||
roomId: str = ""
|
roomId: str = ""
|
||||||
displayName: str = ""
|
displayName: str = ""
|
||||||
topic: Optional[str] = None
|
topic: Optional[str] = None
|
||||||
lastEventDateTime: Optional[QDateTime] = None
|
lastEventDateTime: Optional[QDateTime] = None
|
||||||
typingMembers: List[str] = []
|
typingMembers: List[str] = []
|
||||||
|
|
||||||
members: ListModel = ListModel()
|
members: ListModel = ListModel()
|
||||||
|
sortedMembers: SortFilterProxy = SortFilterProxy(ListModel(), "", "")
|
||||||
|
|
||||||
inviter: Optional[Dict[str, str]] = None
|
inviter: Optional[Dict[str, str]] = None
|
||||||
leftEvent: Optional[Dict[str, str]] = None
|
leftEvent: Optional[Dict[str, str]] = None
|
||||||
|
|
|
@ -166,6 +166,13 @@ class SignalManager(QObject):
|
||||||
previous_room = categories["Rooms"].rooms.pop(room_id, None)
|
previous_room = categories["Rooms"].rooms.pop(room_id, None)
|
||||||
previous_left = categories["Left"].rooms.pop(room_id, None)
|
previous_left = categories["Left"].rooms.pop(room_id, None)
|
||||||
|
|
||||||
|
members = ListModel()
|
||||||
|
sorted_members = SortFilterProxy(
|
||||||
|
source_model = members,
|
||||||
|
sort_by_role = "userId", # TODO
|
||||||
|
filter_by_role = "userId",
|
||||||
|
)
|
||||||
|
|
||||||
categories["Invites"].rooms.upsert(
|
categories["Invites"].rooms.upsert(
|
||||||
where_main_key_is = room_id,
|
where_main_key_is = room_id,
|
||||||
update_with = Room(
|
update_with = Room(
|
||||||
|
@ -174,9 +181,10 @@ class SignalManager(QObject):
|
||||||
topic = nio_room.topic,
|
topic = nio_room.topic,
|
||||||
inviter = inviter,
|
inviter = inviter,
|
||||||
lastEventDateTime = QDateTime.currentDateTime(), # FIXME
|
lastEventDateTime = QDateTime.currentDateTime(), # FIXME
|
||||||
members = ListModel(),
|
members = members,
|
||||||
|
sortedMembers = sorted_members,
|
||||||
),
|
),
|
||||||
no_update = ("typingMembers"),
|
no_update = ("typingMembers", "members"),
|
||||||
)
|
)
|
||||||
categories["Invites"].rooms[room_id].members.updateAll([
|
categories["Invites"].rooms[room_id].members.updateAll([
|
||||||
RoomMember(userId=user_id) for user_id in nio_room.users
|
RoomMember(userId=user_id) for user_id in nio_room.users
|
||||||
|
@ -198,15 +206,24 @@ class SignalManager(QObject):
|
||||||
previous_invite = categories["Invites"].rooms.pop(room_id, None)
|
previous_invite = categories["Invites"].rooms.pop(room_id, None)
|
||||||
previous_left = categories["Left"].rooms.pop(room_id, None)
|
previous_left = categories["Left"].rooms.pop(room_id, None)
|
||||||
|
|
||||||
|
members = ListModel()
|
||||||
|
sorted_members = SortFilterProxy(
|
||||||
|
source_model = members,
|
||||||
|
sort_by_role = "userId", # TODO
|
||||||
|
filter_by_role = "userId",
|
||||||
|
)
|
||||||
|
|
||||||
categories["Rooms"].rooms.upsert(
|
categories["Rooms"].rooms.upsert(
|
||||||
where_main_key_is = room_id,
|
where_main_key_is = room_id,
|
||||||
update_with = Room(
|
update_with = Room(
|
||||||
roomId = room_id,
|
roomId = room_id,
|
||||||
displayName = self._get_room_displayname(nio_room),
|
displayName = self._get_room_displayname(nio_room),
|
||||||
topic = nio_room.topic,
|
topic = nio_room.topic,
|
||||||
members = ListModel(),
|
members = members,
|
||||||
|
sortedMembers = sorted_members,
|
||||||
),
|
),
|
||||||
no_update = ("typingMembers", "members", "lastEventDateTime"),
|
no_update = ("typingMembers", "members", "sortedMembers",
|
||||||
|
"lastEventDateTime"),
|
||||||
)
|
)
|
||||||
categories["Rooms"].rooms[room_id].members.updateAll([
|
categories["Rooms"].rooms[room_id].members.updateAll([
|
||||||
RoomMember(userId=user_id) for user_id in nio_room.users
|
RoomMember(userId=user_id) for user_id in nio_room.users
|
||||||
|
@ -232,6 +249,13 @@ class SignalManager(QObject):
|
||||||
|
|
||||||
left_time = left_event.get("server_timestamp") if left_event else None
|
left_time = left_event.get("server_timestamp") if left_event else None
|
||||||
|
|
||||||
|
members = ListModel()
|
||||||
|
sorted_members = SortFilterProxy(
|
||||||
|
source_model = members,
|
||||||
|
sort_by_role = "userId", # TODO
|
||||||
|
filter_by_role = "userId",
|
||||||
|
)
|
||||||
|
|
||||||
categories["Left"].rooms.upsert(
|
categories["Left"].rooms.upsert(
|
||||||
where_main_key_is = room_id,
|
where_main_key_is = room_id,
|
||||||
update_with = Room(
|
update_with = Room(
|
||||||
|
@ -243,9 +267,10 @@ class SignalManager(QObject):
|
||||||
QDateTime.fromMSecsSinceEpoch(left_time)
|
QDateTime.fromMSecsSinceEpoch(left_time)
|
||||||
if left_time else QDateTime.currentDateTime()
|
if left_time else QDateTime.currentDateTime()
|
||||||
),
|
),
|
||||||
members = ListModel(),
|
members = members,
|
||||||
|
sortedMembers = sorted_members,
|
||||||
),
|
),
|
||||||
no_update = ("members", "lastEventDateTime"),
|
no_update = ("members", "sortedMembers", "lastEventDateTime"),
|
||||||
)
|
)
|
||||||
|
|
||||||
signal = self.roomCategoryChanged
|
signal = self.roomCategoryChanged
|
||||||
|
|
|
@ -19,7 +19,7 @@ HColumnLayout {
|
||||||
NumberAnimation { duration: HStyle.animationDuration }
|
NumberAnimation { duration: HStyle.animationDuration }
|
||||||
}
|
}
|
||||||
|
|
||||||
model: chatPage.roomInfo.members
|
model: chatPage.roomInfo.sortedMembers
|
||||||
delegate: MemberDelegate {}
|
delegate: MemberDelegate {}
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
Loading…
Reference in New Issue
Block a user