Mark events that are loaded from storage as such

This commit is contained in:
RMidhunSuresh 2023-04-18 21:54:52 +05:30
parent 644f1af88c
commit 85ede8a753
2 changed files with 9 additions and 4 deletions

View File

@ -19,15 +19,16 @@ import {getPrevContentFromStateEvent, isRedacted} from "../../common";
import {getRelationFromContent, getRelatedEventId} from "../relations.js";
export class EventEntry extends BaseEventEntry {
constructor(eventEntry, fragmentIdComparer) {
constructor(eventEntry, fragmentIdComparer, isLoadedFromStorage = false) {
super(fragmentIdComparer);
this._eventEntry = eventEntry;
this._decryptionError = null;
this._decryptionResult = null;
this._isLoadedFromStorage = isLoadedFromStorage;
}
clone() {
const clone = new EventEntry(this._eventEntry, this._fragmentIdComparer);
const clone = new EventEntry(this._eventEntry, this._fragmentIdComparer, this._isLoadedFromStorage);
clone.updateFrom(this);
return clone;
}
@ -89,6 +90,10 @@ export class EventEntry extends BaseEventEntry {
return this._eventEntry.event.origin_server_ts;
}
get isLoadedFromStorage() {
return this._isLoadedFromStorage;
}
get id() {
return this._eventEntry.event.event_id;
}

View File

@ -54,7 +54,7 @@ async function readRawTimelineEntriesWithTxn(roomId, eventKey, direction, amount
} else {
eventsWithinFragment = await timelineStore.eventsBefore(roomId, eventKey, amount);
}
let eventEntries = eventsWithinFragment.map(e => new EventEntry(e, fragmentIdComparer));
let eventEntries = eventsWithinFragment.map(e => new EventEntry(e, fragmentIdComparer, true));
entries = directionalConcat(entries, eventEntries, direction);
// prepend or append eventsWithinFragment to entries, and wrap them in EventEntry
@ -140,7 +140,7 @@ export class TimelineReader {
const txn = await this._storage.readTxn(stores); // todo: can we just use this.readTxnStores here? probably
const storageEntry = await txn.timelineEvents.getByEventId(this._roomId, id);
if (storageEntry) {
const entry = new EventEntry(storageEntry, this._fragmentIdComparer);
const entry = new EventEntry(storageEntry, this._fragmentIdComparer, true);
if (this._decryptEntries) {
const request = this._decryptEntries([entry], txn, log);
await request.complete();