mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
move fillGap to room
This commit is contained in:
parent
ae01a65b3c
commit
6d68ec1bac
@ -18,7 +18,7 @@ export default class RoomViewModel extends EventEmitter {
|
||||
this._room.on("change", this._onRoomChange);
|
||||
try {
|
||||
this._timeline = await this._room.openTimeline();
|
||||
this._timelineVM = new TimelineViewModel(this._timeline, this._ownUserId);
|
||||
this._timelineVM = new TimelineViewModel(this._room, this._timeline, this._ownUserId);
|
||||
this.emit("change", "timelineViewModel");
|
||||
} catch (err) {
|
||||
console.error(`room.openTimeline(): ${err.message}:\n${err.stack}`);
|
||||
|
@ -18,12 +18,12 @@ import TilesCollection from "./TilesCollection.js";
|
||||
import tilesCreator from "./tilesCreator.js";
|
||||
|
||||
export default class TimelineViewModel {
|
||||
constructor(timeline, ownUserId) {
|
||||
constructor(room, timeline, ownUserId) {
|
||||
this._timeline = timeline;
|
||||
// once we support sending messages we could do
|
||||
// timeline.entries.concat(timeline.pendingEvents)
|
||||
// for an ObservableList that also contains local echos
|
||||
this._tiles = new TilesCollection(timeline.entries, tilesCreator({timeline, ownUserId}));
|
||||
this._tiles = new TilesCollection(timeline.entries, tilesCreator({room, ownUserId}));
|
||||
}
|
||||
|
||||
// doesn't fill gaps, only loads stored entries/tiles
|
||||
|
@ -4,11 +4,11 @@ import LocationTile from "./tiles/LocationTile.js";
|
||||
import RoomNameTile from "./tiles/RoomNameTile.js";
|
||||
import RoomMemberTile from "./tiles/RoomMemberTile.js";
|
||||
|
||||
export default function ({timeline, ownUserId}) {
|
||||
export default function ({room, ownUserId}) {
|
||||
return function tilesCreator(entry, emitUpdate) {
|
||||
const options = {entry, emitUpdate, ownUserId};
|
||||
if (entry.isGap) {
|
||||
return new GapTile(options, timeline);
|
||||
return new GapTile(options, room);
|
||||
} else if (entry.eventType) {
|
||||
switch (entry.eventType) {
|
||||
case "m.room.message": {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import EventEmitter from "../../EventEmitter.js";
|
||||
import RoomSummary from "./summary.js";
|
||||
import SyncWriter from "./timeline/persistence/SyncWriter.js";
|
||||
import GapWriter from "./timeline/persistence/GapWriter.js";
|
||||
import Timeline from "./timeline/Timeline.js";
|
||||
import FragmentIdComparer from "./timeline/FragmentIdComparer.js";
|
||||
import SendQueue from "./sending/SendQueue.js";
|
||||
@ -58,6 +59,26 @@ export default class Room extends EventEmitter {
|
||||
this._sendQueue.enqueueEvent(eventType, content);
|
||||
}
|
||||
|
||||
|
||||
/** @public */
|
||||
async fillGap(fragmentEntry, amount) {
|
||||
const response = await this._hsApi.messages(this._roomId, {
|
||||
from: fragmentEntry.token,
|
||||
dir: fragmentEntry.direction.asApiString(),
|
||||
limit: amount,
|
||||
filter: {lazy_load_members: true}
|
||||
}).response();
|
||||
const gapWriter = new GapWriter({
|
||||
roomId: this._roomId,
|
||||
storage: this._storage,
|
||||
fragmentIdComparer: this._fragmentIdComparer
|
||||
});
|
||||
const newEntries = await gapWriter.writeFragmentFill(fragmentEntry, response);
|
||||
if (this._timeline) {
|
||||
this._timeline.addGapEntries(newEntries)
|
||||
}
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this._summary.name;
|
||||
}
|
||||
@ -73,7 +94,6 @@ export default class Room extends EventEmitter {
|
||||
this._timeline = new Timeline({
|
||||
roomId: this.id,
|
||||
storage: this._storage,
|
||||
hsApi: this._hsApi,
|
||||
fragmentIdComparer: this._fragmentIdComparer,
|
||||
pendingEvents: this._sendQueue.pendingEvents,
|
||||
closeCallback: () => this._timeline = null,
|
||||
|
@ -1,16 +1,14 @@
|
||||
import { SortedArray, MappedList, ConcatList } from "../../../observable/index.js";
|
||||
import Direction from "./Direction.js";
|
||||
import GapWriter from "./persistence/GapWriter.js";
|
||||
import TimelineReader from "./persistence/TimelineReader.js";
|
||||
import PendingEventEntry from "./entries/PendingEventEntry.js";
|
||||
|
||||
export default class Timeline {
|
||||
constructor({roomId, storage, closeCallback, fragmentIdComparer, pendingEvents, user, hsApi}) {
|
||||
constructor({roomId, storage, closeCallback, fragmentIdComparer, pendingEvents, user}) {
|
||||
this._roomId = roomId;
|
||||
this._storage = storage;
|
||||
this._closeCallback = closeCallback;
|
||||
this._fragmentIdComparer = fragmentIdComparer;
|
||||
this._hsApi = hsApi;
|
||||
this._remoteEntries = new SortedArray((a, b) => a.compare(b));
|
||||
this._timelineReader = new TimelineReader({
|
||||
roomId: this._roomId,
|
||||
@ -36,20 +34,8 @@ export default class Timeline {
|
||||
this._remoteEntries.setManySorted(newEntries);
|
||||
}
|
||||
|
||||
/** @public */
|
||||
async fillGap(fragmentEntry, amount) {
|
||||
const response = await this._hsApi.messages(this._roomId, {
|
||||
from: fragmentEntry.token,
|
||||
dir: fragmentEntry.direction.asApiString(),
|
||||
limit: amount,
|
||||
filter: {lazy_load_members: true}
|
||||
}).response();
|
||||
const gapWriter = new GapWriter({
|
||||
roomId: this._roomId,
|
||||
storage: this._storage,
|
||||
fragmentIdComparer: this._fragmentIdComparer
|
||||
});
|
||||
const newEntries = await gapWriter.writeFragmentFill(fragmentEntry, response);
|
||||
/** @package */
|
||||
addGapEntries(newEntries) {
|
||||
this._remoteEntries.setManySorted(newEntries);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user