You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Move relations and redactions to thread timeline
This commit is contained in:
@@ -420,6 +420,11 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
|| this.thread instanceof Thread;
|
|| this.thread instanceof Thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get parentEventId(): string {
|
||||||
|
return this.replyEventId
|
||||||
|
|| 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.
|
||||||
|
|||||||
@@ -1305,8 +1305,7 @@ export class Room extends EventEmitter {
|
|||||||
this.handleRemoteEcho(event, existingEvent);
|
this.handleRemoteEcho(event, existingEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let thread = this.findEventById(event.parentEventId)?.getThread();
|
||||||
let thread = this.findEventById(event.replyEventId)?.getThread();
|
|
||||||
if (thread) {
|
if (thread) {
|
||||||
thread.addEvent(event);
|
thread.addEvent(event);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -149,6 +149,10 @@ export class Thread extends EventEmitter {
|
|||||||
return this.findEventById(this.root);
|
return this.findEventById(this.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get roomId(): string {
|
||||||
|
return this.rootEvent.getRoomId();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of messages in the thread
|
* The number of messages in the thread
|
||||||
*/
|
*/
|
||||||
|
|||||||
58
src/sync.ts
58
src/sync.ts
@@ -316,8 +316,18 @@ export class SyncApi {
|
|||||||
if (this.opts.experimentalThreadSupport) {
|
if (this.opts.experimentalThreadSupport) {
|
||||||
return events.reduce((memo, event: MatrixEvent) => {
|
return events.reduce((memo, event: MatrixEvent) => {
|
||||||
const room = this.client.getRoom(event.getRoomId());
|
const room = this.client.getRoom(event.getRoomId());
|
||||||
const eventInThread = this.shouldLiveInThreadTimeline(event, room);
|
// An event should live in the thread timeline if
|
||||||
memo[eventInThread ? 1 : 0].push(event);
|
// - It's a reply in thread event
|
||||||
|
// - It's related to a reply in thread event
|
||||||
|
let shouldLiveInThreadTimeline = event.replyInThread;
|
||||||
|
if (!shouldLiveInThreadTimeline) {
|
||||||
|
const parentEventId = event.getWireContent()["m.relates_to"]?.event_id;
|
||||||
|
const parentEvent = room?.findEventById(parentEventId) || events.find((mxEv: MatrixEvent) => {
|
||||||
|
return mxEv.getId() === parentEventId;
|
||||||
|
});
|
||||||
|
shouldLiveInThreadTimeline = parentEvent?.replyInThread;
|
||||||
|
}
|
||||||
|
memo[shouldLiveInThreadTimeline ? 1 : 0].push(event);
|
||||||
return memo;
|
return memo;
|
||||||
}, [[], []]);
|
}, [[], []]);
|
||||||
} else {
|
} else {
|
||||||
@@ -330,50 +340,6 @@ export class SyncApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental
|
|
||||||
* An event should live in a thread if it's a threaded reply
|
|
||||||
* Or if it's related to an event that is a threaded reply
|
|
||||||
* Things like annotations, redactions, ...
|
|
||||||
*/
|
|
||||||
private shouldLiveInThreadTimeline(event: MatrixEvent, room: Room): boolean {
|
|
||||||
let isThreadReply = event.replyInThread;
|
|
||||||
|
|
||||||
// If the message is sent from a client that does not support threads
|
|
||||||
// The relation body will not contain `UNSTABLE_ELEMENT_REPLY_IN_THREAD`
|
|
||||||
// We go up the reply chain looking for an event that has this property
|
|
||||||
// If we find one, we then decide to render this reply inside the thread
|
|
||||||
if (!isThreadReply && event.replyEventId) {
|
|
||||||
isThreadReply = this.ancestorInThread(event, room);
|
|
||||||
}
|
|
||||||
|
|
||||||
let isRelatedToThreadReply = false;
|
|
||||||
const relationEventId = event.getRelation()?.event_id;
|
|
||||||
if (relationEventId) {
|
|
||||||
const relatedEvent = room.findEventById(relationEventId);
|
|
||||||
isRelatedToThreadReply = relatedEvent.replyInThread;
|
|
||||||
}
|
|
||||||
|
|
||||||
return isThreadReply || isRelatedToThreadReply;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental
|
|
||||||
* Checks whether an event up in the reply chain has
|
|
||||||
* the `UNSTABLE_ELEMENT_REPLY_IN_THREAD` property in its
|
|
||||||
* relations body
|
|
||||||
*/
|
|
||||||
private ancestorInThread(event: MatrixEvent, room: Room): boolean {
|
|
||||||
const relatedEvent = room.findEventById(event.replyEventId);
|
|
||||||
if (relatedEvent.replyInThread) {
|
|
||||||
return true;
|
|
||||||
} else if (relatedEvent.replyEventId) {
|
|
||||||
return this.ancestorInThread(relatedEvent, room);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Peek into a room. This will result in the room in question being synced so it
|
* Peek into a room. This will result in the room in question being synced so it
|
||||||
* is accessible via getRooms(). Live updates for the room will be provided.
|
* is accessible via getRooms(). Live updates for the room will be provided.
|
||||||
|
|||||||
Reference in New Issue
Block a user