pass ownUserId to RelationWriter

We'll need to to aggregate whether we have reacted to a message

Create writers at room level and pass subwriter is dependency, rather
than creating them in sync and gap writer.
This commit is contained in:
Bruno Windels 2021-06-03 16:42:09 +02:00
parent 46bfab3eb7
commit 36a35d92f0
5 changed files with 27 additions and 10 deletions

View file

@ -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) {

View file

@ -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});
}

View file

@ -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) {

View file

@ -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;
}

View file

@ -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;
}