diff --git a/src/components/structures/ThreadPanel.tsx b/src/components/structures/ThreadPanel.tsx index 37a4122015..a452ee630a 100644 --- a/src/components/structures/ThreadPanel.tsx +++ b/src/components/structures/ThreadPanel.tsx @@ -22,8 +22,8 @@ import { MatrixClient } from 'matrix-js-sdk/src/client'; import { Filter, IFilterDefinition, - UNSTABLE_FILTER_RELATION_SENDERS, - UNSTABLE_FILTER_RELATION_TYPES, + UNSTABLE_FILTER_RELATED_BY_SENDERS, + UNSTABLE_FILTER_RELATED_BY_REL_TYPES, } from 'matrix-js-sdk/src/filter'; import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread'; @@ -46,23 +46,20 @@ export async function getThreadTimelineSet( room: Room, filterType = ThreadFilterType.All, ): Promise { - const capabilities = await client.getCapabilities(); - const serverSupportsThreads = capabilities['io.element.thread']?.enabled; - - if (serverSupportsThreads) { + if (Thread.hasServerSideSupport) { const myUserId = client.getUserId(); const filter = new Filter(myUserId); const definition: IFilterDefinition = { "room": { "timeline": { - [UNSTABLE_FILTER_RELATION_TYPES.name]: [RelationType.Thread], + [UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: [RelationType.Thread], }, }, }; if (filterType === ThreadFilterType.My) { - definition.room.timeline[UNSTABLE_FILTER_RELATION_SENDERS.name] = [myUserId]; + definition.room.timeline[UNSTABLE_FILTER_RELATED_BY_SENDERS.name] = [myUserId]; } filter.setDefinition(definition); @@ -241,9 +238,6 @@ const ThreadPanel: React.FC = ({ roomId, onClose, permalinkCreator }) => async function onNewThread(thread: Thread): Promise { setThreadCount(room.threads.size); if (timelineSet) { - const capabilities = await mxClient.getCapabilities(); - const serverSupportsThreads = capabilities['io.element.thread']?.enabled; - const discoveredScrollingBack = room.lastThread.rootEvent.localTimestamp < thread.rootEvent.localTimestamp; @@ -251,7 +245,7 @@ const ThreadPanel: React.FC = ({ roomId, onClose, permalinkCreator }) => // 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 (Thread.hasServerSideSupport) { if (!discoveredScrollingBack) { timelineSet.addEventToTimeline( thread.rootEvent, diff --git a/src/components/structures/ThreadView.tsx b/src/components/structures/ThreadView.tsx index bc8789b11a..c5d404a901 100644 --- a/src/components/structures/ThreadView.tsx +++ b/src/components/structures/ThreadView.tsx @@ -246,7 +246,7 @@ export default class ThreadView extends React.Component { direction = Direction.Backward, limit = 20, ): Promise => { - if (!this.state.thread.hasServerSideSupport) { + if (!Thread.hasServerSideSupport) { return false; } diff --git a/test/components/structures/ThreadPanel-test.tsx b/test/components/structures/ThreadPanel-test.tsx index bf9de71a75..7f735171d7 100644 --- a/test/components/structures/ThreadPanel-test.tsx +++ b/test/components/structures/ThreadPanel-test.tsx @@ -20,11 +20,12 @@ import { MatrixClient, RelationType, Room, - UNSTABLE_FILTER_RELATION_SENDERS, - UNSTABLE_FILTER_RELATION_TYPES, + UNSTABLE_FILTER_RELATED_BY_REL_TYPES, + UNSTABLE_FILTER_RELATED_BY_SENDERS, } from 'matrix-js-sdk/src/matrix'; import { mocked } from 'jest-mock'; import '../../skinned-sdk'; +import { Thread } from 'matrix-js-sdk/src/models/thread'; import { ThreadFilterType, @@ -94,7 +95,7 @@ describe('ThreadPanel', () => { const filterId = '123'; const client = { getUserId: jest.fn(), - getCapabilities: jest.fn().mockResolvedValue({}), + doesServerSupportUnstableFeature: jest.fn().mockResolvedValue(false), decryptEventIfNeeded: jest.fn().mockResolvedValue(undefined), getOrCreateFilter: jest.fn().mockResolvedValue(filterId), paginateEventTimeline: jest.fn().mockResolvedValue(undefined), @@ -128,7 +129,7 @@ describe('ThreadPanel', () => { beforeEach(() => { mocked(client.getUserId).mockReturnValue(aliceId); - mocked(client.getCapabilities).mockResolvedValue({}); + mocked(client.doesServerSupportUnstableFeature).mockResolvedValue(false); }); describe('when extra capabilities are not enabled on server', () => { @@ -168,9 +169,8 @@ describe('ThreadPanel', () => { describe('when extra capabilities are enabled on server', () => { beforeEach(() => { jest.clearAllMocks(); - mocked(client.getCapabilities).mockResolvedValue({ - ['io.element.thread']: { enabled: true }, - }); + Thread.hasServerSideSupport = true; + mocked(client.doesServerSupportUnstableFeature).mockResolvedValue(true); }); it('creates a filter with correct definition when filterType is All', async () => { @@ -179,7 +179,7 @@ describe('ThreadPanel', () => { const [filterKey, filter] = mocked(client).getOrCreateFilter.mock.calls[0]; expect(filterKey).toEqual(`THREAD_PANEL_${room.roomId}_${ThreadFilterType.All}`); expect(filter.getDefinition().room.timeline).toEqual({ - [UNSTABLE_FILTER_RELATION_TYPES.name]: [RelationType.Thread], + [UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: [RelationType.Thread], }); }); @@ -189,8 +189,8 @@ describe('ThreadPanel', () => { const [filterKey, filter] = mocked(client).getOrCreateFilter.mock.calls[0]; expect(filterKey).toEqual(`THREAD_PANEL_${room.roomId}_${ThreadFilterType.My}`); expect(filter.getDefinition().room.timeline).toEqual({ - [UNSTABLE_FILTER_RELATION_TYPES.name]: [RelationType.Thread], - [UNSTABLE_FILTER_RELATION_SENDERS.name]: [aliceId], + [UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: [RelationType.Thread], + [UNSTABLE_FILTER_RELATED_BY_SENDERS.name]: [aliceId], }); }); });