You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-07 23:02:56 +03:00
Out of sync thread summary in main timeline (#2153)
This commit is contained in:
@@ -29,7 +29,21 @@ export function eventMapperFor(client: MatrixClient, options: MapperOpts): Event
|
|||||||
const decrypt = options.decrypt !== false;
|
const decrypt = options.decrypt !== false;
|
||||||
|
|
||||||
function mapper(plainOldJsObject: Partial<IEvent>) {
|
function mapper(plainOldJsObject: Partial<IEvent>) {
|
||||||
const event = new MatrixEvent(plainOldJsObject);
|
const room = client.getRoom(plainOldJsObject.room_id);
|
||||||
|
let event: MatrixEvent;
|
||||||
|
|
||||||
|
// If the event is already known to the room, let's re-use the model
|
||||||
|
// rather than creating a duplicate
|
||||||
|
if (room) {
|
||||||
|
event = room.findEventById(plainOldJsObject.event_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no event is found or if the event found was only local we can
|
||||||
|
// safely create a new model
|
||||||
|
if (!event || event.status) {
|
||||||
|
event = new MatrixEvent(plainOldJsObject);
|
||||||
|
}
|
||||||
|
|
||||||
if (event.isEncrypted()) {
|
if (event.isEncrypted()) {
|
||||||
if (!preventReEmit) {
|
if (!preventReEmit) {
|
||||||
client.reEmitter.reEmit(event, [
|
client.reEmitter.reEmit(event, [
|
||||||
|
@@ -277,7 +277,7 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
* it to us and the time we're now constructing this event, but that's better
|
* it to us and the time we're now constructing this event, but that's better
|
||||||
* than assuming the local clock is in sync with the origin HS's clock.
|
* than assuming the local clock is in sync with the origin HS's clock.
|
||||||
*/
|
*/
|
||||||
public readonly localTimestamp: number;
|
public localTimestamp: number;
|
||||||
|
|
||||||
// XXX: these should be read-only
|
// XXX: these should be read-only
|
||||||
public sender: RoomMember = null;
|
public sender: RoomMember = null;
|
||||||
@@ -342,7 +342,7 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.txnId = event.txn_id || null;
|
this.txnId = event.txn_id || null;
|
||||||
this.localTimestamp = Date.now() - this.getAge();
|
this.localTimestamp = Date.now() - (this.getAge() ?? 0);
|
||||||
this.reEmitter = new ReEmitter(this);
|
this.reEmitter = new ReEmitter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -584,9 +584,10 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
* Get the age of this event. This represents the age of the event when the
|
* Get the age of this event. This represents the age of the event when the
|
||||||
* event arrived at the device, and not the age of the event when this
|
* event arrived at the device, and not the age of the event when this
|
||||||
* function was called.
|
* function was called.
|
||||||
* @return {Number} The age of this event in milliseconds.
|
* Can only be returned once the server has echo'ed back
|
||||||
|
* @return {Number|undefined} The age of this event in milliseconds.
|
||||||
*/
|
*/
|
||||||
public getAge(): number {
|
public getAge(): number | undefined {
|
||||||
return this.getUnsigned().age || this.event.age; // v2 / v1
|
return this.getUnsigned().age || this.event.age; // v2 / v1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1269,6 +1270,8 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
// emit the event if it changed
|
// emit the event if it changed
|
||||||
this.emit("Event.localEventIdReplaced", this);
|
this.emit("Event.localEventIdReplaced", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.localTimestamp = Date.now() - this.getAge();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -77,8 +77,6 @@ export class Thread extends TypedEventEmitter<ThreadEvent> {
|
|||||||
});
|
});
|
||||||
this.reEmitter = new ReEmitter(this);
|
this.reEmitter = new ReEmitter(this);
|
||||||
|
|
||||||
this.initialiseThread(this.rootEvent);
|
|
||||||
|
|
||||||
this.reEmitter.reEmit(this.timelineSet, [
|
this.reEmitter.reEmit(this.timelineSet, [
|
||||||
"Room.timeline",
|
"Room.timeline",
|
||||||
"Room.timelineReset",
|
"Room.timelineReset",
|
||||||
@@ -92,6 +90,7 @@ export class Thread extends TypedEventEmitter<ThreadEvent> {
|
|||||||
} else {
|
} else {
|
||||||
this.id = rootEvent.getId();
|
this.id = rootEvent.getId();
|
||||||
}
|
}
|
||||||
|
this.initialiseThread(this.rootEvent);
|
||||||
|
|
||||||
opts?.initialEvents?.forEach(event => this.addEvent(event));
|
opts?.initialEvents?.forEach(event => this.addEvent(event));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user