diff --git a/TODO.md b/TODO.md index aafa9daf..363a6bdc 100644 --- a/TODO.md +++ b/TODO.md @@ -15,6 +15,8 @@ - ![A picture](https://picsum.photos/256/256) not clickable? - UI + - One line label componant + - Collapsible roomList sections, + button - Reorganize SidePane - Proper theme, with components taking their colors from theme settings - Settings page diff --git a/harmonyqml/backend/client.py b/harmonyqml/backend/client.py index 4fd9ba04..f6d90060 100644 --- a/harmonyqml/backend/client.py +++ b/harmonyqml/backend/client.py @@ -116,7 +116,7 @@ class Client(QObject): def _on_sync(self, response: nr.SyncResponse) -> None: self.nio.receive_response(response) - for room_id in response.rooms.invite: + for room_id, room_info in response.rooms.invite.items(): self.roomInvited.emit(room_id) for room_id, room_info in response.rooms.join.items(): diff --git a/harmonyqml/backend/model/items.py b/harmonyqml/backend/model/items.py index fefd6877..aaa3602b 100644 --- a/harmonyqml/backend/model/items.py +++ b/harmonyqml/backend/model/items.py @@ -62,13 +62,15 @@ class User(ListItem): class Room(ListItem): - roles = ("roomId", "displayName", "topic", "typingUsers") + roles = ("roomId", "category", "displayName", "topic", "typingUsers") + categoryChanged = pyqtSignal(str) displayNameChanged = pyqtSignal("QVariant") topicChanged = pyqtSignal(str) typingUsersChanged = pyqtSignal("QVariantList") roomId = prop(str, "roomId") + category = prop(str, "category") displayName = prop(str, "displayName", displayNameChanged) topic = prop(str, "topic", topicChanged, "") typingUsers = prop(list, "typingUsers", typingUsersChanged, []) diff --git a/harmonyqml/backend/signal_manager.py b/harmonyqml/backend/signal_manager.py index 339035f6..cf0172cb 100644 --- a/harmonyqml/backend/signal_manager.py +++ b/harmonyqml/backend/signal_manager.py @@ -7,6 +7,7 @@ from typing import Any, Deque, Dict, List, Optional from PyQt5.QtCore import QDateTime, QObject, pyqtBoundSignal import nio +from nio.rooms import MatrixRoom from .backend import Backend from .client import Client @@ -54,24 +55,29 @@ class SignalManager(QObject): def onRoomInvited(self, client: Client, room_id: str) -> None: - pass # TODO + self._add_room(client, client.nio.invited_rooms[room_id], "Invites") def onRoomJoined(self, client: Client, room_id: str) -> None: + self._add_room(client, client.nio.rooms[room_id], "Rooms") + + + def _add_room(self, client: Client, room: MatrixRoom, category: str + ) -> None: model = self.backend.models.rooms[client.userId] - room = client.nio.rooms[room_id] def group_name() -> Optional[str]: name = room.group_name() return None if name == "Empty room?" else name item = Room( - roomId = room_id, + roomId = room.room_id, + category = category, displayName = room.name or room.canonical_alias or group_name(), topic = room.topic, ) - model.updateOrAppendWhere("roomId", room_id, item) + model.updateOrAppendWhere("roomId", room.room_id, item) def onRoomLeft(self, client: Client, room_id: str) -> None: diff --git a/harmonyqml/components/sidePane/RoomCategoryDelegate.qml b/harmonyqml/components/sidePane/RoomCategoryDelegate.qml new file mode 100644 index 00000000..2f741119 --- /dev/null +++ b/harmonyqml/components/sidePane/RoomCategoryDelegate.qml @@ -0,0 +1,16 @@ +import QtQuick 2.7 +import "../base" as Base + +Base.HLabel { + width: roomList.width + height: text.height + + // topPadding is provided by the roomList spacing + bottomPadding: roomList.spacing + + text: section + elide: Text.ElideRight + maximumLineCount: 1 + + font.bold: true +} diff --git a/harmonyqml/components/sidePane/RoomList.qml b/harmonyqml/components/sidePane/RoomList.qml index abaf6611..559830bb 100644 --- a/harmonyqml/components/sidePane/RoomList.qml +++ b/harmonyqml/components/sidePane/RoomList.qml @@ -18,4 +18,7 @@ ListView { spacing: 8 model: Backend.models.rooms.get(forUserId) delegate: RoomDelegate {} + + section.property: "category" + section.delegate: RoomCategoryDelegate {} }