Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Add options to pin unread/mentioned rooms to the top of the room list #1936

Merged
merged 4 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/structures/UserSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const SIMPLE_SETTINGS = [
{ id: "TagPanel.disableTagPanel" },
{ id: "enableWidgetScreenshots" },
{ id: "RoomSubList.showEmpty" },
{ id: "pinMentionedRooms" },
{ id: "pinUnreadRooms" },
{ id: "showDeveloperTools" },
];

Expand Down
2 changes: 2 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions src/settings/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
25 changes: 25 additions & 0 deletions src/stores/RoomListStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -263,6 +264,30 @@ class RoomListStore extends Store {
}

_recentsComparator(roomA, roomB) {
const pinUnread = SettingsStore.getValue("pinUnreadRooms");
bwindels marked this conversation as resolved.
Show resolved Hide resolved
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;
bwindels marked this conversation as resolved.
Show resolved Hide resolved
// 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);
Expand Down