diff --git a/src/matrix/room/BaseRoom.js b/src/matrix/room/BaseRoom.js index 531f6a1a..9269404a 100644 --- a/src/matrix/room/BaseRoom.js +++ b/src/matrix/room/BaseRoom.js @@ -17,6 +17,7 @@ limitations under the License. import {EventEmitter} from "../../utils/EventEmitter.js"; import {RoomSummary} from "./RoomSummary.js"; import {GapWriter} from "./timeline/persistence/GapWriter.js"; +import {RelationWriter} from "./timeline/persistence/RelationWriter.js"; import {Timeline} from "./timeline/Timeline.js"; import {FragmentIdComparer} from "./timeline/FragmentIdComparer.js"; import {WrappedError} from "../error.js" @@ -266,10 +267,16 @@ export class BaseRoom extends EventEmitter { // detect remote echos of pending messages in the gap extraGapFillChanges = await this._writeGapFill(response.chunk, txn, log); // write new events into gap + const relationWriter = new RelationWriter({ + roomId: this._roomId, + fragmentIdComparer: this._fragmentIdComparer, + ownUserId: this._user.id, + }); const gapWriter = new GapWriter({ roomId: this._roomId, storage: this._storage, fragmentIdComparer: this._fragmentIdComparer, + relationWriter }); gapResult = await gapWriter.writeFragmentFill(fragmentEntry, response, txn, log); } catch (err) { diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index da9eef52..0361e069 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -16,6 +16,8 @@ limitations under the License. import {BaseRoom} from "./BaseRoom.js"; import {SyncWriter} from "./timeline/persistence/SyncWriter.js"; +import {MemberWriter} from "./timeline/persistence/MemberWriter.js"; +import {RelationWriter} from "./timeline/persistence/RelationWriter.js"; import {SendQueue} from "./sending/SendQueue.js"; import {WrappedError} from "../error.js" import {Heroes} from "./members/Heroes.js"; @@ -28,7 +30,17 @@ export class Room extends BaseRoom { constructor(options) { super(options); const {pendingEvents} = options; - this._syncWriter = new SyncWriter({roomId: this.id, fragmentIdComparer: this._fragmentIdComparer}); + const relationWriter = new RelationWriter({ + roomId: this.id, + fragmentIdComparer: this._fragmentIdComparer, + ownUserId: this._user.id + }); + this._syncWriter = new SyncWriter({ + roomId: this.id, + fragmentIdComparer: this._fragmentIdComparer, + relationWriter, + memberWriter: new MemberWriter(this.id) + }); this._sendQueue = new SendQueue({roomId: this.id, storage: this._storage, hsApi: this._hsApi, pendingEvents}); } diff --git a/src/matrix/room/timeline/persistence/GapWriter.js b/src/matrix/room/timeline/persistence/GapWriter.js index 67668298..5e49695a 100644 --- a/src/matrix/room/timeline/persistence/GapWriter.js +++ b/src/matrix/room/timeline/persistence/GapWriter.js @@ -14,18 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {RelationWriter} from "./RelationWriter.js"; import {EventKey} from "../EventKey.js"; import {EventEntry} from "../entries/EventEntry.js"; import {createEventEntry, directionalAppend} from "./common.js"; import {RoomMember, EVENT_TYPE as MEMBER_EVENT_TYPE} from "../../members/RoomMember.js"; export class GapWriter { - constructor({roomId, storage, fragmentIdComparer}) { + constructor({roomId, storage, fragmentIdComparer, relationWriter}) { this._roomId = roomId; this._storage = storage; this._fragmentIdComparer = fragmentIdComparer; - this._relationWriter = new RelationWriter(roomId, fragmentIdComparer); + this._relationWriter = relationWriter; } // events is in reverse-chronological order (last event comes at index 0) if backwards async _findOverlappingEvents(fragmentEntry, events, txn, log) { diff --git a/src/matrix/room/timeline/persistence/RelationWriter.js b/src/matrix/room/timeline/persistence/RelationWriter.js index 45716d04..305fc8eb 100644 --- a/src/matrix/room/timeline/persistence/RelationWriter.js +++ b/src/matrix/room/timeline/persistence/RelationWriter.js @@ -18,8 +18,9 @@ import {EventEntry} from "../entries/EventEntry.js"; import {REDACTION_TYPE} from "../../common.js"; export class RelationWriter { - constructor(roomId, fragmentIdComparer) { + constructor({roomId, ownUserId, fragmentIdComparer}) { this._roomId = roomId; + this._ownUserId = ownUserId; this._fragmentIdComparer = fragmentIdComparer; } diff --git a/src/matrix/room/timeline/persistence/SyncWriter.js b/src/matrix/room/timeline/persistence/SyncWriter.js index 671b944a..39d341ef 100644 --- a/src/matrix/room/timeline/persistence/SyncWriter.js +++ b/src/matrix/room/timeline/persistence/SyncWriter.js @@ -20,8 +20,6 @@ import {EventEntry} from "../entries/EventEntry.js"; import {FragmentBoundaryEntry} from "../entries/FragmentBoundaryEntry.js"; import {createEventEntry} from "./common.js"; import {EVENT_TYPE as MEMBER_EVENT_TYPE} from "../../members/RoomMember.js"; -import {MemberWriter} from "./MemberWriter.js"; -import {RelationWriter} from "./RelationWriter.js"; // Synapse bug? where the m.room.create event appears twice in sync response // when first syncing the room @@ -38,10 +36,10 @@ function deduplicateEvents(events) { } export class SyncWriter { - constructor({roomId, fragmentIdComparer}) { + constructor({roomId, fragmentIdComparer, memberWriter, relationWriter}) { this._roomId = roomId; - this._memberWriter = new MemberWriter(roomId); - this._relationWriter = new RelationWriter(roomId, fragmentIdComparer); + this._memberWriter = memberWriter; + this._relationWriter = relationWriter; this._fragmentIdComparer = fragmentIdComparer; this._lastLiveKey = null; }