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

Commit

Permalink
Add an option to sort the room list by recents first
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Feb 22, 2019
1 parent 5695de0 commit 8a6dc1d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/components/views/settings/tabs/PreferencesSettingsTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export default class PreferencesSettingsTab extends React.Component {
'showDisplaynameChanges',
];

static ROOM_LIST_SETTINGS = [
'RoomList.orderByImportance',
];

static ADVANCED_SETTINGS = [
'alwaysShowEncryptionIcons',
'Pill.shouldShowPillAvatar',
Expand Down Expand Up @@ -104,6 +108,9 @@ export default class PreferencesSettingsTab extends React.Component {
<span className="mx_SettingsTab_subheading">{_t("Timeline")}</span>
{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>
{this._renderGroup(PreferencesSettingsTab.ADVANCED_SETTINGS)}
{autoLaunchOption}
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 @@ -306,6 +306,7 @@
"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",
"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 logs": "Collecting logs",
"Uploading report": "Uploading report",
Expand Down Expand Up @@ -554,6 +555,7 @@
"Preferences": "Preferences",
"Composer": "Composer",
"Timeline": "Timeline",
"Room list": "Room list",
"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 name, you must be a": "To change the room's name, you must be a",
Expand Down
7 changes: 6 additions & 1 deletion src/settings/Settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
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");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -340,4 +340,9 @@ export const SETTINGS = {
displayName: _td('Show developer tools'),
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,
},
};
40 changes: 39 additions & 1 deletion src/stores/RoomListStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ const LIST_ORDERS = {
* the RoomList.
*/
class RoomListStore extends Store {

// True to order rooms by importance (CATEGORY_ORDER) and false to order rooms by
// how recently active they were. This is set internally when the room list is
// reinitialized and whenever the setting changes.
orderRoomsByImportance = true;

constructor() {
super(dis);

Expand All @@ -59,6 +65,22 @@ class RoomListStore extends Store {
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() {
// Initialise state
const defaultLists = {
Expand All @@ -77,7 +99,10 @@ class RoomListStore extends Store {
presentationLists: defaultLists, // like `lists`, but with arrays of rooms instead
ready: false,
stickyRoomId: null,
orderRoomsByImportance: true,
};

SettingsStore.monitorSetting('RoomList.orderByImportance', null);
}

_setState(newState) {
Expand All @@ -99,14 +124,19 @@ class RoomListStore extends Store {
__onDispatch(payload) {
const logicallyReady = this._matrixClient && this._state.ready;
switch (payload.action) {
case 'setting_updated': {
if (payload.settingName !== 'RoomList.orderByImportance') break;
this.updateSortingAlgorithm();
}
break;
// Initialise state after initial sync
case 'MatrixActions.sync': {
if (!(payload.prevState !== 'PREPARED' && payload.state === 'PREPARED')) {
break;
}

this._matrixClient = payload.matrixClient;
this._generateInitialRoomLists();
this.updateSortingAlgorithm(/*force=*/true);
}
break;
case 'MatrixActions.Room.receipt': {
Expand Down Expand Up @@ -517,6 +547,14 @@ class RoomListStore extends Store {
}

_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;
if (mentions) return CATEGORY_RED;

Expand Down

0 comments on commit 8a6dc1d

Please sign in to comment.