Don't assume that widget IDs are unique (#8052)
* Don't assume that widget IDs are unique Signed-off-by: Robin Townsend <robin@robin.town> * Don't remove live tiles that don't exist Signed-off-by: Robin Townsend <robin@robin.town> * Add unit test for AppTile's live tile tracking Signed-off-by: Robin Townsend <robin@robin.town>
This commit is contained in:
parent
bc8fdac491
commit
744eeb53fe
13 changed files with 276 additions and 159 deletions
|
@ -29,7 +29,6 @@ import ActiveWidgetStore from "../stores/ActiveWidgetStore";
|
|||
import WidgetUtils from "../utils/WidgetUtils";
|
||||
import { WidgetType } from "../widgets/WidgetType";
|
||||
import { UPDATE_EVENT } from "./AsyncStore";
|
||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
|
||||
interface IState {}
|
||||
|
||||
|
@ -44,10 +43,6 @@ interface IRoomWidgets {
|
|||
widgets: IApp[];
|
||||
}
|
||||
|
||||
function widgetUid(app: IApp): string {
|
||||
return `${app.roomId ?? MatrixClientPeg.get().getUserId()}::${app.id}`;
|
||||
}
|
||||
|
||||
// TODO consolidate WidgetEchoStore into this
|
||||
// TODO consolidate ActiveWidgetStore into this
|
||||
export default class WidgetStore extends AsyncStoreWithClient<IState> {
|
||||
|
@ -119,13 +114,13 @@ export default class WidgetStore extends AsyncStoreWithClient<IState> {
|
|||
// otherwise we are out of sync with the rest of the app with stale widget events during removal
|
||||
Array.from(this.widgetMap.values()).forEach(app => {
|
||||
if (app.roomId !== room.roomId) return; // skip - wrong room
|
||||
this.widgetMap.delete(widgetUid(app));
|
||||
this.widgetMap.delete(WidgetUtils.getWidgetUid(app));
|
||||
});
|
||||
|
||||
let edited = false;
|
||||
this.generateApps(room).forEach(app => {
|
||||
// Sanity check for https://github.com/vector-im/element-web/issues/15705
|
||||
const existingApp = this.widgetMap.get(widgetUid(app));
|
||||
const existingApp = this.widgetMap.get(WidgetUtils.getWidgetUid(app));
|
||||
if (existingApp) {
|
||||
logger.warn(
|
||||
`Possible widget ID conflict for ${app.id} - wants to store in room ${app.roomId} ` +
|
||||
|
@ -133,7 +128,7 @@ export default class WidgetStore extends AsyncStoreWithClient<IState> {
|
|||
);
|
||||
}
|
||||
|
||||
this.widgetMap.set(widgetUid(app), app);
|
||||
this.widgetMap.set(WidgetUtils.getWidgetUid(app), app);
|
||||
roomInfo.widgets.push(app);
|
||||
edited = true;
|
||||
});
|
||||
|
@ -144,14 +139,13 @@ export default class WidgetStore extends AsyncStoreWithClient<IState> {
|
|||
// If a persistent widget is active, check to see if it's just been removed.
|
||||
// If it has, it needs to destroyed otherwise unmounting the node won't kill it
|
||||
const persistentWidgetId = ActiveWidgetStore.instance.getPersistentWidgetId();
|
||||
if (persistentWidgetId) {
|
||||
if (
|
||||
ActiveWidgetStore.instance.getRoomId(persistentWidgetId) === room.roomId &&
|
||||
!roomInfo.widgets.some(w => w.id === persistentWidgetId)
|
||||
) {
|
||||
logger.log(`Persistent widget ${persistentWidgetId} removed from room ${room.roomId}: destroying.`);
|
||||
ActiveWidgetStore.instance.destroyPersistentWidget(persistentWidgetId);
|
||||
}
|
||||
if (
|
||||
persistentWidgetId &&
|
||||
ActiveWidgetStore.instance.getPersistentRoomId() === room.roomId &&
|
||||
!roomInfo.widgets.some(w => w.id === persistentWidgetId)
|
||||
) {
|
||||
logger.log(`Persistent widget ${persistentWidgetId} removed from room ${room.roomId}: destroying.`);
|
||||
ActiveWidgetStore.instance.destroyPersistentWidget(persistentWidgetId, room.roomId);
|
||||
}
|
||||
|
||||
this.emit(room.roomId);
|
||||
|
@ -196,7 +190,7 @@ export default class WidgetStore extends AsyncStoreWithClient<IState> {
|
|||
|
||||
// A persistent conference widget indicates that we're participating
|
||||
const widgets = roomInfo.widgets.filter(w => WidgetType.JITSI.matches(w.type));
|
||||
return widgets.some(w => ActiveWidgetStore.instance.getWidgetPersistence(w.id));
|
||||
return widgets.some(w => ActiveWidgetStore.instance.getWidgetPersistence(w.id, room.roomId));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue