You've already forked matrix-js-sdk
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:
@@ -8569,6 +8569,10 @@ export class MatrixClient extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public partitionThreadedEvents(events: MatrixEvent[]): [MatrixEvent[], MatrixEvent[]] {
|
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) {
|
if (this.supportsExperimentalThreads) {
|
||||||
return events.reduce((memo, event: MatrixEvent) => {
|
return events.reduce((memo, event: MatrixEvent) => {
|
||||||
const room = this.getRoom(event.getRoomId());
|
const room = this.getRoom(event.getRoomId());
|
||||||
@@ -8576,14 +8580,25 @@ export class MatrixClient extends EventEmitter {
|
|||||||
// - It's a reply in thread event
|
// - It's a reply in thread event
|
||||||
// - It's related to a reply in thread event
|
// - It's related to a reply in thread event
|
||||||
let shouldLiveInThreadTimeline = event.isThreadRelation;
|
let shouldLiveInThreadTimeline = event.isThreadRelation;
|
||||||
if (!shouldLiveInThreadTimeline) {
|
if (shouldLiveInThreadTimeline) {
|
||||||
|
threadRoots.add(event.relationEventId);
|
||||||
|
} else {
|
||||||
const parentEventId = event.parentEventId;
|
const parentEventId = event.parentEventId;
|
||||||
const parentEvent = room?.findEventById(parentEventId) || events.find((mxEv: MatrixEvent) => {
|
const parentEvent = room?.findEventById(parentEventId) || events.find((mxEv: MatrixEvent) => {
|
||||||
return mxEv.getId() === parentEventId;
|
return mxEv.getId() === parentEventId;
|
||||||
});
|
});
|
||||||
shouldLiveInThreadTimeline = parentEvent?.isThreadRelation;
|
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;
|
return memo;
|
||||||
}, [[], []]);
|
}, [[], []]);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -438,14 +438,14 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
public get isThreadRoot(): boolean {
|
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();
|
const thread = this.getThread();
|
||||||
return thread?.id === this.getId();
|
return thread?.id === this.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public get parentEventId(): string {
|
public get parentEventId(): string {
|
||||||
const relations = this.getWireContent()["m.relates_to"];
|
return this.replyEventId || this.relationEventId;
|
||||||
return relations?.["m.in_reply_to"]?.["event_id"]
|
|
||||||
|| relations?.event_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get replyEventId(): string {
|
public get replyEventId(): string {
|
||||||
@@ -453,6 +453,12 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
return relations?.["m.in_reply_to"]?.["event_id"];
|
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
|
* Get the previous event content JSON. This will only return something for
|
||||||
* state events which exist in the timeline.
|
* state events which exist in the timeline.
|
||||||
|
|||||||
@@ -1270,8 +1270,11 @@ export class Room extends EventEmitter {
|
|||||||
if (!event) {
|
if (!event) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.isThreadRelation) {
|
if (event.isThreadRelation) {
|
||||||
return this.threads.get(event.threadRootId);
|
return this.threads.get(event.threadRootId);
|
||||||
|
} else if (event.isThreadRoot) {
|
||||||
|
return this.threads.get(event.getId());
|
||||||
} else {
|
} else {
|
||||||
const parentEvent = this.findEventById(event.parentEventId);
|
const parentEvent = this.findEventById(event.parentEventId);
|
||||||
return this.findThreadForEvent(parentEvent);
|
return this.findThreadForEvent(parentEvent);
|
||||||
|
|||||||
Reference in New Issue
Block a user