From a61f052fe86c7e4f2ca7175d81968213f1a281dd Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 27 Aug 2021 17:23:32 +0200 Subject: [PATCH] fix lint --- .../room/timeline/persistence/MemberWriter.js | 26 -------- .../room/timeline/persistence/SyncWriter.js | 62 +++++++++---------- 2 files changed, 31 insertions(+), 57 deletions(-) diff --git a/src/matrix/room/timeline/persistence/MemberWriter.js b/src/matrix/room/timeline/persistence/MemberWriter.js index 0c24b06f..fba43ddf 100644 --- a/src/matrix/room/timeline/persistence/MemberWriter.js +++ b/src/matrix/room/timeline/persistence/MemberWriter.js @@ -191,32 +191,6 @@ export function tests() { }; } - function createRoomResponse(stateEvents, timelineEvents) { - if (!Array.isArray(timelineEvents)) { - timelineEvents = [timelineEvents]; - } - if (!Array.isArray(stateEvents)) { - stateEvents = [stateEvents]; - } - return { - timeline: { - limited: false, - events: timelineEvents, - }, - state: { - events: stateEvents - } - }; - } - - function createTimelineResponse(timelineEvents) { - return createRoomResponse([], timelineEvents) - } - - function createStateReponse(stateEvents) { - return createRoomResponse(stateEvents, []); - } - function createStorage(initialMembers = []) { const members = new Map(); for (const m of initialMembers) { diff --git a/src/matrix/room/timeline/persistence/SyncWriter.js b/src/matrix/room/timeline/persistence/SyncWriter.js index b0970ca0..f6c167e8 100644 --- a/src/matrix/room/timeline/persistence/SyncWriter.js +++ b/src/matrix/room/timeline/persistence/SyncWriter.js @@ -149,35 +149,37 @@ export class SyncWriter { const entries = []; const updatedEntries = []; // only create a fragment when we will really write an event - currentKey = await this._ensureLiveFragment(currentKey, entries, timeline, txn, log); - log.set("timelineEvents", timelineEvents.length); - let timelineStateEventCount = 0; - for(const event of timelineEvents) { - // store event in timeline - currentKey = currentKey.nextKey(); - const storageEntry = createEventEntry(currentKey, this._roomId, event); - let member = await memberSync.lookupMemberAtEvent(event.sender, event, txn); - if (member) { - storageEntry.displayName = member.displayName; - storageEntry.avatarUrl = member.avatarUrl; - } - txn.timelineEvents.insert(storageEntry); - const entry = new EventEntry(storageEntry, this._fragmentIdComparer); - entries.push(entry); - const updatedRelationTargetEntries = await this._relationWriter.writeRelation(entry, txn, log); - if (updatedRelationTargetEntries) { - updatedEntries.push(...updatedRelationTargetEntries); - } - // update state events after writing event, so for a member event, - // we only update the member info after having written the member event - // to the timeline, as we want that event to have the old profile info. - // member events are written prior by MemberWriter. - if (typeof event.state_key === "string" && event.type !== MEMBER_EVENT_TYPE) { - timelineStateEventCount += 1; - txn.roomState.set(this._roomId, event); + if (timelineEvents?.length) { + currentKey = await this._ensureLiveFragment(currentKey, entries, timeline, txn, log); + log.set("timelineEvents", timelineEvents.length); + let timelineStateEventCount = 0; + for(const event of timelineEvents) { + // store event in timeline + currentKey = currentKey.nextKey(); + const storageEntry = createEventEntry(currentKey, this._roomId, event); + let member = await memberSync.lookupMemberAtEvent(event.sender, event, txn); + if (member) { + storageEntry.displayName = member.displayName; + storageEntry.avatarUrl = member.avatarUrl; + } + txn.timelineEvents.insert(storageEntry); + const entry = new EventEntry(storageEntry, this._fragmentIdComparer); + entries.push(entry); + const updatedRelationTargetEntries = await this._relationWriter.writeRelation(entry, txn, log); + if (updatedRelationTargetEntries) { + updatedEntries.push(...updatedRelationTargetEntries); + } + // update state events after writing event, so for a member event, + // we only update the member info after having written the member event + // to the timeline, as we want that event to have the old profile info. + // member events are written prior by MemberWriter. + if (typeof event.state_key === "string" && event.type !== MEMBER_EVENT_TYPE) { + timelineStateEventCount += 1; + txn.roomState.set(this._roomId, event); + } } + log.set("timelineStateEventCount", timelineStateEventCount); } - log.set("timelineStateEventCount", timelineStateEventCount); return {currentKey, entries, updatedEntries}; } @@ -236,10 +238,8 @@ export class SyncWriter { if (stateEvents) { await this._writeStateEvents(roomResponse, txn, log); } - if (timelineEvents?.length) { - const {currentKey, entries, updatedEntries} = - await this._writeTimeline(timelineEvents, timeline, memberSync, this._lastLiveKey, txn, log); - } + const {currentKey, entries, updatedEntries} = + await this._writeTimeline(timelineEvents, timeline, memberSync, this._lastLiveKey, txn, log); const memberChanges = await memberSync.write(txn); return {entries, updatedEntries, newLiveKey: currentKey, memberChanges}; }