forked from mystiq/hydrogen-web
implement reading n events from end of live fragment
This commit is contained in:
parent
3137f025c7
commit
f8fbfbff9a
2 changed files with 33 additions and 4 deletions
|
@ -19,8 +19,7 @@ export default class Timeline {
|
||||||
|
|
||||||
/** @package */
|
/** @package */
|
||||||
async load() {
|
async load() {
|
||||||
const txn = await this._storage.readTxn([this._storage.storeNames.timelineEvents]);
|
const entries = this._timelineReader.readFromEnd(100);
|
||||||
const entries = await txn.roomTimeline.lastEvents(this._roomId, 100);
|
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
this._entriesList.append(entry);
|
this._entriesList.append(entry);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {directionalConcat, directionalAppend} from "./common.js";
|
import {directionalConcat, directionalAppend} from "./common.js";
|
||||||
import EventKey from "../EventKey.js";
|
import EventKey from "../EventKey.js";
|
||||||
|
import Direction from "../Direction.js";
|
||||||
import EventEntry from "../entries/EventEntry.js";
|
import EventEntry from "../entries/EventEntry.js";
|
||||||
import FragmentBoundaryEntry from "../entries/FragmentBoundaryEntry.js";
|
import FragmentBoundaryEntry from "../entries/FragmentBoundaryEntry.js";
|
||||||
|
|
||||||
|
@ -10,11 +11,19 @@ export default class TimelineReader {
|
||||||
this._fragmentIdComparer = fragmentIdComparer;
|
this._fragmentIdComparer = fragmentIdComparer;
|
||||||
}
|
}
|
||||||
|
|
||||||
async readFrom(eventKey, direction, amount) {
|
_openTxn() {
|
||||||
const txn = this._storage.readTxn([
|
return this._storage.readTxn([
|
||||||
this._storage.storeNames.timelineEvents,
|
this._storage.storeNames.timelineEvents,
|
||||||
this._storage.storeNames.timelineFragments,
|
this._storage.storeNames.timelineFragments,
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async readFrom(eventKey, direction, amount) {
|
||||||
|
const txn = await this._openTxn();
|
||||||
|
return this._readFrom(eventKey, direction, amount, txn);
|
||||||
|
}
|
||||||
|
|
||||||
|
async _readFrom(eventKey, direction, amount, txn) {
|
||||||
let entries = [];
|
let entries = [];
|
||||||
|
|
||||||
const timelineStore = txn.timelineEvents;
|
const timelineStore = txn.timelineEvents;
|
||||||
|
@ -52,4 +61,25 @@ export default class TimelineReader {
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async readFromEnd(amount) {
|
||||||
|
const txn = await this._openTxn();
|
||||||
|
const liveFragment = await txn.timelineFragments.liveFragment(this._roomId);
|
||||||
|
// room hasn't been synced yet
|
||||||
|
if (!liveFragment) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
this._fragmentIdComparer.add(liveFragment);
|
||||||
|
const liveFragmentEntry = new FragmentBoundaryEntry(liveFragment, Direction.Forward, this._fragmentIdComparer);
|
||||||
|
const eventKey = new EventKey(liveFragmentEntry.fragmentId, liveFragmentEntry.eventIndex);
|
||||||
|
const entries = this._readFrom(eventKey, Direction.Backward, amount, txn);
|
||||||
|
entries.unshift(liveFragmentEntry);
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reads distance up and down from eventId
|
||||||
|
// or just expose eventIdToKey?
|
||||||
|
readAtEventId(eventId, distance) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue