[Update thread info after MSC3440 updates] (#7911)

pull/21833/head
Germain 2022-03-02 10:52:14 +00:00 committed by GitHub
parent 3a82163127
commit d01ea1824b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 23 deletions

View File

@ -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<EventTimelineSet> {
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<IProps> = ({ roomId, onClose, permalinkCreator }) =>
async function onNewThread(thread: Thread): Promise<void> {
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<IProps> = ({ 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,

View File

@ -246,7 +246,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
direction = Direction.Backward,
limit = 20,
): Promise<boolean> => {
if (!this.state.thread.hasServerSideSupport) {
if (!Thread.hasServerSideSupport) {
return false;
}

View File

@ -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],
});
});
});