Add more types in WidgetEchoStore
This commit is contained in:
parent
82caac16c8
commit
25e4feeb38
1 changed files with 7 additions and 6 deletions
|
@ -16,6 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
import { IWidget } from 'matrix-widget-api';
|
import { IWidget } from 'matrix-widget-api';
|
||||||
|
import MatrixEvent from "matrix-js-sdk/src/models/event";
|
||||||
import {WidgetType} from "../widgets/WidgetType";
|
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,
|
// Map as below. Object is the content of the widget state event,
|
||||||
// so for widgets that have been deleted locally, the object is empty.
|
// so for widgets that have been deleted locally, the object is empty.
|
||||||
// roomId: {
|
// 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
|
* and we don't really need the actual widget events anyway since we just want to
|
||||||
* show a spinner / prevent widgets being added twice.
|
* 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
|
* @param {MatrixEvent[]} currentRoomWidgets Current widgets for the room
|
||||||
* @returns {MatrixEvent[]} List of widgets in the room, minus any pending removal
|
* @returns {MatrixEvent[]} List of widgets in the room, minus any pending removal
|
||||||
*/
|
*/
|
||||||
getEchoedRoomWidgets(roomId, currentRoomWidgets) {
|
getEchoedRoomWidgets(roomId: string, currentRoomWidgets: MatrixEvent[]): MatrixEvent[] {
|
||||||
const echoedWidgets = [];
|
const echoedWidgets = [];
|
||||||
|
|
||||||
const roomEchoState = Object.assign({}, this.roomWidgetEcho[roomId]);
|
const roomEchoState = Object.assign({}, this.roomWidgetEcho[roomId]);
|
||||||
|
@ -71,7 +72,7 @@ class WidgetEchoStore extends EventEmitter {
|
||||||
return echoedWidgets;
|
return echoedWidgets;
|
||||||
}
|
}
|
||||||
|
|
||||||
roomHasPendingWidgetsOfType(roomId, currentRoomWidgets, type?: WidgetType) {
|
roomHasPendingWidgetsOfType(roomId: string, currentRoomWidgets: MatrixEvent[], type?: WidgetType): boolean {
|
||||||
const roomEchoState = Object.assign({}, this.roomWidgetEcho[roomId]);
|
const roomEchoState = Object.assign({}, this.roomWidgetEcho[roomId]);
|
||||||
|
|
||||||
// any widget IDs that are already in the room are not pending, so
|
// 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);
|
return this.roomHasPendingWidgetsOfType(roomId, currentRoomWidgets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +103,7 @@ class WidgetEchoStore extends EventEmitter {
|
||||||
this.emit('update', roomId, widgetId);
|
this.emit('update', roomId, widgetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeRoomWidgetEcho(roomId, widgetId) {
|
removeRoomWidgetEcho(roomId: string, widgetId: string) {
|
||||||
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', roomId, widgetId);
|
this.emit('update', roomId, widgetId);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue