You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-04 05:02:41 +03:00
Fix initial sync fail when event fetching unsuccessful (#2150)
This commit is contained in:
@@ -1372,13 +1372,24 @@ export class Room extends EventEmitter {
|
|||||||
let rootEvent = this.findEventById(event.threadRootId);
|
let rootEvent = this.findEventById(event.threadRootId);
|
||||||
// If the rootEvent does not exist in the current sync, then look for
|
// If the rootEvent does not exist in the current sync, then look for
|
||||||
// it over the network
|
// it over the network
|
||||||
const eventData = await this.client.fetchRoomEvent(this.roomId, event.threadRootId);
|
try {
|
||||||
if (!rootEvent) {
|
let eventData;
|
||||||
rootEvent = new MatrixEvent(eventData);
|
if (event.threadRootId) {
|
||||||
} else {
|
eventData = await this.client.fetchRoomEvent(this.roomId, event.threadRootId);
|
||||||
rootEvent.setUnsigned(eventData.unsigned);
|
}
|
||||||
|
|
||||||
|
if (!rootEvent) {
|
||||||
|
rootEvent = new MatrixEvent(eventData);
|
||||||
|
} else {
|
||||||
|
rootEvent.setUnsigned(eventData.unsigned);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// The root event might be not be visible to the person requesting
|
||||||
|
// it. If it wasn't fetched successfully the thread will work
|
||||||
|
// in "limited" mode and won't benefit from all the APIs a homeserver
|
||||||
|
// can provide to enhance the thread experience
|
||||||
|
thread = this.createThread(rootEvent, events);
|
||||||
}
|
}
|
||||||
thread = this.createThread(rootEvent, events);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getUnsigned().transaction_id) {
|
if (event.getUnsigned().transaction_id) {
|
||||||
@@ -1393,26 +1404,30 @@ export class Room extends EventEmitter {
|
|||||||
this.emit(ThreadEvent.Update, thread);
|
this.emit(ThreadEvent.Update, thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
public createThread(rootEvent: MatrixEvent, events?: MatrixEvent[]): Thread {
|
public createThread(rootEvent: MatrixEvent, events?: MatrixEvent[]): Thread | undefined {
|
||||||
const thread = new Thread(rootEvent, {
|
const thread = new Thread(rootEvent, {
|
||||||
initialEvents: events,
|
initialEvents: events,
|
||||||
room: this,
|
room: this,
|
||||||
client: this.client,
|
client: this.client,
|
||||||
});
|
});
|
||||||
this.threads.set(thread.id, thread);
|
// If we managed to create a thread and figure out its `id`
|
||||||
this.reEmitter.reEmit(thread, [
|
// then we can use it
|
||||||
ThreadEvent.Update,
|
if (thread.id) {
|
||||||
ThreadEvent.Ready,
|
this.threads.set(thread.id, thread);
|
||||||
"Room.timeline",
|
this.reEmitter.reEmit(thread, [
|
||||||
"Room.timelineReset",
|
ThreadEvent.Update,
|
||||||
]);
|
ThreadEvent.Ready,
|
||||||
|
"Room.timeline",
|
||||||
|
"Room.timelineReset",
|
||||||
|
]);
|
||||||
|
|
||||||
if (!this.lastThread || this.lastThread.rootEvent.localTimestamp < rootEvent.localTimestamp) {
|
if (!this.lastThread || this.lastThread.rootEvent.localTimestamp < rootEvent.localTimestamp) {
|
||||||
this.lastThread = thread;
|
this.lastThread = thread;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.emit(ThreadEvent.New, thread);
|
||||||
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emit(ThreadEvent.New, thread);
|
|
||||||
return thread;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -60,8 +60,10 @@ export class Thread extends TypedEventEmitter<ThreadEvent> {
|
|||||||
|
|
||||||
public initialEventsFetched = false;
|
public initialEventsFetched = false;
|
||||||
|
|
||||||
|
public readonly id: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public readonly rootEvent: MatrixEvent,
|
public readonly rootEvent: MatrixEvent | undefined,
|
||||||
opts: IThreadOpts,
|
opts: IThreadOpts,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
@@ -82,6 +84,15 @@ export class Thread extends TypedEventEmitter<ThreadEvent> {
|
|||||||
"Room.timelineReset",
|
"Room.timelineReset",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// If we weren't able to find the root event, it's probably missing
|
||||||
|
// and we define the thread ID from one of the thread relation
|
||||||
|
if (!rootEvent) {
|
||||||
|
this.id = opts?.initialEvents
|
||||||
|
?.find(event => event.isThreadRelation)?.relationEventId;
|
||||||
|
} else {
|
||||||
|
this.id = rootEvent.getId();
|
||||||
|
}
|
||||||
|
|
||||||
opts?.initialEvents?.forEach(event => this.addEvent(event));
|
opts?.initialEvents?.forEach(event => this.addEvent(event));
|
||||||
|
|
||||||
this.room.on("Room.localEchoUpdated", this.onEcho);
|
this.room.on("Room.localEchoUpdated", this.onEcho);
|
||||||
@@ -177,9 +188,9 @@ export class Thread extends TypedEventEmitter<ThreadEvent> {
|
|||||||
this.emit(ThreadEvent.Update, this);
|
this.emit(ThreadEvent.Update, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private initialiseThread(rootEvent: MatrixEvent): void {
|
private initialiseThread(rootEvent: MatrixEvent | undefined): void {
|
||||||
const bundledRelationship = rootEvent
|
const bundledRelationship = rootEvent
|
||||||
.getServerAggregatedRelation<IThreadBundledRelationship>(RelationType.Thread);
|
?.getServerAggregatedRelation<IThreadBundledRelationship>(RelationType.Thread);
|
||||||
|
|
||||||
if (this.hasServerSideSupport && bundledRelationship) {
|
if (this.hasServerSideSupport && bundledRelationship) {
|
||||||
this.replyCount = bundledRelationship.count;
|
this.replyCount = bundledRelationship.count;
|
||||||
@@ -190,7 +201,7 @@ export class Thread extends TypedEventEmitter<ThreadEvent> {
|
|||||||
this.lastEvent = event;
|
this.lastEvent = event;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bundledRelationship) {
|
if (!bundledRelationship && rootEvent) {
|
||||||
this.addEvent(rootEvent);
|
this.addEvent(rootEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,15 +240,8 @@ export class Thread extends TypedEventEmitter<ThreadEvent> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The thread ID, which is the same as the root event ID
|
|
||||||
*/
|
|
||||||
public get id(): string {
|
|
||||||
return this.rootEvent.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public get roomId(): string {
|
public get roomId(): string {
|
||||||
return this.rootEvent.getRoomId();
|
return this.room.roomId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user