Dismantle usage of the proxy store class
This commit is contained in:
parent
3c047cecfd
commit
1810711380
7 changed files with 23 additions and 54 deletions
|
@ -24,7 +24,8 @@ import * as sdk from '../index';
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
import { Room } from "matrix-js-sdk/src/models/room";
|
import { Room } from "matrix-js-sdk/src/models/room";
|
||||||
import { AsyncActionPayload } from "../dispatcher/payloads";
|
import { AsyncActionPayload } from "../dispatcher/payloads";
|
||||||
import { RoomListStoreTempProxy } from "../stores/room-list/RoomListStoreTempProxy";
|
import RoomListStore from "../stores/room-list/RoomListStore2";
|
||||||
|
import { SortAlgorithm } from "../stores/room-list/algorithms/models";
|
||||||
|
|
||||||
export default class RoomListActions {
|
export default class RoomListActions {
|
||||||
/**
|
/**
|
||||||
|
@ -51,9 +52,9 @@ export default class RoomListActions {
|
||||||
let metaData = null;
|
let metaData = null;
|
||||||
|
|
||||||
// Is the tag ordered manually?
|
// Is the tag ordered manually?
|
||||||
if (newTag && !newTag.match(/^(m\.lowpriority|im\.vector\.fake\.(invite|recent|direct|archived))$/)) {
|
const store = RoomListStore.instance;
|
||||||
const lists = RoomListStoreTempProxy.getRoomLists();
|
if (newTag && store.getTagSorting(newTag) === SortAlgorithm.Manual) {
|
||||||
const newList = [...lists[newTag]];
|
const newList = [...store.orderedLists[newTag]];
|
||||||
|
|
||||||
newList.sort((a, b) => a.tags[newTag].order - b.tags[newTag].order);
|
newList.sort((a, b) => a.tags[newTag].order - b.tags[newTag].order);
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ import * as KeyboardShortcuts from "../../accessibility/KeyboardShortcuts";
|
||||||
import HomePage from "./HomePage";
|
import HomePage from "./HomePage";
|
||||||
import ResizeNotifier from "../../utils/ResizeNotifier";
|
import ResizeNotifier from "../../utils/ResizeNotifier";
|
||||||
import PlatformPeg from "../../PlatformPeg";
|
import PlatformPeg from "../../PlatformPeg";
|
||||||
import { RoomListStoreTempProxy } from "../../stores/room-list/RoomListStoreTempProxy";
|
|
||||||
import { DefaultTagID } from "../../stores/room-list/models";
|
import { DefaultTagID } from "../../stores/room-list/models";
|
||||||
import {
|
import {
|
||||||
showToast as showSetPasswordToast,
|
showToast as showSetPasswordToast,
|
||||||
|
@ -54,6 +53,7 @@ import { Action } from "../../dispatcher/actions";
|
||||||
import LeftPanel2 from "./LeftPanel2";
|
import LeftPanel2 from "./LeftPanel2";
|
||||||
import CallContainer from '../views/voip/CallContainer';
|
import CallContainer from '../views/voip/CallContainer';
|
||||||
import { ViewRoomDeltaPayload } from "../../dispatcher/payloads/ViewRoomDeltaPayload";
|
import { ViewRoomDeltaPayload } from "../../dispatcher/payloads/ViewRoomDeltaPayload";
|
||||||
|
import RoomListStore from "../../stores/room-list/RoomListStore2";
|
||||||
|
|
||||||
// We need to fetch each pinned message individually (if we don't already have it)
|
// We need to fetch each pinned message individually (if we don't already have it)
|
||||||
// so each pinned message may trigger a request. Limit the number per room for sanity.
|
// so each pinned message may trigger a request. Limit the number per room for sanity.
|
||||||
|
@ -308,8 +308,8 @@ class LoggedInView extends React.Component<IProps, IState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
onRoomStateEvents = (ev, state) => {
|
onRoomStateEvents = (ev, state) => {
|
||||||
const roomLists = RoomListStoreTempProxy.getRoomLists();
|
const serverNoticeList = RoomListStore.instance.orderedLists[DefaultTagID.ServerNotice];
|
||||||
if (roomLists[DefaultTagID.ServerNotice] && roomLists[DefaultTagID.ServerNotice].some(r => r.roomId === ev.getRoomId())) {
|
if (serverNoticeList && serverNoticeList.some(r => r.roomId === ev.getRoomId())) {
|
||||||
this._updateServerNoticeEvents();
|
this._updateServerNoticeEvents();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -328,11 +328,11 @@ class LoggedInView extends React.Component<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateServerNoticeEvents = async () => {
|
_updateServerNoticeEvents = async () => {
|
||||||
const roomLists = RoomListStoreTempProxy.getRoomLists();
|
const serverNoticeList = RoomListStore.instance.orderedLists[DefaultTagID.ServerNotice];
|
||||||
if (!roomLists[DefaultTagID.ServerNotice]) return [];
|
if (!serverNoticeList) return [];
|
||||||
|
|
||||||
const events = [];
|
const events = [];
|
||||||
for (const room of roomLists[DefaultTagID.ServerNotice]) {
|
for (const room of serverNoticeList) {
|
||||||
const pinStateEvent = room.currentState.getStateEvents("m.room.pinned_events", "");
|
const pinStateEvent = room.currentState.getStateEvents("m.room.pinned_events", "");
|
||||||
|
|
||||||
if (!pinStateEvent || !pinStateEvent.getContent().pinned) continue;
|
if (!pinStateEvent || !pinStateEvent.getContent().pinned) continue;
|
||||||
|
|
|
@ -35,8 +35,8 @@ import createRoom, {canEncryptToAllUsers, privateShouldBeEncrypted} from "../../
|
||||||
import {inviteMultipleToRoom} from "../../../RoomInvite";
|
import {inviteMultipleToRoom} from "../../../RoomInvite";
|
||||||
import {Key} from "../../../Keyboard";
|
import {Key} from "../../../Keyboard";
|
||||||
import {Action} from "../../../dispatcher/actions";
|
import {Action} from "../../../dispatcher/actions";
|
||||||
import {RoomListStoreTempProxy} from "../../../stores/room-list/RoomListStoreTempProxy";
|
|
||||||
import {DefaultTagID} from "../../../stores/room-list/models";
|
import {DefaultTagID} from "../../../stores/room-list/models";
|
||||||
|
import RoomListStore from "../../../stores/room-list/RoomListStore2";
|
||||||
|
|
||||||
export const KIND_DM = "dm";
|
export const KIND_DM = "dm";
|
||||||
export const KIND_INVITE = "invite";
|
export const KIND_INVITE = "invite";
|
||||||
|
@ -346,8 +346,7 @@ export default class InviteDialog extends React.PureComponent {
|
||||||
|
|
||||||
// Also pull in all the rooms tagged as DefaultTagID.DM so we don't miss anything. Sometimes the
|
// Also pull in all the rooms tagged as DefaultTagID.DM so we don't miss anything. Sometimes the
|
||||||
// room list doesn't tag the room for the DMRoomMap, but does for the room list.
|
// room list doesn't tag the room for the DMRoomMap, but does for the room list.
|
||||||
const taggedRooms = RoomListStoreTempProxy.getRoomLists();
|
const dmTaggedRooms = RoomListStore.instance.orderedLists[DefaultTagID.DM];
|
||||||
const dmTaggedRooms = taggedRooms[DefaultTagID.DM];
|
|
||||||
const myUserId = MatrixClientPeg.get().getUserId();
|
const myUserId = MatrixClientPeg.get().getUserId();
|
||||||
for (const dmRoom of dmTaggedRooms) {
|
for (const dmRoom of dmTaggedRooms) {
|
||||||
const otherMembers = dmRoom.getJoinedMembers().filter(u => u.userId !== myUserId);
|
const otherMembers = dmRoom.getJoinedMembers().filter(u => u.userId !== myUserId);
|
||||||
|
|
|
@ -23,28 +23,12 @@ import SettingsStore from "../../../../../settings/SettingsStore";
|
||||||
import Field from "../../../elements/Field";
|
import Field from "../../../elements/Field";
|
||||||
import * as sdk from "../../../../..";
|
import * as sdk from "../../../../..";
|
||||||
import PlatformPeg from "../../../../../PlatformPeg";
|
import PlatformPeg from "../../../../../PlatformPeg";
|
||||||
import {RoomListStoreTempProxy} from "../../../../../stores/room-list/RoomListStoreTempProxy";
|
|
||||||
|
|
||||||
export default class PreferencesUserSettingsTab extends React.Component {
|
export default class PreferencesUserSettingsTab extends React.Component {
|
||||||
static ROOM_LIST_SETTINGS = [
|
static ROOM_LIST_SETTINGS = [
|
||||||
'RoomList.orderAlphabetically',
|
|
||||||
'RoomList.orderByImportance',
|
|
||||||
'breadcrumbs',
|
'breadcrumbs',
|
||||||
];
|
];
|
||||||
|
|
||||||
// TODO: Remove temp structures: https://github.com/vector-im/riot-web/issues/14367
|
|
||||||
static ROOM_LIST_2_SETTINGS = [
|
|
||||||
'breadcrumbs',
|
|
||||||
];
|
|
||||||
|
|
||||||
// TODO: Remove temp structures: https://github.com/vector-im/riot-web/issues/14367
|
|
||||||
static eligibleRoomListSettings = () => {
|
|
||||||
if (RoomListStoreTempProxy.isUsingNewStore()) {
|
|
||||||
return PreferencesUserSettingsTab.ROOM_LIST_2_SETTINGS;
|
|
||||||
}
|
|
||||||
return PreferencesUserSettingsTab.ROOM_LIST_SETTINGS;
|
|
||||||
};
|
|
||||||
|
|
||||||
static COMPOSER_SETTINGS = [
|
static COMPOSER_SETTINGS = [
|
||||||
'MessageComposerInput.autoReplaceEmoji',
|
'MessageComposerInput.autoReplaceEmoji',
|
||||||
'MessageComposerInput.suggestEmoji',
|
'MessageComposerInput.suggestEmoji',
|
||||||
|
@ -189,7 +173,7 @@ export default class PreferencesUserSettingsTab extends React.Component {
|
||||||
|
|
||||||
<div className="mx_SettingsTab_section">
|
<div className="mx_SettingsTab_section">
|
||||||
<span className="mx_SettingsTab_subheading">{_t("Room list")}</span>
|
<span className="mx_SettingsTab_subheading">{_t("Room list")}</span>
|
||||||
{this._renderGroup(PreferencesUserSettingsTab.eligibleRoomListSettings())}
|
{this._renderGroup(PreferencesUserSettingsTab.ROOM_LIST_SETTINGS)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mx_SettingsTab_section">
|
<div className="mx_SettingsTab_section">
|
||||||
|
|
|
@ -20,7 +20,6 @@ import { ActionPayload } from "../dispatcher/payloads";
|
||||||
import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
|
import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
|
||||||
import defaultDispatcher from "../dispatcher/dispatcher";
|
import defaultDispatcher from "../dispatcher/dispatcher";
|
||||||
import { arrayHasDiff } from "../utils/arrays";
|
import { arrayHasDiff } from "../utils/arrays";
|
||||||
import { RoomListStoreTempProxy } from "./room-list/RoomListStoreTempProxy";
|
|
||||||
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
|
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
|
||||||
|
|
||||||
const MAX_ROOMS = 20; // arbitrary
|
const MAX_ROOMS = 20; // arbitrary
|
||||||
|
@ -62,9 +61,6 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
|
||||||
protected async onAction(payload: ActionPayload) {
|
protected async onAction(payload: ActionPayload) {
|
||||||
if (!this.matrixClient) return;
|
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.action === 'setting_updated') {
|
||||||
if (payload.settingName === 'breadcrumb_rooms') {
|
if (payload.settingName === 'breadcrumb_rooms') {
|
||||||
await this.updateRooms();
|
await this.updateRooms();
|
||||||
|
@ -85,9 +81,6 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async onReady() {
|
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.updateRooms();
|
||||||
await this.updateState({enabled: SettingsStore.getValue("breadcrumbs", null)});
|
await this.updateState({enabled: SettingsStore.getValue("breadcrumbs", null)});
|
||||||
|
|
||||||
|
@ -96,9 +89,6 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async onNotReady() {
|
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.myMembership", this.onMyMembership);
|
||||||
this.matrixClient.removeListener("Room", this.onRoom);
|
this.matrixClient.removeListener("Room", this.onRoom);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,9 @@ import * as RoomNotifs from '../RoomNotifs';
|
||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
import { throttle } from "lodash";
|
import { throttle } from "lodash";
|
||||||
import SettingsStore from "../settings/SettingsStore";
|
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))$/;
|
const STANDARD_TAGS_REGEX = /^(m\.(favourite|lowpriority|server_notice)|im\.vector\.fake\.(invite|recent|direct|archived))$/;
|
||||||
|
|
||||||
function commonPrefix(a, b) {
|
function commonPrefix(a, b) {
|
||||||
|
@ -60,9 +61,7 @@ class CustomRoomTagStore extends EventEmitter {
|
||||||
trailing: true,
|
trailing: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
this._roomListStoreToken = RoomListStoreTempProxy.addListener(() => {
|
RoomListStore.instance.on(LISTS_UPDATE_EVENT,this._onListsUpdated);
|
||||||
this._setState({tags: this._getUpdatedTags()});
|
|
||||||
});
|
|
||||||
dis.register(payload => this._onDispatch(payload));
|
dis.register(payload => this._onDispatch(payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +84,7 @@ class CustomRoomTagStore extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
getSortedTags() {
|
getSortedTags() {
|
||||||
const roomLists = RoomListStoreTempProxy.getRoomLists();
|
const roomLists = RoomListStore.instance.orderedLists;
|
||||||
|
|
||||||
const tagNames = Object.keys(this._state.tags).sort();
|
const tagNames = Object.keys(this._state.tags).sort();
|
||||||
const prefixes = tagNames.map((name, i) => {
|
const prefixes = tagNames.map((name, i) => {
|
||||||
|
@ -109,6 +108,9 @@ class CustomRoomTagStore extends EventEmitter {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onListsUpdated = () => {
|
||||||
|
this._setState({tags: this._getUpdatedTags()});
|
||||||
|
};
|
||||||
|
|
||||||
_onDispatch(payload) {
|
_onDispatch(payload) {
|
||||||
switch (payload.action) {
|
switch (payload.action) {
|
||||||
|
@ -126,10 +128,7 @@ class CustomRoomTagStore extends EventEmitter {
|
||||||
case 'on_logged_out': {
|
case 'on_logged_out': {
|
||||||
// we assume to always have a tags object in the state
|
// we assume to always have a tags object in the state
|
||||||
this._state = {tags: {}};
|
this._state = {tags: {}};
|
||||||
if (this._roomListStoreToken) {
|
RoomListStore.instance.off(LISTS_UPDATE_EVENT,this._onListsUpdated);
|
||||||
this._roomListStoreToken.remove();
|
|
||||||
this._roomListStoreToken = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +139,7 @@ class CustomRoomTagStore extends EventEmitter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newTagNames = Object.keys(RoomListStoreTempProxy.getRoomLists())
|
const newTagNames = Object.keys(RoomListStore.instance.orderedLists)
|
||||||
.filter((tagName) => {
|
.filter((tagName) => {
|
||||||
return !tagName.match(STANDARD_TAGS_REGEX);
|
return !tagName.match(STANDARD_TAGS_REGEX);
|
||||||
}).sort();
|
}).sort();
|
||||||
|
|
|
@ -18,7 +18,6 @@ import { Room } from "matrix-js-sdk/src/models/room";
|
||||||
import { ActionPayload } from "../../dispatcher/payloads";
|
import { ActionPayload } from "../../dispatcher/payloads";
|
||||||
import { AsyncStoreWithClient } from "../AsyncStoreWithClient";
|
import { AsyncStoreWithClient } from "../AsyncStoreWithClient";
|
||||||
import defaultDispatcher from "../../dispatcher/dispatcher";
|
import defaultDispatcher from "../../dispatcher/dispatcher";
|
||||||
import { RoomListStoreTempProxy } from "./RoomListStoreTempProxy";
|
|
||||||
import { MessageEventPreview } from "./previews/MessageEventPreview";
|
import { MessageEventPreview } from "./previews/MessageEventPreview";
|
||||||
import { NameEventPreview } from "./previews/NameEventPreview";
|
import { NameEventPreview } from "./previews/NameEventPreview";
|
||||||
import { TagID } from "./models";
|
import { TagID } from "./models";
|
||||||
|
@ -192,9 +191,6 @@ export class MessagePreviewStore extends AsyncStoreWithClient<IState> {
|
||||||
protected async onAction(payload: ActionPayload) {
|
protected async onAction(payload: ActionPayload) {
|
||||||
if (!this.matrixClient) return;
|
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') {
|
if (payload.action === 'MatrixActions.Room.timeline' || payload.action === 'MatrixActions.Event.decrypted') {
|
||||||
const event = payload.event; // TODO: Type out the dispatcher
|
const event = payload.event; // TODO: Type out the dispatcher
|
||||||
if (!Object.keys(this.state).includes(event.getRoomId())) return; // not important
|
if (!Object.keys(this.state).includes(event.getRoomId())) return; // not important
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue