Support custom tags in the new algorithm
parent
e083d50e31
commit
3d152da822
|
@ -52,7 +52,6 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
|
|||
} else if (event.getType() === "im.vector.web.settings") {
|
||||
// We can't really discern what changed, so trigger updates for everything
|
||||
for (const settingName of Object.keys(event.getContent())) {
|
||||
console.log(settingName);
|
||||
this._watchers.notifyUpdate(settingName, null, event.getContent()[settingName]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ class RoomListStore extends Store {
|
|||
* behave.
|
||||
* @param {boolean} forceRegeneration True to force a change in the algorithm
|
||||
*/
|
||||
updateSortingAlgorithm(forceRegeneration=false) {
|
||||
updateSortingAlgorithm(forceRegeneration = false) {
|
||||
const byImportance = SettingsStore.getValue("RoomList.orderByImportance");
|
||||
if (byImportance !== this._state.orderRoomsByImportance || forceRegeneration) {
|
||||
console.log("Updating room sorting algorithm: sortByImportance=" + byImportance);
|
||||
|
@ -119,8 +119,15 @@ class RoomListStore extends Store {
|
|||
const logicallyReady = this._matrixClient && this._state.ready;
|
||||
switch (payload.action) {
|
||||
case 'setting_updated': {
|
||||
if (payload.settingName !== 'RoomList.orderByImportance') break;
|
||||
if (payload.settingName === 'RoomList.orderByImportance') {
|
||||
this.updateSortingAlgorithm();
|
||||
} else if (payload.settingName === 'feature_custom_tags') {
|
||||
const isActive = SettingsStore.isFeatureEnabled("feature_custom_tags");
|
||||
if (isActive !== this._state.tagsEnabled) {
|
||||
this._setState({tagsEnabled: isActive});
|
||||
this.updateSortingAlgorithm(/*force=*/true);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
// Initialise state after initial sync
|
||||
|
@ -129,6 +136,8 @@ class RoomListStore extends Store {
|
|||
break;
|
||||
}
|
||||
|
||||
this._setState({tagsEnabled: SettingsStore.isFeatureEnabled("feature_custom_tags")});
|
||||
|
||||
this._matrixClient = payload.matrixClient;
|
||||
this.updateSortingAlgorithm(/*force=*/true);
|
||||
}
|
||||
|
@ -269,14 +278,19 @@ class RoomListStore extends Store {
|
|||
}
|
||||
}
|
||||
|
||||
_filterTags(tags) {
|
||||
tags = tags ? Object.keys(tags) : [];
|
||||
if (this._state.tagsEnabled) return tags;
|
||||
return tags.filter((t) => !!LIST_ORDERS[t]);
|
||||
}
|
||||
|
||||
_getRecommendedTagsForRoom(room) {
|
||||
const tags = [];
|
||||
|
||||
const myMembership = room.getMyMembership();
|
||||
if (myMembership === 'join' || myMembership === 'invite') {
|
||||
// Stack the user's tags on top
|
||||
// TODO: Consider whether tags are enabled at all
|
||||
tags.push(...(room.tags || []));
|
||||
tags.push(...this._filterTags(room.tags));
|
||||
|
||||
const dmRoomMap = DMRoomMap.shared();
|
||||
if (dmRoomMap.getUserIdForRoomId(room.roomId)) {
|
||||
|
@ -328,15 +342,15 @@ class RoomListStore extends Store {
|
|||
// Speed optimization: Don't do complicated math if we don't have to.
|
||||
if (!shouldHaveRoom) {
|
||||
listsClone[key] = this._state.lists[key].filter((e) => e.room.roomId !== room.roomId);
|
||||
} else if (LIST_ORDERS[key] !== 'recent') {
|
||||
// Manually ordered tags are sorted later, so for now we'll just clone the tag
|
||||
// and add our room if needed
|
||||
listsClone[key] = this._state.lists[key].filter((e) => e.room.roomId !== room.roomId);
|
||||
listsClone[key].push({room, category});
|
||||
insertedIntoTags.push(key);
|
||||
} else {
|
||||
listsClone[key] = [];
|
||||
|
||||
// Tags sorted by recents are more complicated than manually ordered tags, so hope
|
||||
// for the best.
|
||||
// TODO: Use the SettingsStore watcher to determine if tags are enabled or not
|
||||
if (LIST_ORDERS[key] !== 'recent') {
|
||||
// TODO: Actually insert the room
|
||||
} else {
|
||||
// We track where the boundary within listsClone[key] is just in case our timestamp
|
||||
// ordering fails. If we can't stick the room in at the correct place in the category
|
||||
// grouping based on timestamp, we'll stick it at the top of the group which will be
|
||||
|
@ -408,7 +422,6 @@ class RoomListStore extends Store {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Double check that we inserted the room in the right places
|
||||
for (const targetTag of targetTags) {
|
||||
|
@ -422,6 +435,12 @@ class RoomListStore extends Store {
|
|||
}
|
||||
}
|
||||
|
||||
// Sort the favourites before we set the clone
|
||||
for (const tag of Object.keys(listsClone)) {
|
||||
if (LIST_ORDERS[tag] === 'recent') continue; // skip recents (pre-sorted)
|
||||
listsClone[tag].sort(this._getManualComparator(tag));
|
||||
}
|
||||
|
||||
this._setState({lists: listsClone});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue