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

Commit fbcea7d

Browse files
committed
Fix editing and redactions not updating the Reply Thread
Signed-off-by: Michael Telatynski <[email protected]>
1 parent 4f52afd commit fbcea7d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/components/views/elements/ReplyThread.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ export default class ReplyThread extends React.Component {
6262
err: false,
6363
};
6464

65+
this.unmounted = false;
66+
this.context.on("Event.replaced", this.onEventReplaced);
67+
this.room = this.context.getRoom(this.props.parentEv.getRoomId());
68+
this.room.on("Room.redaction", this.onRoomRedaction);
69+
this.room.on("Room.redactionCancelled", this.onRoomRedaction);
70+
6571
this.onQuoteClick = this.onQuoteClick.bind(this);
6672
this.canCollapse = this.canCollapse.bind(this);
6773
this.collapse = this.collapse.bind(this);
@@ -213,11 +219,6 @@ export default class ReplyThread extends React.Component {
213219
}
214220

215221
componentDidMount() {
216-
this.unmounted = false;
217-
this.room = this.context.getRoom(this.props.parentEv.getRoomId());
218-
this.room.on("Room.redaction", this.onRoomRedaction);
219-
// same event handler as Room.redaction as for both we just do forceUpdate
220-
this.room.on("Room.redactionCancelled", this.onRoomRedaction);
221222
this.initialize();
222223
}
223224

@@ -227,13 +228,14 @@ export default class ReplyThread extends React.Component {
227228

228229
componentWillUnmount() {
229230
this.unmounted = true;
231+
this.context.removeListener("Event.replaced", this.onEventReplaced);
230232
if (this.room) {
231233
this.room.removeListener("Room.redaction", this.onRoomRedaction);
232234
this.room.removeListener("Room.redactionCancelled", this.onRoomRedaction);
233235
}
234236
}
235237

236-
onRoomRedaction = (ev, room) => {
238+
onEventReplaced = (ev) => {
237239
if (this.unmounted) return;
238240

239241
// If one of the events we are rendering gets redacted, force a re-render
@@ -242,6 +244,18 @@ export default class ReplyThread extends React.Component {
242244
}
243245
};
244246

247+
onRoomRedaction = (ev) => {
248+
if (this.unmounted) return;
249+
250+
const eventId = ev.getAssociatedId();
251+
if (!eventId) return;
252+
253+
// If one of the events we are rendering gets redacted, force a re-render
254+
if (this.state.events.some(event => event.getId() === eventId)) {
255+
this.forceUpdate();
256+
}
257+
};
258+
245259
async initialize() {
246260
const {parentEv} = this.props;
247261
// at time of making this component we checked that props.parentEv has a parentEventId
@@ -368,6 +382,7 @@ export default class ReplyThread extends React.Component {
368382
isTwelveHour={SettingsStore.getValue("showTwelveHourTimestamps")}
369383
useIRCLayout={this.props.useIRCLayout}
370384
enableFlair={SettingsStore.getValue(UIFeature.Flair)}
385+
replacingEventId={ev.replacingEventId()}
371386
/>
372387
</blockquote>;
373388
});

src/components/views/rooms/EventTile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ export default class EventTile extends React.Component {
918918
highlights={this.props.highlights}
919919
highlightLink={this.props.highlightLink}
920920
onHeightChanged={this.props.onHeightChanged}
921+
replacingEventId={this.props.replacingEventId}
921922
showUrlPreview={false} />
922923
</div>
923924
</div>

0 commit comments

Comments
 (0)