1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-23 17:02:25 +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 {

View File

@@ -438,14 +438,14 @@ export class MatrixEvent extends EventEmitter {
* @experimental
*/
public get isThreadRoot(): boolean {
// TODO, change the inner working of this getter for it to use the
// bundled relationship return on the event, view MSC3440
const thread = this.getThread();
return thread?.id === this.getId();
}
public get parentEventId(): string {
const relations = this.getWireContent()["m.relates_to"];
return relations?.["m.in_reply_to"]?.["event_id"]
|| relations?.event_id;
return this.replyEventId || this.relationEventId;
}
public get replyEventId(): string {
@@ -453,6 +453,12 @@ export class MatrixEvent extends EventEmitter {
return relations?.["m.in_reply_to"]?.["event_id"];
}
public get relationEventId(): string {
return this.getWireContent()
?.["m.relates_to"]
?.event_id;
}
/**
* Get the previous event content JSON. This will only return something for
* state events which exist in the timeline.

View File

@@ -1270,8 +1270,11 @@ export class Room extends EventEmitter {
if (!event) {
return null;
}
if (event.isThreadRelation) {
return this.threads.get(event.threadRootId);
} else if (event.isThreadRoot) {
return this.threads.get(event.getId());
} else {
const parentEvent = this.findEventById(event.parentEventId);
return this.findThreadForEvent(parentEvent);