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
Improve thread deduplication thread process
Some threads were still holding a reference to the original thread models they were assigned to, leading to some unexpected timeline rendering
This commit is contained in:
@@ -412,9 +412,12 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
* or in the main room timeline
|
* or in the main room timeline
|
||||||
*/
|
*/
|
||||||
public get replyInThread(): boolean {
|
public get replyInThread(): boolean {
|
||||||
const relations = this.getWireContent()["m.relates_to"];
|
const replyTo = this.getWireContent()
|
||||||
return this.replyEventId
|
?.["m.relates_to"]
|
||||||
&& relations[UNSTABLE_ELEMENT_REPLY_IN_THREAD.name];
|
?.["m.in_reply_to"];
|
||||||
|
return (this.replyEventId
|
||||||
|
&& replyTo[UNSTABLE_ELEMENT_REPLY_IN_THREAD.name])
|
||||||
|
|| this.thread instanceof Thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1104,16 +1104,17 @@ export class Room extends EventEmitter {
|
|||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
private dedupeThreads = (readyThread): void => {
|
private dedupeThreads = (readyThread): void => {
|
||||||
const threads = Array.from(this.threads);
|
const deduped = Array.from(this.threads).reduce((dedupedThreads, thread) => {
|
||||||
if (threads.includes(readyThread)) {
|
if (dedupedThreads.has(thread.id)) {
|
||||||
this.threads = new Set(threads.filter(thread => {
|
dedupedThreads.get(thread.id).merge(thread);
|
||||||
if (readyThread.id === thread.id && readyThread !== thread) {
|
} else {
|
||||||
return false;
|
dedupedThreads.set(thread.id, thread);
|
||||||
} else {
|
}
|
||||||
return true;
|
|
||||||
}
|
return dedupedThreads;
|
||||||
}));
|
}, new Map<string, Thread>());
|
||||||
}
|
|
||||||
|
this.threads = new Set<Thread>(deduped.values());
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export class Thread extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* A reference to all the events ID at the bottom of the threads
|
* A reference to all the events ID at the bottom of the threads
|
||||||
*/
|
*/
|
||||||
public tail = new Set<string>();
|
public readonly tail = new Set<string>();
|
||||||
private _timelineSet: EventTimelineSet;
|
private _timelineSet: EventTimelineSet;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -155,7 +155,7 @@ export class Thread extends EventEmitter {
|
|||||||
* The number of messages in the thread
|
* The number of messages in the thread
|
||||||
*/
|
*/
|
||||||
public get length(): number {
|
public get length(): number {
|
||||||
return this._timelineSet.getLiveTimeline().getEvents().length;
|
return this.events.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,7 +163,7 @@ export class Thread extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
public get participants(): Set<string> {
|
public get participants(): Set<string> {
|
||||||
const participants = new Set<string>();
|
const participants = new Set<string>();
|
||||||
this._timelineSet.getLiveTimeline().getEvents().forEach(event => {
|
this.events.forEach(event => {
|
||||||
participants.add(event.getSender());
|
participants.add(event.getSender());
|
||||||
});
|
});
|
||||||
return participants;
|
return participants;
|
||||||
@@ -180,7 +180,18 @@ export class Thread extends EventEmitter {
|
|||||||
* A getter for the last event added to the thread
|
* A getter for the last event added to the thread
|
||||||
*/
|
*/
|
||||||
public get replyToEvent(): MatrixEvent {
|
public get replyToEvent(): MatrixEvent {
|
||||||
const events = this._timelineSet.getLiveTimeline().getEvents();
|
const events = this.events;
|
||||||
return events[events.length -1];
|
return events[events.length -1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get events(): MatrixEvent[] {
|
||||||
|
return this._timelineSet.getLiveTimeline().getEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
public merge(thread: Thread): void {
|
||||||
|
thread.events.forEach(event => {
|
||||||
|
this.addEvent(event);
|
||||||
|
});
|
||||||
|
this.events.forEach(event => event.setThread(this));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/sync.ts
22
src/sync.ts
@@ -1718,11 +1718,27 @@ export class SyncApi {
|
|||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
private processThreadEvents(room: Room, threadedEvents: MatrixEvent[]): void {
|
private processThreadEvents(room: Room, threadedEvents: MatrixEvent[]): void {
|
||||||
threadedEvents.forEach(event => {
|
threadedEvents
|
||||||
room.addThreadedEvent(event);
|
.sort((a, b) => a.getTs() - b.getTs())
|
||||||
});
|
.forEach(event => {
|
||||||
|
room.addThreadedEvent(event);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// extractRelatedEvents(event: MatrixEvent, events: MatrixEvent[], relatedEvents: MatrixEvent[] = []): MatrixEvent[] {
|
||||||
|
// relatedEvents.push(event);
|
||||||
|
|
||||||
|
// const parentEventId = event.parentEventId;
|
||||||
|
// const parentEventIndex = events.findIndex(event => event.getId() === parentEventId);
|
||||||
|
|
||||||
|
// if (parentEventIndex > -1) {
|
||||||
|
// const [relatedEvent] = events.splice(parentEventIndex, 1);
|
||||||
|
// return this.extractRelatedEvents(relatedEvent, events, relatedEvents);
|
||||||
|
// } else {
|
||||||
|
// return relatedEvents;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a list of timelineEvents and adds and adds to notifEvents
|
* Takes a list of timelineEvents and adds and adds to notifEvents
|
||||||
* as appropriate.
|
* as appropriate.
|
||||||
|
|||||||
Reference in New Issue
Block a user