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

Commit 430bceb

Browse files
authored
Merge pull request #5281 from matrix-org/t3chguy/fix/9836
Fix editing and redactions not updating the Reply Thread
2 parents 35c7ccf + 1bd0d9e commit 430bceb

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/components/views/elements/ReplyThread.js

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

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

219225
componentDidMount() {
220-
this.unmounted = false;
221-
this.room = this.context.getRoom(this.props.parentEv.getRoomId());
222-
this.room.on("Room.redaction", this.onRoomRedaction);
223-
// same event handler as Room.redaction as for both we just do forceUpdate
224-
this.room.on("Room.redactionCancelled", this.onRoomRedaction);
225226
this.initialize();
226227
}
227228

@@ -231,19 +232,34 @@ export default class ReplyThread extends React.Component {
231232

232233
componentWillUnmount() {
233234
this.unmounted = true;
235+
this.context.removeListener("Event.replaced", this.onEventReplaced);
234236
if (this.room) {
235237
this.room.removeListener("Room.redaction", this.onRoomRedaction);
236238
this.room.removeListener("Room.redactionCancelled", this.onRoomRedaction);
237239
}
238240
}
239241

240-
onRoomRedaction = (ev, room) => {
242+
updateForEventId = (eventId) => {
243+
if (this.state.events.some(event => event.getId() === eventId)) {
244+
this.forceUpdate();
245+
}
246+
};
247+
248+
onEventReplaced = (ev) => {
249+
if (this.unmounted) return;
250+
251+
// If one of the events we are rendering gets replaced, force a re-render
252+
this.updateForEventId(ev.getId());
253+
};
254+
255+
onRoomRedaction = (ev) => {
241256
if (this.unmounted) return;
242257

258+
const eventId = ev.getAssociatedId();
259+
if (!eventId) return;
260+
243261
// If one of the events we are rendering gets redacted, force a re-render
244-
if (this.state.events.some(event => event.getId() === ev.getId())) {
245-
this.forceUpdate();
246-
}
262+
this.updateForEventId(eventId);
247263
};
248264

249265
async initialize() {
@@ -372,6 +388,7 @@ export default class ReplyThread extends React.Component {
372388
isTwelveHour={SettingsStore.getValue("showTwelveHourTimestamps")}
373389
useIRCLayout={this.props.useIRCLayout}
374390
enableFlair={SettingsStore.getValue(UIFeature.Flair)}
391+
replacingEventId={ev.replacingEventId()}
375392
/>
376393
</blockquote>;
377394
});

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)