1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Copy relations to thread root in the thread timeline (#2012)

This commit is contained in:
Germain
2021-11-05 14:16:45 +00:00
committed by GitHub
parent 195498e9db
commit 43bc09f392
3 changed files with 29 additions and 5 deletions

View File

@@ -8569,6 +8569,10 @@ export class MatrixClient extends EventEmitter {
}
public partitionThreadedEvents(events: MatrixEvent[]): [MatrixEvent[], MatrixEvent[]] {
// Indices to the events array, for readibility
const ROOM = 0;
const THREAD = 1;
const threadRoots = new Set<string>();
if (this.supportsExperimentalThreads) {
return events.reduce((memo, event: MatrixEvent) => {
const room = this.getRoom(event.getRoomId());
@@ -8576,14 +8580,25 @@ export class MatrixClient extends EventEmitter {
// - It's a reply in thread event
// - It's related to a reply in thread event
let shouldLiveInThreadTimeline = event.isThreadRelation;
if (!shouldLiveInThreadTimeline) {
if (shouldLiveInThreadTimeline) {
threadRoots.add(event.relationEventId);
} else {
const parentEventId = event.parentEventId;
const parentEvent = room?.findEventById(parentEventId) || events.find((mxEv: MatrixEvent) => {
return mxEv.getId() === parentEventId;
});
shouldLiveInThreadTimeline = parentEvent?.isThreadRelation;
// Copy all the reactions and annotations to the root event
// to the thread timeline. They will end up living in both
// timelines at the same time
const targetingThreadRoot = parentEvent?.isThreadRoot || threadRoots.has(event.relationEventId);
if (targetingThreadRoot && !event.isThreadRelation && event.relationEventId) {
memo[THREAD].push(event);
}
}
memo[shouldLiveInThreadTimeline ? 1 : 0].push(event);
const targetTimeline = shouldLiveInThreadTimeline ? THREAD : ROOM;
memo[targetTimeline].push(event);
return memo;
}, [[], []]);
} else {