Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit ca4e720

Browse files
authored
Merge pull request #5350 from matrix-org/t3chguy/fix/widgets
Widgets fixes
2 parents 25c9b26 + 5f2058a commit ca4e720

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/components/views/elements/PersistedElement.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {throttle} from "lodash";
2121
import ResizeObserver from 'resize-observer-polyfill';
2222

2323
import dis from '../../../dispatcher/dispatcher';
24+
import MatrixClientContext from "../../../contexts/MatrixClientContext";
25+
import {MatrixClientPeg} from "../../../MatrixClientPeg";
2426

2527
// Shamelessly ripped off Modal.js. There's probably a better way
2628
// of doing reusable widgets like dialog boxes & menus where we go and
@@ -144,9 +146,11 @@ export default class PersistedElement extends React.Component {
144146
}
145147

146148
renderApp() {
147-
const content = <div ref={this.collectChild} style={this.props.style}>
148-
{this.props.children}
149-
</div>;
149+
const content = <MatrixClientContext.Provider value={MatrixClientPeg.get()}>
150+
<div ref={this.collectChild} style={this.props.style}>
151+
{this.props.children}
152+
</div>
153+
</MatrixClientContext.Provider>;
150154

151155
ReactDOM.render(content, getOrCreateContainer('mx_persistedElement_'+this.props.persistKey));
152156
}

src/components/views/right_panel/RoomSummaryCard.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {SetRightPanelPhasePayload} from "../../../dispatcher/payloads/SetRightPa
3131
import Modal from "../../../Modal";
3232
import ShareDialog from '../dialogs/ShareDialog';
3333
import {useEventEmitter} from "../../../hooks/useEventEmitter";
34-
import WidgetEchoStore from "../../../stores/WidgetEchoStore";
3534
import WidgetUtils from "../../../utils/WidgetUtils";
3635
import {IntegrationManagers} from "../../../integrations/IntegrationManagers";
3736
import SettingsStore from "../../../settings/SettingsStore";
@@ -77,7 +76,6 @@ export const useWidgets = (room: Room) => {
7776
}, [room]);
7877

7978
useEffect(updateApps, [room]);
80-
useEventEmitter(WidgetEchoStore, "update", updateApps);
8179
useEventEmitter(WidgetStore.instance, room.roomId, updateApps);
8280

8381
return apps;

src/stores/WidgetEchoStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class WidgetEchoStore extends EventEmitter {
5555
const widgetId = w.getStateKey();
5656
// If there's no echo, or the echo still has a widget present, show the *old* widget
5757
// we don't include widgets that have changed for the same reason we don't include new ones,
58-
// ie. we'd need to fake matrix events to do so and therte's currently no need.
58+
// ie. we'd need to fake matrix events to do so and there's currently no need.
5959
if (!roomEchoState[widgetId] || Object.keys(roomEchoState[widgetId]).length !== 0) {
6060
echoedWidgets.push(w);
6161
}

src/stores/WidgetStore.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ export default class WidgetStore extends AsyncStoreWithClient<IState> {
122122
if (!room) return;
123123
const roomInfo = this.roomMap.get(room.roomId);
124124
roomInfo.widgets = [];
125+
126+
// first clean out old widgets from the map which originate from this room
127+
// otherwise we are out of sync with the rest of the app with stale widget events during removal
128+
Array.from(this.widgetMap.values()).forEach(app => {
129+
if (app.roomId === room.roomId) {
130+
this.widgetMap.delete(app.id);
131+
}
132+
});
133+
125134
this.generateApps(room).forEach(app => {
126135
this.widgetMap.set(app.id, app);
127136
roomInfo.widgets.push(app);

0 commit comments

Comments
 (0)