Change room bookmark terminology to pin/unpin

Pin/unpin is more representative of what the function actually does
for rooms in the left pane. Also change the corresponding icons and
renames the config file section: RoomList.Bookmarks → RoomList.Pinned
This commit is contained in:
miruka 2021-02-25 05:51:48 -04:00
parent 13558fd61c
commit 8a6f7c262f
6 changed files with 39 additions and 32 deletions

View File

@ -1138,22 +1138,22 @@ class MatrixClient(nio.AsyncClient):
response = await super().join(string) response = await super().join(string)
return response.room_id return response.room_id
async def toggle_bookmark(self, room_id: str) -> None: async def toggle_room_pin(self, room_id: str) -> None:
room = self.models[self.user_id, "rooms"][room_id] room = self.models[self.user_id, "rooms"][room_id]
room.bookmarked = not room.bookmarked room.pinned = not room.pinned
settings = self.backend.settings settings = self.backend.settings
bookmarks = settings.RoomList.Bookmarks pinned = settings.RoomList.Pinned
user_bookmarks = bookmarks.setdefault(self.user_id, []) user_pinned = pinned.setdefault(self.user_id, [])
if room.bookmarked and room_id not in user_bookmarks: if room.pinned and room_id not in user_pinned:
user_bookmarks.append(room_id) user_pinned.append(room_id)
while not room.bookmarked and room_id in user_bookmarks: while not room.pinned and room_id in user_pinned:
user_bookmarks.remove(room_id) user_pinned.remove(room_id)
# Changes inside dicts/lists aren't monitored, need to reassign # 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() self.backend.settings.save()
async def room_forget(self, room_id: str) -> None: async def room_forget(self, room_id: str) -> None:
@ -2003,7 +2003,7 @@ class MatrixClient(nio.AsyncClient):
) )
unverified_devices = registered.unverified_devices unverified_devices = registered.unverified_devices
bookmarks = self.backend.settings.RoomList.Bookmarks pinned = self.backend.settings.RoomList.Pinned
room_item = Room( room_item = Room(
id = room.room_id, id = room.room_id,
for_account = self.user_id, for_account = self.user_id,
@ -2049,7 +2049,7 @@ class MatrixClient(nio.AsyncClient):
local_unreads = local_unreads, local_unreads = local_unreads,
lexical_sorting = self.backend.settings.RoomList.lexical_sort, 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 self.models[self.user_id, "rooms"][room.room_id] = room_item

View File

@ -171,7 +171,7 @@ class Room(ModelItem):
local_unreads: bool = False local_unreads: bool = False
lexical_sorting: bool = False lexical_sorting: bool = False
bookmarked: bool = False pinned: bool = False
def __lt__(self, other: "Room") -> bool: def __lt__(self, other: "Room") -> bool:
"""Sort by membership, highlights/unread events, last event date, name. """Sort by membership, highlights/unread events, last event date, name.
@ -186,14 +186,14 @@ class Room(ModelItem):
if self.lexical_sorting: if self.lexical_sorting:
return ( return (
self.for_account, self.for_account,
other.bookmarked, other.pinned,
self.left, self.left,
bool(other.inviter_id), bool(other.inviter_id),
(self.display_name or self.id).lower(), (self.display_name or self.id).lower(),
self.id, self.id,
) < ( ) < (
other.for_account, other.for_account,
self.bookmarked, self.pinned,
other.left, other.left,
bool(self.inviter_id), bool(self.inviter_id),
(other.display_name or other.id).lower(), (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. # Left rooms may still have an inviter_id, so check left first.
return ( return (
self.for_account, self.for_account,
other.bookmarked, other.pinned,
self.left, self.left,
bool(other.inviter_id), bool(other.inviter_id),
bool(other.highlights), bool(other.highlights),
@ -215,7 +215,7 @@ class Room(ModelItem):
) < ( ) < (
other.for_account, other.for_account,
self.bookmarked, self.pinned,
other.left, other.left,
bool(self.inviter_id), bool(self.inviter_id),
bool(self.highlights), bool(self.highlights),
@ -238,7 +238,7 @@ class AccountOrRoom(Account, Room):
self.account_order, self.account_order,
self.id if self.type is Account else self.for_account, self.id if self.type is Account else self.for_account,
other.type is Account, other.type is Account,
other.bookmarked, other.pinned,
self.left, self.left,
bool(other.inviter_id), bool(other.inviter_id),
(self.display_name or self.id).lower(), (self.display_name or self.id).lower(),
@ -247,7 +247,7 @@ class AccountOrRoom(Account, Room):
other.account_order, other.account_order,
other.id if other.type is Account else other.for_account, other.id if other.type is Account else other.for_account,
self.type is Account, self.type is Account,
self.bookmarked, self.pinned,
other.left, other.left,
bool(self.inviter_id), bool(self.inviter_id),
(other.display_name or other.id).lower(), (other.display_name or other.id).lower(),
@ -258,7 +258,7 @@ class AccountOrRoom(Account, Room):
self.account_order, self.account_order,
self.id if self.type is Account else self.for_account, self.id if self.type is Account else self.for_account,
other.type is Account, other.type is Account,
other.bookmarked, other.pinned,
self.left, self.left,
bool(other.inviter_id), bool(other.inviter_id),
bool(other.highlights), bool(other.highlights),
@ -272,7 +272,7 @@ class AccountOrRoom(Account, Room):
other.account_order, other.account_order,
other.id if other.type is Account else other.for_account, other.id if other.type is Account else other.for_account,
self.type is Account, self.type is Account,
self.bookmarked, self.pinned,
other.left, other.left,
bool(self.inviter_id), bool(self.inviter_id),
bool(self.highlights), bool(self.highlights),

View File

@ -93,7 +93,7 @@ class RoomList:
# in addition to focusing the current page or chat composer. # in addition to focusing the current page or chat composer.
escape_clears_filter: bool = True escape_clears_filter: bool = True
class Bookmarks: class Pinned:
# Each property in this section is an account user ID, and the # Each property in this section is an account user ID, and the
# value is a list of room ID to always keep on top. # 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. # A room's ID can be copied by right clicking on it in the room list.

View File

@ -63,7 +63,8 @@ HTile {
TitleLabel { TitleLabel {
text: text:
(model.bookmarked ? "\u2665 " : "") + // U+1f4cc pushpin + force black-and-white variant
(model.pinned ? "📌\ufe0e " : "") +
(model.display_name || qsTr("Empty room")) (model.display_name || qsTr("Empty room"))
color: color:
model.unreads || model.local_unreads ? model.unreads || model.local_unreads ?
@ -135,6 +136,14 @@ HTile {
} }
contextMenu: HMenu { 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 { HMenuItemPopupSpawner {
visible: joined visible: joined
enabled: model.can_invite && accountModel.presence !== "offline" 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 { HMenuItem {
icon.name: "copy-room-id" icon.name: "copy-room-id"
text: qsTr("Copy room ID") text: qsTr("Copy room ID")

View File

@ -0,0 +1,3 @@
<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="m11 17h2v5l-2 2zm7-2h-12c0-3.128.091-4.744 1.874-7.276.551-.783.915-1.3.915-2.373 0-2.372-1.789-1.695-1.789-5.351h10c0 3.616-1.789 3.005-1.789 5.35 0 1.073.364 1.59.915 2.374 1.785 2.535 1.874 4.154 1.874 7.276zm-9.968-2h7.936c-.298-4.376-2.756-4.142-2.756-7.649-.001-1.605.521-2.351 1.271-3.351h-4.966c.75 1 1.272 1.745 1.272 3.35 0 3.487-2.46 3.29-2.757 7.65z"/>
</svg>

After

Width:  |  Height:  |  Size: 469 B

View File

@ -0,0 +1,3 @@
<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="m11 17h2v5l-2 2zm7-2h-12c0-3.128.091-4.744 1.874-7.276.551-.783.915-1.3.915-2.373 0-2.372-1.789-1.695-1.789-5.351h10c0 3.616-1.789 3.005-1.789 5.35 0 1.073.364 1.59.915 2.374 1.785 2.535 1.874 4.154 1.874 7.276zm-9.968-2h7.936c-.298-4.376-2.756-4.142-2.756-7.649-.001-1.605.521-2.351 1.271-3.351h-4.966c.75 1 1.272 1.745 1.272 3.35 0 3.487-2.46 3.29-2.757 7.65z"/>
</svg>

After

Width:  |  Height:  |  Size: 469 B