Add setting to sort rooms lexically

This commit is contained in:
miruka 2020-09-01 14:42:08 -04:00
parent 8d61826887
commit a1b9f34958
4 changed files with 35 additions and 1 deletions

View File

@ -2,7 +2,6 @@
- handle invalid access token - handle invalid access token
- If an account is gone from the user's config, discard UI state last page - If an account is gone from the user's config, discard UI state last page
- room A-Z sorting
- filter > enter > room list is always scrolled to top - filter > enter > room list is always scrolled to top
- session list: prevent tab-focusing the delegates - session list: prevent tab-focusing the delegates
- refresh server list button - refresh server list button

View File

@ -1866,6 +1866,8 @@ class MatrixClient(nio.AsyncClient):
highlights = room.unread_highlights, highlights = room.unread_highlights,
local_unreads = local_unreads, local_unreads = local_unreads,
local_highlights = local_highlights, local_highlights = local_highlights,
lexical_sorting = self.backend.ui_settings["lexicalRoomSorting"],
) )
self.models[self.user_id, "rooms"][room.room_id] = room_item self.models[self.user_id, "rooms"][room.room_id] = room_item

View File

@ -130,6 +130,8 @@ class Room(ModelItem):
local_unreads: bool = False local_unreads: bool = False
local_highlights: bool = False local_highlights: bool = False
lexical_sorting: 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.
@ -140,6 +142,19 @@ class Room(ModelItem):
then by display names or ID. then by display names or ID.
""" """
if self.lexical_sorting:
return (
self.for_account,
self.left,
other.inviter_id,
(self.display_name or self.id).lower(),
) < (
other.for_account,
other.left,
self.inviter_id,
(other.display_name or other.id).lower(),
)
# 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,
@ -171,6 +186,23 @@ class AccountOrRoom(Account, Room):
account_order: int = -1 account_order: int = -1
def __lt__(self, other: "AccountOrRoom") -> bool: # type: ignore def __lt__(self, other: "AccountOrRoom") -> bool: # type: ignore
if self.lexical_sorting:
return (
self.account_order,
self.id if self.type is Account else self.for_account,
other.type is Account,
self.left,
other.inviter_id,
(self.display_name or self.id).lower(),
) < (
other.account_order,
other.id if other.type is Account else other.for_account,
self.type is Account,
other.left,
self.inviter_id,
(other.display_name or other.id).lower(),
)
return ( return (
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,

View File

@ -280,6 +280,7 @@ class UISettings(JSONDataFile):
"hideUnknownEvents": True, "hideUnknownEvents": True,
"kineticScrollingMaxSpeed": 2500, "kineticScrollingMaxSpeed": 2500,
"kineticScrollingDeceleration": 1500, "kineticScrollingDeceleration": 1500,
"lexicalRoomSorting": False,
"markRoomReadMsecDelay": 200, "markRoomReadMsecDelay": 200,
"maxMessageCharactersPerLine": 65, "maxMessageCharactersPerLine": 65,
"ownMessagesOnLeftAboveWidth": 895, "ownMessagesOnLeftAboveWidth": 895,