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

Fix incorrect logic to hide thread relations #6951

Merged
merged 6 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/structures/MessagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {

// Checking if the message has a "parentEventId" as we do not
// want to hide the root event of the thread
if (mxEv.isThreadRoot && this.props.hideThreadedMessages
if (mxEv.isThreadRelation && this.props.hideThreadedMessages
&& SettingsStore.getValue("feature_thread")) {
return false;
}
Expand Down
15 changes: 12 additions & 3 deletions src/components/structures/ThreadView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ interface IProps {
}

interface IState {
replyToEvent?: MatrixEvent;
thread?: Thread;
editState?: EditorStateTransfer;

}

@replaceableComponent("structures.ThreadView")
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
});
}

Expand Down
28 changes: 27 additions & 1 deletion src/components/views/rooms/EventTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@ export default class EventTile extends React.Component<IProps, IState> {
this.props.mxEvent.once(ThreadEvent.Ready, 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) => {
Expand Down Expand Up @@ -517,6 +520,9 @@ export default class EventTile extends React.Component<IProps, IState> {
this.props.mxEvent.off(ThreadEvent.Ready, 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) {
Expand All @@ -527,12 +533,32 @@ 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 {
if (!SettingsStore.getValue("feature_thread")) {
return null;
}

const thread = this.state.thread;
/**
* Accessing the threads value through the room due to a race condition
* that will be solved when there are proper backend support for threads
* We currently have no reliable way to discover than an event is a thread
* when we are at the sync stage
*/
const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId());
const thread = room.threads.get(this.props.mxEvent.getId());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth a comment on why this.state.thread isn't the right thing here?


if (thread && !thread.ready) {
thread.addEvent(this.props.mxEvent, true);
}

if (!thread || this.props.showThreadInfo === false || thread.length <= 1) {
return null;
}
Expand Down