From e2fb9b3ae878fcf68f1b4dd72b3badf16e0b2e13 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 24 Feb 2021 18:10:35 -0700 Subject: [PATCH 1/2] Clean up widgets when leaving the room --- .../views/elements/PersistentApp.js | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/components/views/elements/PersistentApp.js b/src/components/views/elements/PersistentApp.js index a1e805c085..eb5f4eab7d 100644 --- a/src/components/views/elements/PersistentApp.js +++ b/src/components/views/elements/PersistentApp.js @@ -31,6 +31,7 @@ export default class PersistentApp extends React.Component { componentDidMount() { this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate); ActiveWidgetStore.on('update', this._onActiveWidgetStoreUpdate); + MatrixClientPeg.get().on("Room.myMembership", this._onMyMembership); } componentWillUnmount() { @@ -38,6 +39,9 @@ export default class PersistentApp extends React.Component { this._roomStoreToken.remove(); } ActiveWidgetStore.removeListener('update', this._onActiveWidgetStoreUpdate); + if (MatrixClientPeg.get()) { + MatrixClientPeg.get().removeListener("Room.myMembership", this._onMyMembership); + } } _onRoomViewStoreUpdate = payload => { @@ -53,16 +57,28 @@ export default class PersistentApp extends React.Component { }); }; + _onMyMembership = async (room) => { + const persistentWidgetInRoomId = ActiveWidgetStore.getRoomId(this.state.persistentWidgetId); + if (room.getMyMembership() !== "join") { + // we're not in the room anymore - delete + if (room.roomId === persistentWidgetInRoomId) { + ActiveWidgetStore.destroyPersistentWidget(this.state.persistentWidgetId); + } + } + }; + render() { if (this.state.persistentWidgetId) { const persistentWidgetInRoomId = ActiveWidgetStore.getRoomId(this.state.persistentWidgetId); - if (this.state.roomId !== persistentWidgetInRoomId) { - const persistentWidgetInRoom = MatrixClientPeg.get().getRoom(persistentWidgetInRoomId); - // Sanity check the room - the widget may have been destroyed between render cycles, and - // thus no room is associated anymore. - if (!persistentWidgetInRoom) return null; + const persistentWidgetInRoom = MatrixClientPeg.get().getRoom(persistentWidgetInRoomId); + // Sanity check the room - the widget may have been destroyed between render cycles, and + // thus no room is associated anymore. + if (!persistentWidgetInRoom) return null; + + const myMembership = persistentWidgetInRoom.getMyMembership(); + if (this.state.roomId !== persistentWidgetInRoomId && myMembership === "join") { // get the widget data const appEvent = WidgetUtils.getRoomWidgets(persistentWidgetInRoom).find((ev) => { return ev.getStateKey() === ActiveWidgetStore.getPersistentWidgetId(); From fbe5d177851ce836ca33afb09ab981511e4c87b3 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 24 Feb 2021 18:27:59 -0700 Subject: [PATCH 2/2] sanity --- src/components/views/elements/PersistentApp.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/views/elements/PersistentApp.js b/src/components/views/elements/PersistentApp.js index eb5f4eab7d..7801076c66 100644 --- a/src/components/views/elements/PersistentApp.js +++ b/src/components/views/elements/PersistentApp.js @@ -57,9 +57,9 @@ export default class PersistentApp extends React.Component { }); }; - _onMyMembership = async (room) => { + _onMyMembership = async (room, membership) => { const persistentWidgetInRoomId = ActiveWidgetStore.getRoomId(this.state.persistentWidgetId); - if (room.getMyMembership() !== "join") { + if (membership !== "join") { // we're not in the room anymore - delete if (room.roomId === persistentWidgetInRoomId) { ActiveWidgetStore.destroyPersistentWidget(this.state.persistentWidgetId);