Add an option to sort the room list by recents first
Fixes https://github.com/vector-im/riot-web/issues/8892
This commit is contained in:
parent
7ea4008daa
commit
b0cc69bca9
4 changed files with 48 additions and 2 deletions
|
@ -44,6 +44,10 @@ export default class PreferencesSettingsTab extends React.Component {
|
||||||
'showDisplaynameChanges',
|
'showDisplaynameChanges',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
static ROOM_LIST_SETTINGS = [
|
||||||
|
'RoomList.orderByImportance',
|
||||||
|
];
|
||||||
|
|
||||||
static ADVANCED_SETTINGS = [
|
static ADVANCED_SETTINGS = [
|
||||||
'alwaysShowEncryptionIcons',
|
'alwaysShowEncryptionIcons',
|
||||||
'Pill.shouldShowPillAvatar',
|
'Pill.shouldShowPillAvatar',
|
||||||
|
@ -104,6 +108,9 @@ export default class PreferencesSettingsTab extends React.Component {
|
||||||
<span className="mx_SettingsTab_subheading">{_t("Timeline")}</span>
|
<span className="mx_SettingsTab_subheading">{_t("Timeline")}</span>
|
||||||
{this._renderGroup(PreferencesSettingsTab.TIMELINE_SETTINGS)}
|
{this._renderGroup(PreferencesSettingsTab.TIMELINE_SETTINGS)}
|
||||||
|
|
||||||
|
<span className="mx_SettingsTab_subheading">{_t("Room list")}</span>
|
||||||
|
{this._renderGroup(PreferencesSettingsTab.ROOM_LIST_SETTINGS)}
|
||||||
|
|
||||||
<span className="mx_SettingsTab_subheading">{_t("Advanced")}</span>
|
<span className="mx_SettingsTab_subheading">{_t("Advanced")}</span>
|
||||||
{this._renderGroup(PreferencesSettingsTab.ADVANCED_SETTINGS)}
|
{this._renderGroup(PreferencesSettingsTab.ADVANCED_SETTINGS)}
|
||||||
{autoLaunchOption}
|
{autoLaunchOption}
|
||||||
|
|
|
@ -306,6 +306,7 @@
|
||||||
"Enable widget screenshots on supported widgets": "Enable widget screenshots on supported widgets",
|
"Enable widget screenshots on supported widgets": "Enable widget screenshots on supported widgets",
|
||||||
"Prompt before sending invites to potentially invalid matrix IDs": "Prompt before sending invites to potentially invalid matrix IDs",
|
"Prompt before sending invites to potentially invalid matrix IDs": "Prompt before sending invites to potentially invalid matrix IDs",
|
||||||
"Show developer tools": "Show developer tools",
|
"Show developer tools": "Show developer tools",
|
||||||
|
"Order rooms in the room list by most important first instead of most recent": "Order rooms in the room list by most important first instead of most recent",
|
||||||
"Collecting app version information": "Collecting app version information",
|
"Collecting app version information": "Collecting app version information",
|
||||||
"Collecting logs": "Collecting logs",
|
"Collecting logs": "Collecting logs",
|
||||||
"Uploading report": "Uploading report",
|
"Uploading report": "Uploading report",
|
||||||
|
@ -554,6 +555,7 @@
|
||||||
"Preferences": "Preferences",
|
"Preferences": "Preferences",
|
||||||
"Composer": "Composer",
|
"Composer": "Composer",
|
||||||
"Timeline": "Timeline",
|
"Timeline": "Timeline",
|
||||||
|
"Room list": "Room list",
|
||||||
"Autocomplete delay (ms)": "Autocomplete delay (ms)",
|
"Autocomplete delay (ms)": "Autocomplete delay (ms)",
|
||||||
"To change the room's avatar, you must be a": "To change the room's avatar, you must be a",
|
"To change the room's avatar, you must be a": "To change the room's avatar, you must be a",
|
||||||
"To change the room's name, you must be a": "To change the room's name, you must be a",
|
"To change the room's name, you must be a": "To change the room's name, you must be a",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2017 Travis Ralston
|
Copyright 2017 Travis Ralston
|
||||||
Copyright 2018 New Vector Ltd
|
Copyright 2018, 2019 New Vector Ltd.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -340,4 +340,9 @@ export const SETTINGS = {
|
||||||
displayName: _td('Show developer tools'),
|
displayName: _td('Show developer tools'),
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
"RoomList.orderByImportance": {
|
||||||
|
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
|
||||||
|
displayName: _td('Order rooms in the room list by most important first instead of most recent'),
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -59,6 +59,22 @@ class RoomListStore extends Store {
|
||||||
this._recentsComparator = this._recentsComparator.bind(this);
|
this._recentsComparator = this._recentsComparator.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alerts the RoomListStore to a potential change in how room list sorting should
|
||||||
|
* behave.
|
||||||
|
* @param {boolean} forceRegeneration True to force a change in the algorithm
|
||||||
|
*/
|
||||||
|
updateSortingAlgorithm(forceRegeneration=false) {
|
||||||
|
const byImportance = SettingsStore.getValue("RoomList.orderByImportance");
|
||||||
|
if (byImportance !== this._state.orderRoomsByImportance || forceRegeneration) {
|
||||||
|
console.log("Updating room sorting algorithm: sortByImportance=" + byImportance);
|
||||||
|
this._setState({orderRoomsByImportance: byImportance});
|
||||||
|
|
||||||
|
// Trigger a resort of the entire list to reflect the change in algorithm
|
||||||
|
this._generateInitialRoomLists();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_init() {
|
_init() {
|
||||||
// Initialise state
|
// Initialise state
|
||||||
const defaultLists = {
|
const defaultLists = {
|
||||||
|
@ -77,7 +93,10 @@ class RoomListStore extends Store {
|
||||||
presentationLists: defaultLists, // like `lists`, but with arrays of rooms instead
|
presentationLists: defaultLists, // like `lists`, but with arrays of rooms instead
|
||||||
ready: false,
|
ready: false,
|
||||||
stickyRoomId: null,
|
stickyRoomId: null,
|
||||||
|
orderRoomsByImportance: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SettingsStore.monitorSetting('RoomList.orderByImportance', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
_setState(newState) {
|
_setState(newState) {
|
||||||
|
@ -99,6 +118,11 @@ class RoomListStore extends Store {
|
||||||
__onDispatch(payload) {
|
__onDispatch(payload) {
|
||||||
const logicallyReady = this._matrixClient && this._state.ready;
|
const logicallyReady = this._matrixClient && this._state.ready;
|
||||||
switch (payload.action) {
|
switch (payload.action) {
|
||||||
|
case 'setting_updated': {
|
||||||
|
if (payload.settingName !== 'RoomList.orderByImportance') break;
|
||||||
|
this.updateSortingAlgorithm();
|
||||||
|
}
|
||||||
|
break;
|
||||||
// Initialise state after initial sync
|
// Initialise state after initial sync
|
||||||
case 'MatrixActions.sync': {
|
case 'MatrixActions.sync': {
|
||||||
if (!(payload.prevState !== 'PREPARED' && payload.state === 'PREPARED')) {
|
if (!(payload.prevState !== 'PREPARED' && payload.state === 'PREPARED')) {
|
||||||
|
@ -106,7 +130,7 @@ class RoomListStore extends Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._matrixClient = payload.matrixClient;
|
this._matrixClient = payload.matrixClient;
|
||||||
this._generateInitialRoomLists();
|
this.updateSortingAlgorithm(/*force=*/true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'MatrixActions.Room.receipt': {
|
case 'MatrixActions.Room.receipt': {
|
||||||
|
@ -517,6 +541,14 @@ class RoomListStore extends Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
_calculateCategory(room) {
|
_calculateCategory(room) {
|
||||||
|
if (!this._state.orderRoomsByImportance) {
|
||||||
|
// Effectively disable the categorization of rooms if we're supposed to
|
||||||
|
// be sorting by more recent messages first. This triggers the timestamp
|
||||||
|
// comparison bit of _setRoomCategory and _recentsComparator instead of
|
||||||
|
// the category ordering.
|
||||||
|
return CATEGORY_IDLE;
|
||||||
|
}
|
||||||
|
|
||||||
const mentions = room.getUnreadNotificationCount("highlight") > 0;
|
const mentions = room.getUnreadNotificationCount("highlight") > 0;
|
||||||
if (mentions) return CATEGORY_RED;
|
if (mentions) return CATEGORY_RED;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue