Make Room.members a properly updating ListModel

This commit is contained in:
miruka 2019-05-14 20:20:54 -04:00
parent 606771735a
commit 1a4ac0f432
4 changed files with 24 additions and 8 deletions

View File

@ -65,6 +65,7 @@
- Banner name color instead of bold
- Missing nio support
- MatrixRoom invited members list
- Invite events are missing their timestamps (needed for sorting)
- Left room events after client reboot
- `org.matrix.room.preview_urls` event

View File

@ -40,6 +40,13 @@ class Room(ListItem):
leftEvent: Optional[Dict[str, str]] = None
class RoomMember(ListItem):
_required_init_values = {"userId"}
_constant = {"userId"}
userId: str = ""
# ----------
class RoomEvent(ListItem):

View File

@ -253,7 +253,7 @@ class ListModel(QAbstractListModel):
@pyqtSlot(list, bool)
def updateAll(self, items: Sequence[NewItem], delete: bool = False
) -> None:
items = [self._convert_new_value(i) for i in items]
items_: List[ListItem] = [self._convert_new_value(i) for i in items]
if delete:
present_item: ListItem
@ -261,15 +261,15 @@ class ListModel(QAbstractListModel):
present_item_key = getattr(present_item, self.mainKey)
# If this present item is in the update items, based on mainKey
for update_item in items:
for update_item in items_:
if present_item_key == getattr(update_item, self.mainKey):
break
else:
del self[i]
for item in items:
for item in items_:
self.upsert(
where_main_key_is = getattr(item, self.mainKey),
where_main_key_is = getattr(item, item.mainKey),
update_with = item
)

View File

@ -13,7 +13,8 @@ from nio.rooms import MatrixRoom
from .backend import Backend
from .client import Client
from .model.items import (
Account, Device, ListModel, Room, RoomCategory, RoomEvent, User
Account, Device, ListModel, Room, RoomCategory, RoomEvent, RoomMember,
User
)
from .model.sort_filter_proxy import SortFilterProxy
from .pyqt_future import futurize
@ -173,10 +174,13 @@ class SignalManager(QObject):
topic = nio_room.topic,
inviter = inviter,
lastEventDateTime = QDateTime.currentDateTime(), # FIXME
members = list(nio_room.users.keys()),
members = ListModel(),
),
no_update = ("typingMembers"),
)
categories["Invites"].rooms[room_id].members.updateAll([
RoomMember(userId=user_id) for user_id in nio_room.users
], delete=True)
signal = self.roomCategoryChanged
if previous_room:
@ -200,10 +204,13 @@ class SignalManager(QObject):
roomId = room_id,
displayName = self._get_room_displayname(nio_room),
topic = nio_room.topic,
members = list(nio_room.users.keys()),
members = ListModel(),
),
no_update = ("typingMembers", "lastEventDateTime"),
no_update = ("typingMembers", "members", "lastEventDateTime"),
)
categories["Rooms"].rooms[room_id].members.updateAll([
RoomMember(userId=user_id) for user_id in nio_room.users
], delete=True)
signal = self.roomCategoryChanged
if previous_invite:
@ -236,6 +243,7 @@ class SignalManager(QObject):
QDateTime.fromMSecsSinceEpoch(left_time)
if left_time else QDateTime.currentDateTime()
),
members = ListModel(),
),
no_update = ("members", "lastEventDateTime"),
)