Implement reply chain fallback for threads backwards compatibility (#7565)

This commit is contained in:
Germain 2022-01-19 09:06:48 +00:00 committed by GitHub
parent a00d359422
commit 41b9e4aa4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 87 additions and 40 deletions

View file

@ -55,6 +55,7 @@ interface IProps {
}
interface IState {
thread?: Thread;
lastThreadReply?: MatrixEvent;
layout: Layout;
editState?: EditorStateTransfer;
replyToEvent?: MatrixEvent;
@ -142,14 +143,14 @@ export default class ThreadView extends React.Component<IProps, IState> {
if (!thread) {
thread = this.props.room.createThread([mxEv]);
}
thread.on(ThreadEvent.Update, this.updateThread);
thread.on(ThreadEvent.Update, this.updateLastThreadReply);
thread.once(ThreadEvent.Ready, this.updateThread);
this.updateThread(thread);
};
private teardownThread = () => {
if (this.state.thread) {
this.state.thread.removeListener(ThreadEvent.Update, this.updateThread);
this.state.thread.removeListener(ThreadEvent.Update, this.updateLastThreadReply);
this.state.thread.removeListener(ThreadEvent.Ready, this.updateThread);
}
};
@ -165,6 +166,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
if (thread && this.state.thread !== thread) {
this.setState({
thread,
lastThreadReply: thread.lastReply,
}, () => {
thread.emit(ThreadEvent.ViewThread);
this.timelinePanelRef.current?.refreshTimeline();
@ -172,6 +174,14 @@ export default class ThreadView extends React.Component<IProps, IState> {
}
};
private updateLastThreadReply = () => {
if (this.state.thread) {
this.setState({
lastThreadReply: this.state.thread.lastReply,
});
}
};
private onScroll = (): void => {
if (this.props.initialEvent && this.props.isInitialEventHighlighted) {
dis.dispatch({
@ -199,8 +209,11 @@ export default class ThreadView extends React.Component<IProps, IState> {
: null;
const threadRelation: IEventRelation = {
rel_type: RelationType.Thread,
event_id: this.state.thread?.id,
"rel_type": RelationType.Thread,
"event_id": this.state.thread?.id,
"m.in_reply_to": {
"event_id": this.state.lastThreadReply?.getId(),
},
};
const messagePanelClassNames = classNames(