diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 40dccd7839..db12515285 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -82,6 +82,8 @@ const SIMPLE_SETTINGS = [ { id: "TagPanel.disableTagPanel" }, { id: "enableWidgetScreenshots" }, { id: "RoomSubList.showEmpty" }, + { id: "pinMentionedRooms" }, + { id: "pinUnreadRooms" }, { id: "showDeveloperTools" }, ]; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 8e1f75f25c..977ec072d6 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -249,6 +249,8 @@ "Enable URL previews for this room (only affects you)": "Enable URL previews for this room (only affects you)", "Enable URL previews by default for participants in this room": "Enable URL previews by default for participants in this room", "Room Colour": "Room Colour", + "Pin unread rooms to the top of the room list": "Pin unread rooms to the top of the room list", + "Pin rooms I'm mentioned in to the top of the room list": "Pin rooms I'm mentioned in to the top of the room list", "Enable widget screenshots on supported widgets": "Enable widget screenshots on supported widgets", "Show empty room list headings": "Show empty room list headings", "Collecting app version information": "Collecting app version information", diff --git a/src/settings/Settings.js b/src/settings/Settings.js index 547c71bac8..d65303b7c6 100644 --- a/src/settings/Settings.js +++ b/src/settings/Settings.js @@ -276,6 +276,16 @@ export const SETTINGS = { default: true, controller: new AudioNotificationsEnabledController(), }, + "pinMentionedRooms": { + supportedLevels: LEVELS_ACCOUNT_SETTINGS, + displayName: _td("Pin rooms I'm mentioned in to the top of the room list"), + default: false, + }, + "pinUnreadRooms": { + supportedLevels: LEVELS_ACCOUNT_SETTINGS, + displayName: _td("Pin unread rooms to the top of the room list"), + default: false, + }, "enableWidgetScreenshots": { supportedLevels: LEVELS_ACCOUNT_SETTINGS, displayName: _td('Enable widget screenshots on supported widgets'), diff --git a/src/stores/RoomListStore.js b/src/stores/RoomListStore.js index c670161dbc..8909dbb489 100644 --- a/src/stores/RoomListStore.js +++ b/src/stores/RoomListStore.js @@ -17,6 +17,7 @@ import {Store} from 'flux/utils'; import dis from '../dispatcher'; import DMRoomMap from '../utils/DMRoomMap'; import Unread from '../Unread'; +import SettingsStore from "../settings/SettingsStore"; /** * A class for storing application state for categorising rooms in @@ -262,6 +263,30 @@ class RoomListStore extends Store { } _recentsComparator(roomA, roomB) { + const pinUnread = SettingsStore.getValue("pinUnreadRooms"); + const pinMentioned = SettingsStore.getValue("pinMentionedRooms"); + + // We try and set the ordering to be Mentioned > Unread > Recent + // assuming the user has the right settings, of course + + if (pinMentioned) { + const mentionsA = roomA.getUnreadNotificationCount("highlight") > 0; + const mentionsB = roomB.getUnreadNotificationCount("highlight") > 0; + if (mentionsA && !mentionsB) return -1; + if (!mentionsA && mentionsB) return 1; + if (mentionsA && mentionsB) return 0; + // If neither have mentions, fall through to remaining checks + } + + if (pinUnread) { + const unreadA = Unread.doesRoomHaveUnreadMessages(roomA); + const unreadB = Unread.doesRoomHaveUnreadMessages(roomB); + if (unreadA && !unreadB) return -1; + if (!unreadA && unreadB) return 1; + if (unreadA && unreadB) return 0; + // If neither have unread messages, fall through to remaining checks + } + // XXX: We could use a cache here and update it when we see new // events that trigger a reorder return this._tsOfNewestEvent(roomB) - this._tsOfNewestEvent(roomA);