Move SettingsStore setting_updated
dispatch to action enum
This commit is contained in:
parent
353c70ad75
commit
12461a79e1
5 changed files with 54 additions and 10 deletions
|
@ -193,4 +193,11 @@ export enum Action {
|
||||||
* Switches space. Should be used with SwitchSpacePayload.
|
* Switches space. Should be used with SwitchSpacePayload.
|
||||||
*/
|
*/
|
||||||
SwitchSpace = "switch_space",
|
SwitchSpace = "switch_space",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fires when a monitored setting is updated,
|
||||||
|
* see SettingsStore::monitorSetting for more details.
|
||||||
|
* Should be used with SettingUpdatedPayload.
|
||||||
|
*/
|
||||||
|
SettingUpdated = "setting_updated",
|
||||||
}
|
}
|
||||||
|
|
29
src/dispatcher/payloads/SettingUpdatedPayload.ts
Normal file
29
src/dispatcher/payloads/SettingUpdatedPayload.ts
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ActionPayload } from "../payloads";
|
||||||
|
import { Action } from "../actions";
|
||||||
|
import { SettingLevel } from "../../settings/SettingLevel";
|
||||||
|
|
||||||
|
export interface SettingUpdatedPayload extends ActionPayload {
|
||||||
|
action: Action.SettingUpdated;
|
||||||
|
|
||||||
|
settingName: string;
|
||||||
|
roomId: string;
|
||||||
|
level: SettingLevel;
|
||||||
|
newValueAtLevel: SettingLevel;
|
||||||
|
newValue: any;
|
||||||
|
}
|
|
@ -29,6 +29,8 @@ import LocalEchoWrapper from "./handlers/LocalEchoWrapper";
|
||||||
import { WatchManager, CallbackFn as WatchCallbackFn } from "./WatchManager";
|
import { WatchManager, CallbackFn as WatchCallbackFn } from "./WatchManager";
|
||||||
import { SettingLevel } from "./SettingLevel";
|
import { SettingLevel } from "./SettingLevel";
|
||||||
import SettingsHandler from "./handlers/SettingsHandler";
|
import SettingsHandler from "./handlers/SettingsHandler";
|
||||||
|
import { SettingUpdatedPayload } from "../dispatcher/payloads/SettingUpdatedPayload";
|
||||||
|
import { Action } from "../dispatcher/actions";
|
||||||
|
|
||||||
const defaultWatchManager = new WatchManager();
|
const defaultWatchManager = new WatchManager();
|
||||||
|
|
||||||
|
@ -147,7 +149,7 @@ export default class SettingsStore {
|
||||||
* if the change in value is worthwhile enough to react upon.
|
* if the change in value is worthwhile enough to react upon.
|
||||||
* @returns {string} A reference to the watcher that was employed.
|
* @returns {string} A reference to the watcher that was employed.
|
||||||
*/
|
*/
|
||||||
public static watchSetting(settingName: string, roomId: string, callbackFn: CallbackFn): string {
|
public static watchSetting(settingName: string, roomId: string | null, callbackFn: CallbackFn): string {
|
||||||
const setting = SETTINGS[settingName];
|
const setting = SETTINGS[settingName];
|
||||||
const originalSettingName = settingName;
|
const originalSettingName = settingName;
|
||||||
if (!setting) throw new Error(`${settingName} is not a setting`);
|
if (!setting) throw new Error(`${settingName} is not a setting`);
|
||||||
|
@ -193,7 +195,7 @@ export default class SettingsStore {
|
||||||
* @param {string} settingName The setting name to monitor.
|
* @param {string} settingName The setting name to monitor.
|
||||||
* @param {String} roomId The room ID to monitor for changes in. Use null for all rooms.
|
* @param {String} roomId The room ID to monitor for changes in. Use null for all rooms.
|
||||||
*/
|
*/
|
||||||
public static monitorSetting(settingName: string, roomId: string) {
|
public static monitorSetting(settingName: string, roomId: string | null) {
|
||||||
roomId = roomId || null; // the thing wants null specifically to work, so appease it.
|
roomId = roomId || null; // the thing wants null specifically to work, so appease it.
|
||||||
|
|
||||||
if (!this.monitors.has(settingName)) this.monitors.set(settingName, new Map());
|
if (!this.monitors.has(settingName)) this.monitors.set(settingName, new Map());
|
||||||
|
@ -201,8 +203,8 @@ export default class SettingsStore {
|
||||||
const registerWatcher = () => {
|
const registerWatcher = () => {
|
||||||
this.monitors.get(settingName).set(roomId, SettingsStore.watchSetting(
|
this.monitors.get(settingName).set(roomId, SettingsStore.watchSetting(
|
||||||
settingName, roomId, (settingName, inRoomId, level, newValueAtLevel, newValue) => {
|
settingName, roomId, (settingName, inRoomId, level, newValueAtLevel, newValue) => {
|
||||||
dis.dispatch({
|
dis.dispatch<SettingUpdatedPayload>({
|
||||||
action: 'setting_updated',
|
action: Action.SettingUpdated,
|
||||||
settingName,
|
settingName,
|
||||||
roomId: inRoomId,
|
roomId: inRoomId,
|
||||||
level,
|
level,
|
||||||
|
|
|
@ -23,6 +23,8 @@ import { arrayHasDiff } from "../utils/arrays";
|
||||||
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
|
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
|
||||||
import { SettingLevel } from "../settings/SettingLevel";
|
import { SettingLevel } from "../settings/SettingLevel";
|
||||||
import SpaceStore from "./SpaceStore";
|
import SpaceStore from "./SpaceStore";
|
||||||
|
import { Action } from "../dispatcher/actions";
|
||||||
|
import { SettingUpdatedPayload } from "../dispatcher/payloads/SettingUpdatedPayload";
|
||||||
|
|
||||||
const MAX_ROOMS = 20; // arbitrary
|
const MAX_ROOMS = 20; // arbitrary
|
||||||
const AUTOJOIN_WAIT_THRESHOLD_MS = 90000; // 90s, the time we wait for an autojoined room to show up
|
const AUTOJOIN_WAIT_THRESHOLD_MS = 90000; // 90s, the time we wait for an autojoined room to show up
|
||||||
|
@ -63,10 +65,11 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
|
||||||
protected async onAction(payload: ActionPayload) {
|
protected async onAction(payload: ActionPayload) {
|
||||||
if (!this.matrixClient) return;
|
if (!this.matrixClient) return;
|
||||||
|
|
||||||
if (payload.action === 'setting_updated') {
|
if (payload.action === Action.SettingUpdated) {
|
||||||
if (payload.settingName === 'breadcrumb_rooms') {
|
const settingUpdatedPayload = payload as SettingUpdatedPayload;
|
||||||
|
if (settingUpdatedPayload.settingName === 'breadcrumb_rooms') {
|
||||||
await this.updateRooms();
|
await this.updateRooms();
|
||||||
} else if (payload.settingName === 'breadcrumbs') {
|
} else if (settingUpdatedPayload.settingName === 'breadcrumbs') {
|
||||||
await this.updateState({ enabled: SettingsStore.getValue("breadcrumbs", null) });
|
await this.updateState({ enabled: SettingsStore.getValue("breadcrumbs", null) });
|
||||||
}
|
}
|
||||||
} else if (payload.action === 'view_room') {
|
} else if (payload.action === 'view_room') {
|
||||||
|
|
|
@ -36,6 +36,8 @@ import { RoomNotificationStateStore } from "../notifications/RoomNotificationSta
|
||||||
import { VisibilityProvider } from "./filters/VisibilityProvider";
|
import { VisibilityProvider } from "./filters/VisibilityProvider";
|
||||||
import { SpaceWatcher } from "./SpaceWatcher";
|
import { SpaceWatcher } from "./SpaceWatcher";
|
||||||
import SpaceStore from "../SpaceStore";
|
import SpaceStore from "../SpaceStore";
|
||||||
|
import { Action } from "../../dispatcher/actions";
|
||||||
|
import { SettingUpdatedPayload } from "../../dispatcher/payloads/SettingUpdatedPayload";
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
tagsEnabled?: boolean;
|
tagsEnabled?: boolean;
|
||||||
|
@ -213,10 +215,11 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
const logicallyReady = this.matrixClient && this.initialListsGenerated;
|
const logicallyReady = this.matrixClient && this.initialListsGenerated;
|
||||||
if (!logicallyReady) return;
|
if (!logicallyReady) return;
|
||||||
|
|
||||||
if (payload.action === 'setting_updated') {
|
if (payload.action === Action.SettingUpdated) {
|
||||||
if (this.watchedSettings.includes(payload.settingName)) {
|
const settingUpdatedPayload = payload as SettingUpdatedPayload;
|
||||||
|
if (this.watchedSettings.includes(settingUpdatedPayload.settingName)) {
|
||||||
// TODO: Remove with https://github.com/vector-im/element-web/issues/14602
|
// TODO: Remove with https://github.com/vector-im/element-web/issues/14602
|
||||||
if (payload.settingName === "advancedRoomListLogging") {
|
if (settingUpdatedPayload.settingName === "advancedRoomListLogging") {
|
||||||
// Log when the setting changes so we know when it was turned on in the rageshake
|
// Log when the setting changes so we know when it was turned on in the rageshake
|
||||||
const enabled = SettingsStore.getValue("advancedRoomListLogging");
|
const enabled = SettingsStore.getValue("advancedRoomListLogging");
|
||||||
console.warn("Advanced room list logging is enabled? " + enabled);
|
console.warn("Advanced room list logging is enabled? " + enabled);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue