mirror of https://github.com/vector-im/riot-web
Merge pull request #5176 from matrix-org/t3chguy/dpsah/6785.4
Fix WatchManager for global room watchers and tidy widget code a littlepull/21833/head
commit
87b72de25f
|
@ -310,20 +310,7 @@ export default class AppTile extends React.Component {
|
||||||
if (this.props.onEditClick) {
|
if (this.props.onEditClick) {
|
||||||
this.props.onEditClick();
|
this.props.onEditClick();
|
||||||
} else {
|
} else {
|
||||||
// TODO: Open the right manager for the widget
|
WidgetUtils.editWidget(this.props.room, this.props.app);
|
||||||
if (SettingsStore.getValue("feature_many_integration_managers")) {
|
|
||||||
IntegrationManagers.sharedInstance().openAll(
|
|
||||||
this.props.room,
|
|
||||||
'type_' + this.props.app.type,
|
|
||||||
this.props.app.id,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
IntegrationManagers.sharedInstance().getPrimaryManager().open(
|
|
||||||
this.props.room,
|
|
||||||
'type_' + this.props.app.type,
|
|
||||||
this.props.app.id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,10 @@ import { SettingLevel } from "./SettingLevel";
|
||||||
|
|
||||||
export type CallbackFn = (changedInRoomId: string, atLevel: SettingLevel, newValAtLevel: any) => void;
|
export type CallbackFn = (changedInRoomId: string, atLevel: SettingLevel, newValAtLevel: any) => void;
|
||||||
|
|
||||||
const IRRELEVANT_ROOM = Symbol("any room");
|
const IRRELEVANT_ROOM: string = null;
|
||||||
|
|
||||||
interface RoomWatcherMap {
|
interface RoomWatcherMap {
|
||||||
// @ts-ignore - TS wants string-only keys but we know better - https://github.com/Microsoft/TypeScript/issues/1863
|
[roomId: string]: CallbackFn[];
|
||||||
[roomId: string | symbol]: CallbackFn[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +68,7 @@ export class WatchManager {
|
||||||
if (!inRoomId) {
|
if (!inRoomId) {
|
||||||
// Fire updates to all the individual room watchers too, as they probably
|
// Fire updates to all the individual room watchers too, as they probably
|
||||||
// care about the change higher up.
|
// care about the change higher up.
|
||||||
callbacks.push(...Object.values(roomWatchers).reduce((r, a) => [...r, ...a], []));
|
callbacks.push(...Object.values(roomWatchers).flat(1));
|
||||||
} else if (roomWatchers[IRRELEVANT_ROOM]) {
|
} else if (roomWatchers[IRRELEVANT_ROOM]) {
|
||||||
callbacks.push(...roomWatchers[IRRELEVANT_ROOM]);
|
callbacks.push(...roomWatchers[IRRELEVANT_ROOM]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,13 +93,13 @@ class WidgetEchoStore extends EventEmitter {
|
||||||
if (this._roomWidgetEcho[roomId] === undefined) this._roomWidgetEcho[roomId] = {};
|
if (this._roomWidgetEcho[roomId] === undefined) this._roomWidgetEcho[roomId] = {};
|
||||||
|
|
||||||
this._roomWidgetEcho[roomId][widgetId] = state;
|
this._roomWidgetEcho[roomId][widgetId] = state;
|
||||||
this.emit('update');
|
this.emit('update', roomId, widgetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeRoomWidgetEcho(roomId, widgetId) {
|
removeRoomWidgetEcho(roomId, widgetId) {
|
||||||
delete this._roomWidgetEcho[roomId][widgetId];
|
delete this._roomWidgetEcho[roomId][widgetId];
|
||||||
if (Object.keys(this._roomWidgetEcho[roomId]).length === 0) delete this._roomWidgetEcho[roomId];
|
if (Object.keys(this._roomWidgetEcho[roomId]).length === 0) delete this._roomWidgetEcho[roomId];
|
||||||
this.emit('update');
|
this.emit('update', roomId, widgetId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -405,6 +405,7 @@ export default class WidgetUtils {
|
||||||
app.creatorUserId = senderUserId;
|
app.creatorUserId = senderUserId;
|
||||||
|
|
||||||
app.id = appId;
|
app.id = appId;
|
||||||
|
app.roomId = roomId;
|
||||||
app.eventId = eventId;
|
app.eventId = eventId;
|
||||||
app.name = app.name || app.type;
|
app.name = app.name || app.type;
|
||||||
|
|
||||||
|
@ -476,4 +477,13 @@ export default class WidgetUtils {
|
||||||
const url = new URL("jitsi.html#" + queryString, baseUrl); // this strips hash fragment from baseUrl
|
const url = new URL("jitsi.html#" + queryString, baseUrl); // this strips hash fragment from baseUrl
|
||||||
return url.href;
|
return url.href;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static editWidget(room, app) {
|
||||||
|
// TODO: Open the right manager for the widget
|
||||||
|
if (SettingsStore.getValue("feature_many_integration_managers")) {
|
||||||
|
IntegrationManagers.sharedInstance().openAll(room, 'type_' + app.type, app.id);
|
||||||
|
} else {
|
||||||
|
IntegrationManagers.sharedInstance().getPrimaryManager().open(room, 'type_' + app.type, app.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue