Merge remote-tracking branch 'origin' into joriks/eslint-config
This commit is contained in:
commit
501e0c29ca
12 changed files with 96 additions and 61 deletions
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
|
||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||
import SettingsStore from "../../settings/SettingsStore";
|
||||
import { DefaultTagID, OrderedDefaultTagIDs, RoomUpdateCause, TagID } from "./models";
|
||||
import { DefaultTagID, isCustomTag, OrderedDefaultTagIDs, RoomUpdateCause, TagID } from "./models";
|
||||
import TagOrderStore from "../TagOrderStore";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { IListOrderingMap, ITagMap, ITagSortingMap, ListAlgorithm, SortAlgorithm } from "./algorithms/models";
|
||||
|
@ -33,6 +33,7 @@ import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
|
|||
import RoomListLayoutStore from "./RoomListLayoutStore";
|
||||
import { MarkedExecution } from "../../utils/MarkedExecution";
|
||||
import { AsyncStoreWithClient } from "../AsyncStoreWithClient";
|
||||
import { isEnumValue } from "../../utils/enums";
|
||||
|
||||
interface IState {
|
||||
tagsEnabled?: boolean;
|
||||
|
@ -527,25 +528,28 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
|
|||
public async regenerateAllLists({trigger = true}) {
|
||||
console.warn("Regenerating all room lists");
|
||||
|
||||
const rooms = this.matrixClient.getVisibleRooms();
|
||||
const customTags = new Set<TagID>();
|
||||
if (this.state.tagsEnabled) {
|
||||
for (const room of rooms) {
|
||||
if (!room.tags) continue;
|
||||
const tags = Object.keys(room.tags).filter(t => isCustomTag(t));
|
||||
tags.forEach(t => customTags.add(t));
|
||||
}
|
||||
}
|
||||
|
||||
const sorts: ITagSortingMap = {};
|
||||
const orders: IListOrderingMap = {};
|
||||
for (const tagId of OrderedDefaultTagIDs) {
|
||||
const allTags = [...OrderedDefaultTagIDs, ...Array.from(customTags)];
|
||||
for (const tagId of allTags) {
|
||||
sorts[tagId] = this.calculateTagSorting(tagId);
|
||||
orders[tagId] = this.calculateListOrder(tagId);
|
||||
|
||||
RoomListLayoutStore.instance.ensureLayoutExists(tagId);
|
||||
}
|
||||
|
||||
if (this.state.tagsEnabled) {
|
||||
// TODO: Fix custom tags: https://github.com/vector-im/riot-web/issues/14091
|
||||
const roomTags = TagOrderStore.getOrderedTags() || [];
|
||||
|
||||
// TODO: Remove debug: https://github.com/vector-im/riot-web/issues/14602
|
||||
console.log("rtags", roomTags);
|
||||
}
|
||||
|
||||
await this.algorithm.populateTags(sorts, orders);
|
||||
await this.algorithm.setKnownRooms(this.matrixClient.getVisibleRooms());
|
||||
await this.algorithm.setKnownRooms(rooms);
|
||||
|
||||
this.initialListsGenerated = true;
|
||||
|
||||
|
|
|
@ -20,10 +20,9 @@ import { CommunityFilterCondition } from "./filters/CommunityFilterCondition";
|
|||
import { arrayDiff, arrayHasDiff } from "../../utils/arrays";
|
||||
|
||||
/**
|
||||
* Watches for changes in tags/groups to manage filters on the provided RoomListStore
|
||||
* Watches for changes in groups to manage filters on the provided RoomListStore
|
||||
*/
|
||||
export class TagWatcher {
|
||||
// TODO: Support custom tags, somehow: https://github.com/vector-im/riot-web/issues/14091
|
||||
private filters = new Map<string, CommunityFilterCondition>();
|
||||
|
||||
constructor(private store: RoomListStoreClass) {
|
||||
|
@ -43,8 +42,6 @@ export class TagWatcher {
|
|||
}
|
||||
|
||||
const newFilters = new Map<string, CommunityFilterCondition>();
|
||||
|
||||
// TODO: Support custom tags, somehow: https://github.com/vector-im/riot-web/issues/14091
|
||||
const filterableTags = newTags.filter(t => t.startsWith("+"));
|
||||
|
||||
for (const tag of filterableTags) {
|
||||
|
@ -54,14 +51,16 @@ export class TagWatcher {
|
|||
continue;
|
||||
}
|
||||
|
||||
newFilters.set(tag, new CommunityFilterCondition(group));
|
||||
let filter = this.filters.get(tag);
|
||||
if (!filter) {
|
||||
filter = new CommunityFilterCondition(group);
|
||||
}
|
||||
newFilters.set(tag, filter);
|
||||
}
|
||||
|
||||
// Update the room list store's filters
|
||||
const diff = arrayDiff(lastTags, newTags);
|
||||
for (const tag of diff.added) {
|
||||
// TODO: Remove this check when custom tags are supported (as we shouldn't be losing filters)
|
||||
// Ref https://github.com/vector-im/riot-web/issues/14091
|
||||
const filter = newFilters.get(tag);
|
||||
if (!filter) continue;
|
||||
|
||||
|
@ -73,10 +72,6 @@ export class TagWatcher {
|
|||
if (!filter) continue;
|
||||
|
||||
this.store.removeFilter(filter);
|
||||
}
|
||||
|
||||
// Destroy any and all old filter conditions to prevent resource leaks
|
||||
for (const filter of this.filters.values()) {
|
||||
filter.destroy();
|
||||
}
|
||||
|
||||
|
|
|
@ -565,9 +565,6 @@ export class Algorithm extends EventEmitter {
|
|||
}
|
||||
|
||||
public getTagsForRoom(room: Room): TagID[] {
|
||||
// XXX: This duplicates a lot of logic from setKnownRooms above, but has a slightly
|
||||
// different use case and therefore different performance curve
|
||||
|
||||
const tags: TagID[] = [];
|
||||
|
||||
const membership = getEffectiveMembership(room.getMyMembership());
|
||||
|
|
|
@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { isEnumValue } from "../../utils/enums";
|
||||
|
||||
export enum DefaultTagID {
|
||||
Invite = "im.vector.fake.invite",
|
||||
Untagged = "im.vector.fake.recent", // legacy: used to just be 'recent rooms' but now it's all untagged rooms
|
||||
|
@ -36,6 +38,10 @@ export const OrderedDefaultTagIDs = [
|
|||
|
||||
export type TagID = string | DefaultTagID;
|
||||
|
||||
export function isCustomTag(tagId: TagID): boolean {
|
||||
return !isEnumValue(DefaultTagID, tagId);
|
||||
}
|
||||
|
||||
export enum RoomUpdateCause {
|
||||
Timeline = "TIMELINE",
|
||||
PossibleTagChange = "POSSIBLE_TAG_CHANGE",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue