Add more types in WidgetEchoStore

This commit is contained in:
J. Ryan Stinnett 2021-04-26 15:38:43 +01:00
parent 82caac16c8
commit 25e4feeb38

View file

@ -16,6 +16,7 @@ limitations under the License.
import EventEmitter from 'events';
import { IWidget } from 'matrix-widget-api';
import MatrixEvent from "matrix-js-sdk/src/models/event";
import {WidgetType} from "../widgets/WidgetType";
/**
@ -36,7 +37,7 @@ class WidgetEchoStore extends EventEmitter {
// Map as below. Object is the content of the widget state event,
// so for widgets that have been deleted locally, the object is empty.
// roomId: {
// widgetId: [object]
// widgetId: IWidget
// }
};
}
@ -48,11 +49,11 @@ class WidgetEchoStore extends EventEmitter {
* and we don't really need the actual widget events anyway since we just want to
* show a spinner / prevent widgets being added twice.
*
* @param {Room} roomId The ID of the room to get widgets for
* @param {string} roomId The ID of the room to get widgets for
* @param {MatrixEvent[]} currentRoomWidgets Current widgets for the room
* @returns {MatrixEvent[]} List of widgets in the room, minus any pending removal
*/
getEchoedRoomWidgets(roomId, currentRoomWidgets) {
getEchoedRoomWidgets(roomId: string, currentRoomWidgets: MatrixEvent[]): MatrixEvent[] {
const echoedWidgets = [];
const roomEchoState = Object.assign({}, this.roomWidgetEcho[roomId]);
@ -71,7 +72,7 @@ class WidgetEchoStore extends EventEmitter {
return echoedWidgets;
}
roomHasPendingWidgetsOfType(roomId, currentRoomWidgets, type?: WidgetType) {
roomHasPendingWidgetsOfType(roomId: string, currentRoomWidgets: MatrixEvent[], type?: WidgetType): boolean {
const roomEchoState = Object.assign({}, this.roomWidgetEcho[roomId]);
// any widget IDs that are already in the room are not pending, so
@ -91,7 +92,7 @@ class WidgetEchoStore extends EventEmitter {
}
}
roomHasPendingWidgets(roomId, currentRoomWidgets) {
roomHasPendingWidgets(roomId: string, currentRoomWidgets: MatrixEvent[]): boolean {
return this.roomHasPendingWidgetsOfType(roomId, currentRoomWidgets);
}
@ -102,7 +103,7 @@ class WidgetEchoStore extends EventEmitter {
this.emit('update', roomId, widgetId);
}
removeRoomWidgetEcho(roomId, widgetId) {
removeRoomWidgetEcho(roomId: string, widgetId: string) {
delete this.roomWidgetEcho[roomId][widgetId];
if (Object.keys(this.roomWidgetEcho[roomId]).length === 0) delete this.roomWidgetEcho[roomId];
this.emit('update', roomId, widgetId);