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

This commit is contained in:
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 { import {
Filter, Filter,
IFilterDefinition, IFilterDefinition,
UNSTABLE_FILTER_RELATION_SENDERS, UNSTABLE_FILTER_RELATED_BY_SENDERS,
UNSTABLE_FILTER_RELATION_TYPES, UNSTABLE_FILTER_RELATED_BY_REL_TYPES,
} from 'matrix-js-sdk/src/filter'; } from 'matrix-js-sdk/src/filter';
import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread'; import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread';
@ -46,23 +46,20 @@ export async function getThreadTimelineSet(
room: Room, room: Room,
filterType = ThreadFilterType.All, filterType = ThreadFilterType.All,
): Promise<EventTimelineSet> { ): Promise<EventTimelineSet> {
const capabilities = await client.getCapabilities(); if (Thread.hasServerSideSupport) {
const serverSupportsThreads = capabilities['io.element.thread']?.enabled;
if (serverSupportsThreads) {
const myUserId = client.getUserId(); const myUserId = client.getUserId();
const filter = new Filter(myUserId); const filter = new Filter(myUserId);
const definition: IFilterDefinition = { const definition: IFilterDefinition = {
"room": { "room": {
"timeline": { "timeline": {
[UNSTABLE_FILTER_RELATION_TYPES.name]: [RelationType.Thread], [UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: [RelationType.Thread],
}, },
}, },
}; };
if (filterType === ThreadFilterType.My) { 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); filter.setDefinition(definition);
@ -241,9 +238,6 @@ const ThreadPanel: React.FC<IProps> = ({ roomId, onClose, permalinkCreator }) =>
async function onNewThread(thread: Thread): Promise<void> { async function onNewThread(thread: Thread): Promise<void> {
setThreadCount(room.threads.size); setThreadCount(room.threads.size);
if (timelineSet) { if (timelineSet) {
const capabilities = await mxClient.getCapabilities();
const serverSupportsThreads = capabilities['io.element.thread']?.enabled;
const discoveredScrollingBack = const discoveredScrollingBack =
room.lastThread.rootEvent.localTimestamp < thread.rootEvent.localTimestamp; 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 newly created threads to the list.
// The ones discovered when scrolling back should be discarded as // The ones discovered when scrolling back should be discarded as
// they will be discovered by the `/messages` filter // they will be discovered by the `/messages` filter
if (serverSupportsThreads) { if (Thread.hasServerSideSupport) {
if (!discoveredScrollingBack) { if (!discoveredScrollingBack) {
timelineSet.addEventToTimeline( timelineSet.addEventToTimeline(
thread.rootEvent, thread.rootEvent,

View file

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

View file

@ -20,11 +20,12 @@ import {
MatrixClient, MatrixClient,
RelationType, RelationType,
Room, Room,
UNSTABLE_FILTER_RELATION_SENDERS, UNSTABLE_FILTER_RELATED_BY_REL_TYPES,
UNSTABLE_FILTER_RELATION_TYPES, UNSTABLE_FILTER_RELATED_BY_SENDERS,
} from 'matrix-js-sdk/src/matrix'; } from 'matrix-js-sdk/src/matrix';
import { mocked } from 'jest-mock'; import { mocked } from 'jest-mock';
import '../../skinned-sdk'; import '../../skinned-sdk';
import { Thread } from 'matrix-js-sdk/src/models/thread';
import { import {
ThreadFilterType, ThreadFilterType,
@ -94,7 +95,7 @@ describe('ThreadPanel', () => {
const filterId = '123'; const filterId = '123';
const client = { const client = {
getUserId: jest.fn(), getUserId: jest.fn(),
getCapabilities: jest.fn().mockResolvedValue({}), doesServerSupportUnstableFeature: jest.fn().mockResolvedValue(false),
decryptEventIfNeeded: jest.fn().mockResolvedValue(undefined), decryptEventIfNeeded: jest.fn().mockResolvedValue(undefined),
getOrCreateFilter: jest.fn().mockResolvedValue(filterId), getOrCreateFilter: jest.fn().mockResolvedValue(filterId),
paginateEventTimeline: jest.fn().mockResolvedValue(undefined), paginateEventTimeline: jest.fn().mockResolvedValue(undefined),
@ -128,7 +129,7 @@ describe('ThreadPanel', () => {
beforeEach(() => { beforeEach(() => {
mocked(client.getUserId).mockReturnValue(aliceId); mocked(client.getUserId).mockReturnValue(aliceId);
mocked(client.getCapabilities).mockResolvedValue({}); mocked(client.doesServerSupportUnstableFeature).mockResolvedValue(false);
}); });
describe('when extra capabilities are not enabled on server', () => { describe('when extra capabilities are not enabled on server', () => {
@ -168,9 +169,8 @@ describe('ThreadPanel', () => {
describe('when extra capabilities are enabled on server', () => { describe('when extra capabilities are enabled on server', () => {
beforeEach(() => { beforeEach(() => {
jest.clearAllMocks(); jest.clearAllMocks();
mocked(client.getCapabilities).mockResolvedValue({ Thread.hasServerSideSupport = true;
['io.element.thread']: { enabled: true }, mocked(client.doesServerSupportUnstableFeature).mockResolvedValue(true);
});
}); });
it('creates a filter with correct definition when filterType is All', async () => { 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]; const [filterKey, filter] = mocked(client).getOrCreateFilter.mock.calls[0];
expect(filterKey).toEqual(`THREAD_PANEL_${room.roomId}_${ThreadFilterType.All}`); expect(filterKey).toEqual(`THREAD_PANEL_${room.roomId}_${ThreadFilterType.All}`);
expect(filter.getDefinition().room.timeline).toEqual({ 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]; const [filterKey, filter] = mocked(client).getOrCreateFilter.mock.calls[0];
expect(filterKey).toEqual(`THREAD_PANEL_${room.roomId}_${ThreadFilterType.My}`); expect(filterKey).toEqual(`THREAD_PANEL_${room.roomId}_${ThreadFilterType.My}`);
expect(filter.getDefinition().room.timeline).toEqual({ expect(filter.getDefinition().room.timeline).toEqual({
[UNSTABLE_FILTER_RELATION_TYPES.name]: [RelationType.Thread], [UNSTABLE_FILTER_RELATED_BY_REL_TYPES.name]: [RelationType.Thread],
[UNSTABLE_FILTER_RELATION_SENDERS.name]: [aliceId], [UNSTABLE_FILTER_RELATED_BY_SENDERS.name]: [aliceId],
}); });
}); });
}); });