Use server capabilities to determine how to build thread list (#7470)

pull/21833/head
Germain 2022-01-11 13:11:08 +00:00 committed by GitHub
parent df6edb0ba7
commit 8b088da888
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 22 deletions

View File

@ -43,32 +43,32 @@ async function getThreadTimelineSet(
room: Room, room: Room,
filterType = ThreadFilterType.All, filterType = ThreadFilterType.All,
): Promise<EventTimelineSet> { ): Promise<EventTimelineSet> {
const myUserId = client.getUserId(); const capabilities = await client.getCapabilities();
const filter = new Filter(myUserId); const serverSupportsThreads = capabilities['io.element.thread']?.enabled;
const definition: IFilterDefinition = { if (serverSupportsThreads) {
"room": { const myUserId = client.getUserId();
"timeline": { const filter = new Filter(myUserId);
[UNSTABLE_FILTER_RELATION_TYPES.name]: [RelationType.Thread],
const definition: IFilterDefinition = {
"room": {
"timeline": {
[UNSTABLE_FILTER_RELATION_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_RELATION_SENDERS.name] = [myUserId];
} }
filter.setDefinition(definition); filter.setDefinition(definition);
let timelineSet;
try {
const filterId = await client.getOrCreateFilter( const filterId = await client.getOrCreateFilter(
`THREAD_PANEL_${room.roomId}_${filterType}`, `THREAD_PANEL_${room.roomId}_${filterType}`,
filter, filter,
); );
filter.filterId = filterId; filter.filterId = filterId;
timelineSet = room.getOrCreateFilteredTimelineSet( const timelineSet = room.getOrCreateFilteredTimelineSet(
filter, filter,
{ prepopulateTimeline: false }, { prepopulateTimeline: false },
); );
@ -78,20 +78,20 @@ async function getThreadTimelineSet(
timelineSet.getLiveTimeline(), timelineSet.getLiveTimeline(),
{ backwards: true, limit: 20 }, { backwards: true, limit: 20 },
); );
} catch (e) { return timelineSet;
} else {
// Filter creation fails if HomeServer does not support the new relation // Filter creation fails if HomeServer does not support the new relation
// filter fields. We fallback to the threads that have been discovered in // filter fields. We fallback to the threads that have been discovered in
// the main timeline // the main timeline
timelineSet = new EventTimelineSet(room, {}); const timelineSet = new EventTimelineSet(room, {});
for (const [, thread] of room.threads) { for (const [, thread] of room.threads) {
const isOwnEvent = thread.rootEvent.getSender() === client.getUserId(); const isOwnEvent = thread.rootEvent.getSender() === client.getUserId();
if (filterType !== ThreadFilterType.My || isOwnEvent) { if (filterType !== ThreadFilterType.My || isOwnEvent) {
timelineSet.getLiveTimeline().addEvent(thread.rootEvent); timelineSet.getLiveTimeline().addEvent(thread.rootEvent, false);
} }
} }
return timelineSet;
} }
return timelineSet;
} }
interface IProps { interface IProps {