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

Commit

Permalink
Add new threads to the panel as they are discovered (#7688)
Browse files Browse the repository at this point in the history
  • Loading branch information
Germain authored Feb 1, 2022
1 parent afe6021 commit 5973d72
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/components/structures/ThreadPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
UNSTABLE_FILTER_RELATION_SENDERS,
UNSTABLE_FILTER_RELATION_TYPES,
} from 'matrix-js-sdk/src/filter';
import { ThreadEvent } from 'matrix-js-sdk/src/models/thread';
import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread';

import BaseCard from "../views/right_panel/BaseCard";
import ResizeNotifier from '../../utils/ResizeNotifier';
Expand Down Expand Up @@ -231,6 +231,35 @@ const ThreadPanel: React.FC<IProps> = ({ roomId, onClose, permalinkCreator }) =>
if (timelineSet) ref.current.refreshTimeline();
});

useEventEmitter(room, ThreadEvent.New, async (thread: Thread) => {
if (timelineSet) {
const capabilities = await mxClient.getCapabilities();
const serverSupportsThreads = capabilities['io.element.thread']?.enabled;

const discoveredScrollingBack = room.lastThread.rootEvent.localTimestamp < thread.rootEvent.localTimestamp;

// When the server support threads we're only interested in adding
// the newly created threads to the list.
// The ones discovered when scrolling back should be discarded as
// they will be discovered by the `/messages` filter
if (serverSupportsThreads) {
if (!discoveredScrollingBack) {
timelineSet.addEventToTimeline(
thread.rootEvent,
timelineSet.getLiveTimeline(),
false,
);
}
} else {
timelineSet.addEventToTimeline(
thread.rootEvent,
timelineSet.getLiveTimeline(),
!discoveredScrollingBack,
);
}
}
});

return (
<RoomContext.Provider value={{
...roomContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ exports[`PollCreateDialog renders a blank poll 1`] = `
"filteredTimelineSets": Object {},
"getTypeWarning": false,
"getVersionWarning": false,
"lastThread": undefined,
"membersPromise": Promise {},
"myUserId": "@name:example.com",
"name": "roomid",
Expand Down Expand Up @@ -256,6 +257,7 @@ exports[`PollCreateDialog renders a blank poll 1`] = `
"filteredTimelineSets": Object {},
"getTypeWarning": false,
"getVersionWarning": false,
"lastThread": undefined,
"membersPromise": Promise {},
"myUserId": "@name:example.com",
"name": "roomid",
Expand Down Expand Up @@ -1157,6 +1159,7 @@ exports[`PollCreateDialog renders a question and some options 1`] = `
"filteredTimelineSets": Object {},
"getTypeWarning": false,
"getVersionWarning": false,
"lastThread": undefined,
"membersPromise": Promise {},
"myUserId": "@name:example.com",
"name": "roomid",
Expand Down Expand Up @@ -1377,6 +1380,7 @@ exports[`PollCreateDialog renders a question and some options 1`] = `
"filteredTimelineSets": Object {},
"getTypeWarning": false,
"getVersionWarning": false,
"lastThread": undefined,
"membersPromise": Promise {},
"myUserId": "@name:example.com",
"name": "roomid",
Expand Down

0 comments on commit 5973d72

Please sign in to comment.