Dismantle usage of the proxy store class

This commit is contained in:
Travis Ralston 2020-07-17 14:25:09 -06:00
parent 3c047cecfd
commit 1810711380
7 changed files with 23 additions and 54 deletions

View file

@ -20,7 +20,6 @@ import { ActionPayload } from "../dispatcher/payloads";
import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
import defaultDispatcher from "../dispatcher/dispatcher";
import { arrayHasDiff } from "../utils/arrays";
import { RoomListStoreTempProxy } from "./room-list/RoomListStoreTempProxy";
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
const MAX_ROOMS = 20; // arbitrary
@ -62,9 +61,6 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
protected async onAction(payload: ActionPayload) {
if (!this.matrixClient) return;
// TODO: Remove when new room list is made the default: https://github.com/vector-im/riot-web/issues/14367
if (!RoomListStoreTempProxy.isUsingNewStore()) return;
if (payload.action === 'setting_updated') {
if (payload.settingName === 'breadcrumb_rooms') {
await this.updateRooms();
@ -85,9 +81,6 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
}
protected async onReady() {
// TODO: Remove when new room list is made the default: https://github.com/vector-im/riot-web/issues/14367
if (!RoomListStoreTempProxy.isUsingNewStore()) return;
await this.updateRooms();
await this.updateState({enabled: SettingsStore.getValue("breadcrumbs", null)});
@ -96,9 +89,6 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
}
protected async onNotReady() {
// TODO: Remove when new room list is made the default: https://github.com/vector-im/riot-web/issues/14367
if (!RoomListStoreTempProxy.isUsingNewStore()) return;
this.matrixClient.removeListener("Room.myMembership", this.onMyMembership);
this.matrixClient.removeListener("Room", this.onRoom);
}

View file

@ -18,8 +18,9 @@ import * as RoomNotifs from '../RoomNotifs';
import EventEmitter from 'events';
import { throttle } from "lodash";
import SettingsStore from "../settings/SettingsStore";
import {RoomListStoreTempProxy} from "./room-list/RoomListStoreTempProxy";
import RoomListStore, {LISTS_UPDATE_EVENT} from "./room-list/RoomListStore2";
// TODO: All of this needs updating for new custom tags: https://github.com/vector-im/riot-web/issues/14091
const STANDARD_TAGS_REGEX = /^(m\.(favourite|lowpriority|server_notice)|im\.vector\.fake\.(invite|recent|direct|archived))$/;
function commonPrefix(a, b) {
@ -60,9 +61,7 @@ class CustomRoomTagStore extends EventEmitter {
trailing: true,
},
);
this._roomListStoreToken = RoomListStoreTempProxy.addListener(() => {
this._setState({tags: this._getUpdatedTags()});
});
RoomListStore.instance.on(LISTS_UPDATE_EVENT,this._onListsUpdated);
dis.register(payload => this._onDispatch(payload));
}
@ -85,7 +84,7 @@ class CustomRoomTagStore extends EventEmitter {
}
getSortedTags() {
const roomLists = RoomListStoreTempProxy.getRoomLists();
const roomLists = RoomListStore.instance.orderedLists;
const tagNames = Object.keys(this._state.tags).sort();
const prefixes = tagNames.map((name, i) => {
@ -109,6 +108,9 @@ class CustomRoomTagStore extends EventEmitter {
});
}
_onListsUpdated = () => {
this._setState({tags: this._getUpdatedTags()});
};
_onDispatch(payload) {
switch (payload.action) {
@ -126,10 +128,7 @@ class CustomRoomTagStore extends EventEmitter {
case 'on_logged_out': {
// we assume to always have a tags object in the state
this._state = {tags: {}};
if (this._roomListStoreToken) {
this._roomListStoreToken.remove();
this._roomListStoreToken = null;
}
RoomListStore.instance.off(LISTS_UPDATE_EVENT,this._onListsUpdated);
}
break;
}
@ -140,7 +139,7 @@ class CustomRoomTagStore extends EventEmitter {
return;
}
const newTagNames = Object.keys(RoomListStoreTempProxy.getRoomLists())
const newTagNames = Object.keys(RoomListStore.instance.orderedLists)
.filter((tagName) => {
return !tagName.match(STANDARD_TAGS_REGEX);
}).sort();

View file

@ -18,7 +18,6 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { ActionPayload } from "../../dispatcher/payloads";
import { AsyncStoreWithClient } from "../AsyncStoreWithClient";
import defaultDispatcher from "../../dispatcher/dispatcher";
import { RoomListStoreTempProxy } from "./RoomListStoreTempProxy";
import { MessageEventPreview } from "./previews/MessageEventPreview";
import { NameEventPreview } from "./previews/NameEventPreview";
import { TagID } from "./models";
@ -192,9 +191,6 @@ export class MessagePreviewStore extends AsyncStoreWithClient<IState> {
protected async onAction(payload: ActionPayload) {
if (!this.matrixClient) return;
// TODO: Remove when new room list is made the default: https://github.com/vector-im/riot-web/issues/14367
if (!RoomListStoreTempProxy.isUsingNewStore()) return;
if (payload.action === 'MatrixActions.Room.timeline' || payload.action === 'MatrixActions.Event.decrypted') {
const event = payload.event; // TODO: Type out the dispatcher
if (!Object.keys(this.state).includes(event.getRoomId())) return; // not important