Merge pull request #6952 from matrix-org/gsouquet/display-new-thread
This commit is contained in:
commit
3ec05c9cbd
2 changed files with 26 additions and 3 deletions
|
@ -48,10 +48,8 @@ interface IProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
replyToEvent?: MatrixEvent;
|
|
||||||
thread?: Thread;
|
thread?: Thread;
|
||||||
editState?: EditorStateTransfer;
|
editState?: EditorStateTransfer;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@replaceableComponent("structures.ThreadView")
|
@replaceableComponent("structures.ThreadView")
|
||||||
|
@ -69,11 +67,16 @@ export default class ThreadView extends React.Component<IProps, IState> {
|
||||||
public componentDidMount(): void {
|
public componentDidMount(): void {
|
||||||
this.setupThread(this.props.mxEvent);
|
this.setupThread(this.props.mxEvent);
|
||||||
this.dispatcherRef = dis.register(this.onAction);
|
this.dispatcherRef = dis.register(this.onAction);
|
||||||
|
|
||||||
|
const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId());
|
||||||
|
room.on(ThreadEvent.New, this.onNewThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount(): void {
|
public componentWillUnmount(): void {
|
||||||
this.teardownThread();
|
this.teardownThread();
|
||||||
dis.unregister(this.dispatcherRef);
|
dis.unregister(this.dispatcherRef);
|
||||||
|
const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId());
|
||||||
|
room.on(ThreadEvent.New, this.onNewThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidUpdate(prevProps) {
|
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) => {
|
private updateThread = (thread?: Thread) => {
|
||||||
if (thread) {
|
if (thread) {
|
||||||
this.setState({
|
this.setState({
|
||||||
thread,
|
thread,
|
||||||
replyToEvent: thread.replyToEvent,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -475,6 +475,9 @@ export default class EventTile extends React.Component<IProps, IState> {
|
||||||
this.props.mxEvent.once(ThreadEvent.Ready, this.updateThread);
|
this.props.mxEvent.once(ThreadEvent.Ready, this.updateThread);
|
||||||
this.props.mxEvent.on(ThreadEvent.Update, this.updateThread);
|
this.props.mxEvent.on(ThreadEvent.Update, this.updateThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const room = this.context.getRoom(this.props.mxEvent.getRoomId());
|
||||||
|
room.on(ThreadEvent.New, this.onNewThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateThread = (thread) => {
|
private updateThread = (thread) => {
|
||||||
|
@ -516,6 +519,9 @@ export default class EventTile extends React.Component<IProps, IState> {
|
||||||
this.props.mxEvent.off(ThreadEvent.Ready, this.updateThread);
|
this.props.mxEvent.off(ThreadEvent.Ready, this.updateThread);
|
||||||
this.props.mxEvent.off(ThreadEvent.Update, this.updateThread);
|
this.props.mxEvent.off(ThreadEvent.Update, this.updateThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const room = this.context.getRoom(this.props.mxEvent.getRoomId());
|
||||||
|
room.off(ThreadEvent.New, this.onNewThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps, prevState, snapshot) {
|
componentDidUpdate(prevProps, prevState, snapshot) {
|
||||||
|
@ -526,6 +532,14 @@ export default class EventTile extends React.Component<IProps, IState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private onNewThread = (thread: Thread) => {
|
||||||
|
if (thread.id === this.props.mxEvent.getId()) {
|
||||||
|
this.updateThread(thread);
|
||||||
|
const room = this.context.getRoom(this.props.mxEvent.getRoomId());
|
||||||
|
room.off(ThreadEvent.New, this.onNewThread);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private renderThreadInfo(): React.ReactNode {
|
private renderThreadInfo(): React.ReactNode {
|
||||||
if (!SettingsStore.getValue("feature_thread")) {
|
if (!SettingsStore.getValue("feature_thread")) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue