mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Move methods into Timeline
This commit is contained in:
parent
51b7b21082
commit
5c0bbdd4c8
@ -30,7 +30,7 @@ import {DecryptionSource} from "../e2ee/common.js";
|
|||||||
import {ensureLogItem} from "../../logging/utils";
|
import {ensureLogItem} from "../../logging/utils";
|
||||||
import {PowerLevels} from "./PowerLevels.js";
|
import {PowerLevels} from "./PowerLevels.js";
|
||||||
import {RetainedObservableValue} from "../../observable/ObservableValue";
|
import {RetainedObservableValue} from "../../observable/ObservableValue";
|
||||||
import {NonPersistedEventEntry} from "./timeline/entries/NonPersistedEventEntry";
|
import {TimelineReader} from "./timeline/persistence/TimelineReader";
|
||||||
|
|
||||||
const EVENT_ENCRYPTED_TYPE = "m.room.encrypted";
|
const EVENT_ENCRYPTED_TYPE = "m.room.encrypted";
|
||||||
|
|
||||||
@ -503,8 +503,7 @@ export class BaseRoom extends EventEmitter {
|
|||||||
clock: this._platform.clock,
|
clock: this._platform.clock,
|
||||||
logger: this._platform.logger,
|
logger: this._platform.logger,
|
||||||
powerLevelsObservable: await this.observePowerLevels(),
|
powerLevelsObservable: await this.observePowerLevels(),
|
||||||
fetchEventFromStorage: eventId => this._readEventById(eventId),
|
hsApi: this._hsApi
|
||||||
fetchEventFromHomeserver: eventId => this._getEventFromHomeserver(eventId)
|
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
if (this._roomEncryption) {
|
if (this._roomEncryption) {
|
||||||
@ -546,39 +545,10 @@ export class BaseRoom extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _readEventById(eventId) {
|
async _readEventById(eventId) {
|
||||||
let stores = [this._storage.storeNames.timelineEvents];
|
const reader = new TimelineReader({ roomId: this._roomId, storage: this._storage, fragmentIdComparer: this._fragmentIdComparer });
|
||||||
if (this.isEncrypted) {
|
const entry = await reader.readById(eventId);
|
||||||
stores.push(this._storage.storeNames.inboundGroupSessions);
|
|
||||||
}
|
|
||||||
const txn = await this._storage.readTxn(stores);
|
|
||||||
const storageEntry = await txn.timelineEvents.getByEventId(this._roomId, eventId);
|
|
||||||
if (storageEntry) {
|
|
||||||
const entry = new EventEntry(storageEntry, this._fragmentIdComparer);
|
|
||||||
if (entry.eventType === EVENT_ENCRYPTED_TYPE) {
|
|
||||||
const request = this._decryptEntries(DecryptionSource.Timeline, [entry], txn);
|
|
||||||
await request.complete();
|
|
||||||
}
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async _getEventFromHomeserver(eventId) {
|
|
||||||
const response = await this._hsApi.context(this._roomId, eventId, 0).response();
|
|
||||||
const sender = response.event.sender;
|
|
||||||
const member = response.state.find(e => e.type === "m.room.member" && e.user_id === sender);
|
|
||||||
const entry = {
|
|
||||||
event: response.event,
|
|
||||||
displayName: member.content.displayname,
|
|
||||||
avatarUrl: member.content.avatar_url
|
|
||||||
};
|
|
||||||
const eventEntry = new NonPersistedEventEntry(entry, this._fragmentIdComparer);
|
|
||||||
if (eventEntry.eventType === EVENT_ENCRYPTED_TYPE) {
|
|
||||||
const request = this._decryptEntries(DecryptionSource.Timeline, [eventEntry]);
|
|
||||||
await request.complete();
|
|
||||||
}
|
|
||||||
return eventEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
this._roomEncryption?.dispose();
|
this._roomEncryption?.dispose();
|
||||||
|
@ -132,6 +132,23 @@ export class TimelineReader {
|
|||||||
}, log);
|
}, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async readById(id, log) {
|
||||||
|
let stores = [this._storage.storeNames.timelineEvents];
|
||||||
|
if (this.isEncrypted) {
|
||||||
|
stores.push(this._storage.storeNames.inboundGroupSessions);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
if (this._decryptEntries) {
|
||||||
|
const request = this._decryptEntries([entry], txn, log);
|
||||||
|
await request.complete();
|
||||||
|
}
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async _readFrom(eventKey, direction, amount, r, txn, log) {
|
async _readFrom(eventKey, direction, amount, r, txn, log) {
|
||||||
const entries = await readRawTimelineEntriesWithTxn(this._roomId, eventKey, direction, amount, this._fragmentIdComparer, txn);
|
const entries = await readRawTimelineEntriesWithTxn(this._roomId, eventKey, direction, amount, this._fragmentIdComparer, txn);
|
||||||
if (this._decryptEntries) {
|
if (this._decryptEntries) {
|
||||||
|
Loading…
Reference in New Issue
Block a user