2019-02-07 05:50:27 +05:30
|
|
|
import SortKey from "../../sortkey.js";
|
2019-01-09 15:36:09 +05:30
|
|
|
|
|
|
|
class TimelineStore {
|
2019-02-04 02:47:24 +05:30
|
|
|
constructor(timelineStore) {
|
|
|
|
this._timelineStore = timelineStore;
|
2019-01-09 15:36:09 +05:30
|
|
|
}
|
|
|
|
|
2019-02-04 02:47:24 +05:30
|
|
|
async lastEvents(roomId, amount) {
|
|
|
|
return this.eventsBefore(roomId, GapSortKey.maxKey());
|
2019-01-09 15:36:09 +05:30
|
|
|
}
|
|
|
|
|
2019-02-04 02:47:24 +05:30
|
|
|
async firstEvents(roomId, amount) {
|
|
|
|
return this.eventsAfter(roomId, GapSortKey.minKey());
|
2019-01-09 15:36:09 +05:30
|
|
|
}
|
|
|
|
|
2019-02-04 02:47:24 +05:30
|
|
|
eventsAfter(roomId, sortKey, amount) {
|
|
|
|
const range = IDBKeyRange.lowerBound([roomId, sortKey], true);
|
|
|
|
return this._timelineStore.selectLimit(range, amount);
|
2019-01-09 15:36:09 +05:30
|
|
|
}
|
|
|
|
|
2019-02-04 02:47:24 +05:30
|
|
|
async eventsBefore(roomId, sortKey, amount) {
|
|
|
|
const range = IDBKeyRange.upperBound([roomId, sortKey], true);
|
|
|
|
const events = await this._timelineStore.selectLimitReverse(range, amount);
|
2019-01-09 15:36:09 +05:30
|
|
|
events.reverse(); // because we fetched them backwards
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
|
|
|
// should this happen as part of a transaction that stores all synced in changes?
|
|
|
|
// e.g.:
|
|
|
|
// - timeline events for all rooms
|
|
|
|
// - latest sync token
|
|
|
|
// - new members
|
|
|
|
// - new room state
|
|
|
|
// - updated/new account data
|
2019-02-04 02:47:24 +05:30
|
|
|
|
|
|
|
appendGap(roomId, sortKey, gap) {
|
|
|
|
this._timelineStore.add({
|
2019-02-07 06:21:27 +05:30
|
|
|
roomId: roomId,
|
|
|
|
sortKey: sortKey,
|
2019-02-04 02:47:24 +05:30
|
|
|
content: {
|
|
|
|
event: null,
|
|
|
|
gap: gap,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
appendEvent(roomId, sortKey, event) {
|
|
|
|
this._timelineStore.add({
|
2019-02-07 06:21:27 +05:30
|
|
|
roomId: roomId,
|
|
|
|
sortKey: sortKey,
|
2019-02-04 02:47:24 +05:30
|
|
|
content: {
|
|
|
|
event: event,
|
|
|
|
gap: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async removeEvent(roomId, sortKey) {
|
|
|
|
this._timelineStore.delete([roomId, sortKey]);
|
2019-01-09 15:36:09 +05:30
|
|
|
}
|
|
|
|
}
|