mirror of https://github.com/vector-im/riot-web
Merge branch 'develop' into travis/room-list/enable
commit
8357461c9b
|
@ -479,13 +479,13 @@ export const SETTINGS = {
|
|||
deny: [],
|
||||
},
|
||||
},
|
||||
// TODO: Remove setting: https://github.com/vector-im/riot-web/issues/14231
|
||||
// TODO: Remove setting: https://github.com/vector-im/riot-web/issues/14373
|
||||
"RoomList.orderAlphabetically": {
|
||||
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
|
||||
displayName: _td("Order rooms by name"),
|
||||
default: false,
|
||||
},
|
||||
// TODO: Remove setting: https://github.com/vector-im/riot-web/issues/14231
|
||||
// TODO: Remove setting: https://github.com/vector-im/riot-web/issues/14373
|
||||
"RoomList.orderByImportance": {
|
||||
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
|
||||
displayName: _td("Show rooms with unread notifications first"),
|
||||
|
|
|
@ -31,6 +31,7 @@ import RoomViewStore from "../RoomViewStore";
|
|||
import { Algorithm, LIST_UPDATED_EVENT } from "./algorithms/Algorithm";
|
||||
import { EffectiveMembership, getEffectiveMembership } from "./membership";
|
||||
import { ListLayout } from "./ListLayout";
|
||||
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
|
||||
|
||||
interface IState {
|
||||
tagsEnabled?: boolean;
|
||||
|
@ -336,6 +337,28 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
|
|||
return <SortAlgorithm>localStorage.getItem(`mx_tagSort_${tagId}`);
|
||||
}
|
||||
|
||||
// logic must match calculateListOrder
|
||||
private calculateTagSorting(tagId: TagID): SortAlgorithm {
|
||||
const defaultSort = SortAlgorithm.Alphabetic;
|
||||
const settingAlphabetical = SettingsStore.getValue("RoomList.orderAlphabetically", null, true);
|
||||
const definedSort = this.getTagSorting(tagId);
|
||||
const storedSort = this.getStoredTagSorting(tagId);
|
||||
|
||||
// We use the following order to determine which of the 4 flags to use:
|
||||
// Stored > Settings > Defined > Default
|
||||
|
||||
let tagSort = defaultSort;
|
||||
if (storedSort) {
|
||||
tagSort = storedSort;
|
||||
} else if (!isNullOrUndefined(settingAlphabetical)) {
|
||||
tagSort = settingAlphabetical ? SortAlgorithm.Alphabetic : SortAlgorithm.Recent;
|
||||
} else if (definedSort) {
|
||||
tagSort = definedSort;
|
||||
} // else default (already set)
|
||||
|
||||
return tagSort;
|
||||
}
|
||||
|
||||
public async setListOrder(tagId: TagID, order: ListAlgorithm) {
|
||||
await this.algorithm.setListOrdering(tagId, order);
|
||||
// TODO: Per-account? https://github.com/vector-im/riot-web/issues/14114
|
||||
|
@ -352,19 +375,35 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
|
|||
return <ListAlgorithm>localStorage.getItem(`mx_listOrder_${tagId}`);
|
||||
}
|
||||
|
||||
private async updateAlgorithmInstances() {
|
||||
const defaultSort = SortAlgorithm.Alphabetic;
|
||||
// logic must match calculateTagSorting
|
||||
private calculateListOrder(tagId: TagID): ListAlgorithm {
|
||||
const defaultOrder = ListAlgorithm.Natural;
|
||||
const settingImportance = SettingsStore.getValue("RoomList.orderByImportance", null, true);
|
||||
const definedOrder = this.getListOrder(tagId);
|
||||
const storedOrder = this.getStoredListOrder(tagId);
|
||||
|
||||
// We use the following order to determine which of the 4 flags to use:
|
||||
// Stored > Settings > Defined > Default
|
||||
|
||||
let listOrder = defaultOrder;
|
||||
if (storedOrder) {
|
||||
listOrder = storedOrder;
|
||||
} else if (!isNullOrUndefined(settingImportance)) {
|
||||
listOrder = settingImportance ? ListAlgorithm.Importance : ListAlgorithm.Natural;
|
||||
} else if (definedOrder) {
|
||||
listOrder = definedOrder;
|
||||
} // else default (already set)
|
||||
|
||||
return listOrder;
|
||||
}
|
||||
|
||||
private async updateAlgorithmInstances() {
|
||||
for (const tag of Object.keys(this.orderedLists)) {
|
||||
const definedSort = this.getTagSorting(tag);
|
||||
const definedOrder = this.getListOrder(tag);
|
||||
|
||||
const storedSort = this.getStoredTagSorting(tag);
|
||||
const storedOrder = this.getStoredListOrder(tag);
|
||||
|
||||
const tagSort = storedSort ? storedSort : (definedSort ? definedSort : defaultSort);
|
||||
const listOrder = storedOrder ? storedOrder : (definedOrder ? definedOrder : defaultOrder);
|
||||
const tagSort = this.calculateTagSorting(tag);
|
||||
const listOrder = this.calculateListOrder(tag);
|
||||
|
||||
if (tagSort !== definedSort) {
|
||||
await this.setTagSorting(tag, tagSort);
|
||||
|
@ -394,8 +433,8 @@ export class RoomListStore2 extends AsyncStore<ActionPayload> {
|
|||
const sorts: ITagSortingMap = {};
|
||||
const orders: IListOrderingMap = {};
|
||||
for (const tagId of OrderedDefaultTagIDs) {
|
||||
sorts[tagId] = this.getStoredTagSorting(tagId) || SortAlgorithm.Alphabetic;
|
||||
orders[tagId] = this.getStoredListOrder(tagId) || ListAlgorithm.Natural;
|
||||
sorts[tagId] = this.calculateTagSorting(tagId);
|
||||
orders[tagId] = this.calculateListOrder(tagId);
|
||||
}
|
||||
|
||||
if (this.state.tagsEnabled) {
|
||||
|
|
|
@ -109,6 +109,7 @@ export class Algorithm extends EventEmitter {
|
|||
}
|
||||
|
||||
public getTagSorting(tagId: TagID): SortAlgorithm {
|
||||
if (!this.sortAlgorithms) return null;
|
||||
return this.sortAlgorithms[tagId];
|
||||
}
|
||||
|
||||
|
@ -125,6 +126,7 @@ export class Algorithm extends EventEmitter {
|
|||
}
|
||||
|
||||
public getListOrdering(tagId: TagID): ListAlgorithm {
|
||||
if (!this.listAlgorithms) return null;
|
||||
return this.listAlgorithms[tagId];
|
||||
}
|
||||
|
||||
|
@ -522,7 +524,7 @@ export class Algorithm extends EventEmitter {
|
|||
}
|
||||
|
||||
if (!inTag) {
|
||||
if (DMRoomMap.getUserIdForRoomId(room.roomId)) {
|
||||
if (DMRoomMap.shared().getUserIdForRoomId(room.roomId)) {
|
||||
newTags[DefaultTagID.DM].push(room);
|
||||
} else {
|
||||
newTags[DefaultTagID.Untagged].push(room);
|
||||
|
|
Loading…
Reference in New Issue