diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 63e16de3..36de56fd 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -1138,22 +1138,22 @@ class MatrixClient(nio.AsyncClient): response = await super().join(string) return response.room_id - async def toggle_bookmark(self, room_id: str) -> None: - room = self.models[self.user_id, "rooms"][room_id] - room.bookmarked = not room.bookmarked + async def toggle_room_pin(self, room_id: str) -> None: + room = self.models[self.user_id, "rooms"][room_id] + room.pinned = not room.pinned - settings = self.backend.settings - bookmarks = settings.RoomList.Bookmarks - user_bookmarks = bookmarks.setdefault(self.user_id, []) + settings = self.backend.settings + pinned = settings.RoomList.Pinned + user_pinned = pinned.setdefault(self.user_id, []) - if room.bookmarked and room_id not in user_bookmarks: - user_bookmarks.append(room_id) + if room.pinned and room_id not in user_pinned: + user_pinned.append(room_id) - while not room.bookmarked and room_id in user_bookmarks: - user_bookmarks.remove(room_id) + while not room.pinned and room_id in user_pinned: + user_pinned.remove(room_id) # Changes inside dicts/lists aren't monitored, need to reassign - settings.RoomList.Bookmarks[self.user_id] = user_bookmarks + settings.RoomList.Pinned[self.user_id] = user_pinned self.backend.settings.save() async def room_forget(self, room_id: str) -> None: @@ -2003,7 +2003,7 @@ class MatrixClient(nio.AsyncClient): ) unverified_devices = registered.unverified_devices - bookmarks = self.backend.settings.RoomList.Bookmarks + pinned = self.backend.settings.RoomList.Pinned room_item = Room( id = room.room_id, for_account = self.user_id, @@ -2049,7 +2049,7 @@ class MatrixClient(nio.AsyncClient): local_unreads = local_unreads, lexical_sorting = self.backend.settings.RoomList.lexical_sort, - bookmarked = room.room_id in bookmarks.get(self.user_id, []), + pinned = room.room_id in pinned.get(self.user_id, []), ) self.models[self.user_id, "rooms"][room.room_id] = room_item diff --git a/src/backend/models/items.py b/src/backend/models/items.py index ae965053..450914e2 100644 --- a/src/backend/models/items.py +++ b/src/backend/models/items.py @@ -171,7 +171,7 @@ class Room(ModelItem): local_unreads: bool = False lexical_sorting: bool = False - bookmarked: bool = False + pinned: bool = False def __lt__(self, other: "Room") -> bool: """Sort by membership, highlights/unread events, last event date, name. @@ -186,14 +186,14 @@ class Room(ModelItem): if self.lexical_sorting: return ( self.for_account, - other.bookmarked, + other.pinned, self.left, bool(other.inviter_id), (self.display_name or self.id).lower(), self.id, ) < ( other.for_account, - self.bookmarked, + self.pinned, other.left, bool(self.inviter_id), (other.display_name or other.id).lower(), @@ -203,7 +203,7 @@ class Room(ModelItem): # Left rooms may still have an inviter_id, so check left first. return ( self.for_account, - other.bookmarked, + other.pinned, self.left, bool(other.inviter_id), bool(other.highlights), @@ -215,7 +215,7 @@ class Room(ModelItem): ) < ( other.for_account, - self.bookmarked, + self.pinned, other.left, bool(self.inviter_id), bool(self.highlights), @@ -238,7 +238,7 @@ class AccountOrRoom(Account, Room): self.account_order, self.id if self.type is Account else self.for_account, other.type is Account, - other.bookmarked, + other.pinned, self.left, bool(other.inviter_id), (self.display_name or self.id).lower(), @@ -247,7 +247,7 @@ class AccountOrRoom(Account, Room): other.account_order, other.id if other.type is Account else other.for_account, self.type is Account, - self.bookmarked, + self.pinned, other.left, bool(self.inviter_id), (other.display_name or other.id).lower(), @@ -258,7 +258,7 @@ class AccountOrRoom(Account, Room): self.account_order, self.id if self.type is Account else self.for_account, other.type is Account, - other.bookmarked, + other.pinned, self.left, bool(other.inviter_id), bool(other.highlights), @@ -272,7 +272,7 @@ class AccountOrRoom(Account, Room): other.account_order, other.id if other.type is Account else other.for_account, self.type is Account, - self.bookmarked, + self.pinned, other.left, bool(self.inviter_id), bool(self.highlights), diff --git a/src/config/settings.py b/src/config/settings.py index bdba233b..14fa8adb 100644 --- a/src/config/settings.py +++ b/src/config/settings.py @@ -93,7 +93,7 @@ class RoomList: # in addition to focusing the current page or chat composer. escape_clears_filter: bool = True - class Bookmarks: + class Pinned: # Each property in this section is an account user ID, and the # value is a list of room ID to always keep on top. # A room's ID can be copied by right clicking on it in the room list. diff --git a/src/gui/MainPane/RoomDelegate.qml b/src/gui/MainPane/RoomDelegate.qml index 279af4f1..7dd8ed69 100644 --- a/src/gui/MainPane/RoomDelegate.qml +++ b/src/gui/MainPane/RoomDelegate.qml @@ -63,7 +63,8 @@ HTile { TitleLabel { text: - (model.bookmarked ? "\u2665 " : "") + + // U+1f4cc pushpin + force black-and-white variant + (model.pinned ? "📌\ufe0e " : "") + (model.display_name || qsTr("Empty room")) color: model.unreads || model.local_unreads ? @@ -135,6 +136,14 @@ HTile { } contextMenu: HMenu { + HMenuItem { + icon.name: model.pinned ? "room-unpin": "room-pin" + text: model.pinned ? qsTr("Unpin"): qsTr("Pin to top") + onTriggered: py.callClientCoro( + model.for_account, "toggle_room_pin", [model.id] + ) + } + HMenuItemPopupSpawner { visible: joined enabled: model.can_invite && accountModel.presence !== "offline" @@ -150,14 +159,6 @@ HTile { }) } - HMenuItem { - icon.name: model.bookmarked ? "bookmark-remove": "bookmark-add" - text: model.bookmarked ? qsTr("Remove bookmark"): qsTr("Bookmark") - onTriggered: py.callClientCoro( - model.for_account, "toggle_bookmark", [model.id] - ) - } - HMenuItem { icon.name: "copy-room-id" text: qsTr("Copy room ID") diff --git a/src/icons/thin/room-pin.svg b/src/icons/thin/room-pin.svg new file mode 100644 index 00000000..94ec57b5 --- /dev/null +++ b/src/icons/thin/room-pin.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/icons/thin/room-unpin.svg b/src/icons/thin/room-unpin.svg new file mode 100644 index 00000000..94ec57b5 --- /dev/null +++ b/src/icons/thin/room-unpin.svg @@ -0,0 +1,3 @@ + + +