mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
draft of how to implement filling a timeline gap
This commit is contained in:
parent
1757a27475
commit
ec925d7c49
@ -17,9 +17,9 @@ export default class RoomPersister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// async persistGapFill(...) {
|
async persistGapFill(gapEntry, response) {
|
||||||
|
throw new Error("not yet implemented");
|
||||||
// }
|
}
|
||||||
|
|
||||||
persistSync(roomResponse, txn) {
|
persistSync(roomResponse, txn) {
|
||||||
let nextKey = this._lastSortKey;
|
let nextKey = this._lastSortKey;
|
||||||
|
@ -4,10 +4,11 @@ import RoomPersister from "./persister.js";
|
|||||||
import Timeline from "./timeline.js";
|
import Timeline from "./timeline.js";
|
||||||
|
|
||||||
export default class Room extends EventEmitter {
|
export default class Room extends EventEmitter {
|
||||||
constructor(roomId, storage, emitCollectionChange) {
|
constructor({roomId, storage, hsApi, emitCollectionChange}) {
|
||||||
super();
|
super();
|
||||||
this._roomId = roomId;
|
this._roomId = roomId;
|
||||||
this._storage = storage;
|
this._storage = storage;
|
||||||
|
this._hsApi = hsApi;
|
||||||
this._summary = new RoomSummary(roomId);
|
this._summary = new RoomSummary(roomId);
|
||||||
this._persister = new RoomPersister(roomId);
|
this._persister = new RoomPersister(roomId);
|
||||||
this._emitCollectionChange = emitCollectionChange;
|
this._emitCollectionChange = emitCollectionChange;
|
||||||
@ -50,6 +51,8 @@ export default class Room extends EventEmitter {
|
|||||||
this._timeline = new Timeline({
|
this._timeline = new Timeline({
|
||||||
roomId: this.id,
|
roomId: this.id,
|
||||||
storage: this._storage,
|
storage: this._storage,
|
||||||
|
persister: this._persister,
|
||||||
|
hsApi: this._hsApi,
|
||||||
closeCallback: () => this._timeline = null,
|
closeCallback: () => this._timeline = null,
|
||||||
});
|
});
|
||||||
await this._timeline.load();
|
await this._timeline.load();
|
||||||
|
@ -24,6 +24,30 @@ export default class Timeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
async fillGap(gapEntry, amount) {
|
||||||
|
const gap = gapEntry.gap;
|
||||||
|
let direction;
|
||||||
|
if (gap.prev_batch) {
|
||||||
|
direction = "b";
|
||||||
|
} else if (gap.next_batch) {
|
||||||
|
direction = "f";
|
||||||
|
} else {
|
||||||
|
throw new Error("Invalid gap, no prev_batch or next_batch field: " + JSON.stringify(gapEntry.gap));
|
||||||
|
}
|
||||||
|
const token = gap.prev_batch || gap.next_batch;
|
||||||
|
|
||||||
|
const response = await this._hsApi.messages({
|
||||||
|
roomId: this._roomId,
|
||||||
|
from: token,
|
||||||
|
dir: direction,
|
||||||
|
limit: amount
|
||||||
|
});
|
||||||
|
const newEntries = await this._persister.persistGapFill(gapEntry, response);
|
||||||
|
// find where to replace existing gap with newEntries by doing binary search
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
get entries() {
|
get entries() {
|
||||||
return this._entriesList;
|
return this._entriesList;
|
||||||
|
@ -2,8 +2,10 @@ import Room from "./room/room.js";
|
|||||||
import { ObservableMap } from "../observable/index.js";
|
import { ObservableMap } from "../observable/index.js";
|
||||||
|
|
||||||
export default class Session {
|
export default class Session {
|
||||||
constructor({storage, sessionInfo}) {
|
// sessionInfo contains deviceId, userId and homeServer
|
||||||
|
constructor({storage, hsApi, sessionInfo}) {
|
||||||
this._storage = storage;
|
this._storage = storage;
|
||||||
|
this._hsApi = hsApi;
|
||||||
this._session = null;
|
this._session = null;
|
||||||
this._sessionInfo = sessionInfo;
|
this._sessionInfo = sessionInfo;
|
||||||
this._rooms = new ObservableMap();
|
this._rooms = new ObservableMap();
|
||||||
@ -36,7 +38,12 @@ export default class Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createRoom(roomId) {
|
createRoom(roomId) {
|
||||||
const room = new Room(roomId, this._storage, this._roomUpdateCallback);
|
const room = new Room({
|
||||||
|
roomId,
|
||||||
|
storage: this._storage,
|
||||||
|
emitCollectionChange: this._roomUpdateCallback,
|
||||||
|
hsApi: this._hsApi,
|
||||||
|
});
|
||||||
this._rooms.add(roomId, room);
|
this._rooms.add(roomId, room);
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user