Listen to new thread to render info on timeline

This commit is contained in:
Germain Souquet 2021-10-15 11:08:33 +01:00
parent 17c4cc91af
commit 6baa6c8f65
2 changed files with 26 additions and 3 deletions

View file

@ -48,10 +48,8 @@ interface IProps {
}
interface IState {
replyToEvent?: MatrixEvent;
thread?: Thread;
editState?: EditorStateTransfer;
}
@replaceableComponent("structures.ThreadView")
@ -69,11 +67,16 @@ export default class ThreadView extends React.Component<IProps, IState> {
public componentDidMount(): void {
this.setupThread(this.props.mxEvent);
this.dispatcherRef = dis.register(this.onAction);
const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId());
room.on(ThreadEvent.New, this.onNewThread);
}
public componentWillUnmount(): void {
this.teardownThread();
dis.unregister(this.dispatcherRef);
const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId());
room.on(ThreadEvent.New, this.onNewThread);
}
public componentDidUpdate(prevProps) {
@ -135,11 +138,17 @@ export default class ThreadView extends React.Component<IProps, IState> {
}
};
private onNewThread = (thread: Thread) => {
if (thread.id === this.props.mxEvent.getId()) {
this.teardownThread();
this.setupThread(this.props.mxEvent);
}
};
private updateThread = (thread?: Thread) => {
if (thread) {
this.setState({
thread,
replyToEvent: thread.replyToEvent,
});
}