Just pass the roomId into WidgetEchoStore

pull/21833/head
David Baker 2018-07-05 18:43:20 +01:00
parent 5f2e2efce6
commit eb552e5cef
5 changed files with 20 additions and 20 deletions

View File

@ -416,7 +416,7 @@ function _startCallApp(roomId, type) {
const currentRoomWidgets = WidgetUtils.getRoomWidgets(room); const currentRoomWidgets = WidgetUtils.getRoomWidgets(room);
if (WidgetEchoStore.roomHasPendingWidgetsOfType(room, currentRoomWidgets, 'jitsi')) { if (WidgetEchoStore.roomHasPendingWidgetsOfType(roomId, currentRoomWidgets, 'jitsi')) {
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createTrackedDialog('Already have pending Jitsi Widget', '', ErrorDialog, { Modal.createTrackedDialog('Already have pending Jitsi Widget', '', ErrorDialog, {

View File

@ -328,9 +328,9 @@ module.exports = React.createClass({
return false; return false;
} }
const widgets = WidgetEchoStore.getEchoedRoomWidgets(room, WidgetUtils.getRoomWidgets(room)); const widgets = WidgetEchoStore.getEchoedRoomWidgets(room.roomId, WidgetUtils.getRoomWidgets(room));
return widgets.length > 0 || WidgetEchoStore.roomHasPendingWidgets(room, WidgetUtils.getRoomWidgets(room)); return widgets.length > 0 || WidgetEchoStore.roomHasPendingWidgets(room.roomId, WidgetUtils.getRoomWidgets(room));
}, },
componentDidMount: function() { componentDidMount: function() {

View File

@ -167,7 +167,7 @@ module.exports = React.createClass({
_getApps: function() { _getApps: function() {
const widgets = WidgetEchoStore.getEchoedRoomWidgets( const widgets = WidgetEchoStore.getEchoedRoomWidgets(
this.props.room, WidgetUtils.getRoomWidgets(this.props.room), this.props.room.roomId, WidgetUtils.getRoomWidgets(this.props.room),
); );
return widgets.map((ev) => { return widgets.map((ev) => {
return this._initAppConfig(ev.getStateKey(), ev.getContent(), ev.sender); return this._initAppConfig(ev.getStateKey(), ev.getContent(), ev.sender);
@ -260,7 +260,7 @@ module.exports = React.createClass({
let spinner; let spinner;
if ( if (
apps.length === 0 && WidgetEchoStore.roomHasPendingWidgets( apps.length === 0 && WidgetEchoStore.roomHasPendingWidgets(
this.props.room, this.props.room.roomId,
WidgetUtils.getRoomWidgets(this.props.room), WidgetUtils.getRoomWidgets(this.props.room),
) )
) { ) {

View File

@ -38,14 +38,14 @@ 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} room The room object to get widgets for * @param {Room} 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(room, currentRoomWidgets) { getEchoedRoomWidgets(roomId, currentRoomWidgets) {
const echoedWidgets = []; const echoedWidgets = [];
const roomEchoState = Object.assign({}, this._roomWidgetEcho[room.roomId]); const roomEchoState = Object.assign({}, this._roomWidgetEcho[roomId]);
for (const w of currentRoomWidgets) { for (const w of currentRoomWidgets) {
const widgetId = w.getStateKey(); const widgetId = w.getStateKey();
@ -70,8 +70,8 @@ class WidgetEchoStore extends EventEmitter {
return echoedWidgets; return echoedWidgets;
} }
roomHasPendingWidgetsOfType(room, currentRoomWidgets, type) { roomHasPendingWidgetsOfType(roomId, currentRoomWidgets, type) {
const roomEchoState = Object.assign({}, this._roomWidgetEcho[room.roomId]); const roomEchoState = Object.assign({}, this._roomWidgetEcho[roomId]);
if (roomEchoState === undefined) return false; if (roomEchoState === undefined) return false;
for (const w of currentRoomWidgets) { for (const w of currentRoomWidgets) {
@ -88,20 +88,20 @@ class WidgetEchoStore extends EventEmitter {
} }
} }
roomHasPendingWidgets(room, currentRoomWidgets) { roomHasPendingWidgets(roomId, currentRoomWidgets) {
return this.roomHasPendingWidgetsOfType(room, currentRoomWidgets); return this.roomHasPendingWidgetsOfType(roomId, currentRoomWidgets);
} }
setRoomWidgetEcho(room, widgetId, state) { setRoomWidgetEcho(roomId, widgetId, state) {
if (this._roomWidgetEcho[room.roomId] === undefined) this._roomWidgetEcho[room.roomId] = {}; if (this._roomWidgetEcho[roomId] === undefined) this._roomWidgetEcho[roomId] = {};
this._roomWidgetEcho[room.roomId][widgetId] = state; this._roomWidgetEcho[roomId][widgetId] = state;
this.emit('updateRoomWidgetEcho'); this.emit('updateRoomWidgetEcho');
} }
removeRoomWidgetEcho(room, widgetId) { removeRoomWidgetEcho(roomId, widgetId) {
delete this._roomWidgetEcho[room.roomId][widgetId]; delete this._roomWidgetEcho[roomId][widgetId];
if (this._roomWidgetEcho[room.roomId] === {}) delete this._roomWidgetEcho[room.roomId]; if (this._roomWidgetEcho[roomId] === {}) delete this._roomWidgetEcho[roomId];
this.emit('updateRoomWidgetEcho'); this.emit('updateRoomWidgetEcho');
} }
} }

View File

@ -255,7 +255,7 @@ export default class WidgetUtils {
} }
const room = MatrixClientPeg.get().getRoom(roomId); const room = MatrixClientPeg.get().getRoom(roomId);
WidgetEchoStore.setRoomWidgetEcho(room, widgetId, content); WidgetEchoStore.setRoomWidgetEcho(roomId, widgetId, content);
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
// TODO - Room widgets need to be moved to 'm.widget' state events // TODO - Room widgets need to be moved to 'm.widget' state events
@ -263,7 +263,7 @@ export default class WidgetUtils {
return client.sendStateEvent(roomId, "im.vector.modular.widgets", content, widgetId).then(() => { return client.sendStateEvent(roomId, "im.vector.modular.widgets", content, widgetId).then(() => {
return WidgetUtils.waitForRoomWidget(widgetId, roomId, addingWidget); return WidgetUtils.waitForRoomWidget(widgetId, roomId, addingWidget);
}).finally(() => { }).finally(() => {
WidgetEchoStore.removeRoomWidgetEcho(room, widgetId); WidgetEchoStore.removeRoomWidgetEcho(roomId, widgetId);
}); });
} }