Merge pull request #1936 from turt2live/travis/pinned-room-list

Add options to pin unread/mentioned rooms to the top of the room list
This commit is contained in:
Travis Ralston 2018-11-01 08:04:12 -06:00 committed by GitHub
commit 57b99893e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 0 deletions

View file

@ -82,6 +82,8 @@ const SIMPLE_SETTINGS = [
{ id: "TagPanel.disableTagPanel" }, { id: "TagPanel.disableTagPanel" },
{ id: "enableWidgetScreenshots" }, { id: "enableWidgetScreenshots" },
{ id: "RoomSubList.showEmpty" }, { id: "RoomSubList.showEmpty" },
{ id: "pinMentionedRooms" },
{ id: "pinUnreadRooms" },
{ id: "showDeveloperTools" }, { id: "showDeveloperTools" },
]; ];

View file

@ -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 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", "Enable URL previews by default for participants in this room": "Enable URL previews by default for participants in this room",
"Room Colour": "Room Colour", "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", "Enable widget screenshots on supported widgets": "Enable widget screenshots on supported widgets",
"Show empty room list headings": "Show empty room list headings", "Show empty room list headings": "Show empty room list headings",
"Collecting app version information": "Collecting app version information", "Collecting app version information": "Collecting app version information",

View file

@ -276,6 +276,16 @@ export const SETTINGS = {
default: true, default: true,
controller: new AudioNotificationsEnabledController(), 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": { "enableWidgetScreenshots": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS, supportedLevels: LEVELS_ACCOUNT_SETTINGS,
displayName: _td('Enable widget screenshots on supported widgets'), displayName: _td('Enable widget screenshots on supported widgets'),

View file

@ -17,6 +17,7 @@ import {Store} from 'flux/utils';
import dis from '../dispatcher'; import dis from '../dispatcher';
import DMRoomMap from '../utils/DMRoomMap'; import DMRoomMap from '../utils/DMRoomMap';
import Unread from '../Unread'; import Unread from '../Unread';
import SettingsStore from "../settings/SettingsStore";
/** /**
* A class for storing application state for categorising rooms in * A class for storing application state for categorising rooms in
@ -262,6 +263,30 @@ class RoomListStore extends Store {
} }
_recentsComparator(roomA, roomB) { _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 // XXX: We could use a cache here and update it when we see new
// events that trigger a reorder // events that trigger a reorder
return this._tsOfNewestEvent(roomB) - this._tsOfNewestEvent(roomA); return this._tsOfNewestEvent(roomB) - this._tsOfNewestEvent(roomA);