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);
|
this._room.on("change", this._onRoomChange);
|
||||||
try {
|
try {
|
||||||
this._timeline = await this._room.openTimeline();
|
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");
|
this.emit("change", "timelineViewModel");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`room.openTimeline(): ${err.message}:\n${err.stack}`);
|
console.error(`room.openTimeline(): ${err.message}:\n${err.stack}`);
|
||||||
|
@ -18,12 +18,12 @@ import TilesCollection from "./TilesCollection.js";
|
|||||||
import tilesCreator from "./tilesCreator.js";
|
import tilesCreator from "./tilesCreator.js";
|
||||||
|
|
||||||
export default class TimelineViewModel {
|
export default class TimelineViewModel {
|
||||||
constructor(timeline, ownUserId) {
|
constructor(room, timeline, ownUserId) {
|
||||||
this._timeline = timeline;
|
this._timeline = timeline;
|
||||||
// once we support sending messages we could do
|
// once we support sending messages we could do
|
||||||
// timeline.entries.concat(timeline.pendingEvents)
|
// timeline.entries.concat(timeline.pendingEvents)
|
||||||
// for an ObservableList that also contains local echos
|
// 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
|
// 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 RoomNameTile from "./tiles/RoomNameTile.js";
|
||||||
import RoomMemberTile from "./tiles/RoomMemberTile.js";
|
import RoomMemberTile from "./tiles/RoomMemberTile.js";
|
||||||
|
|
||||||
export default function ({timeline, ownUserId}) {
|
export default function ({room, ownUserId}) {
|
||||||
return function tilesCreator(entry, emitUpdate) {
|
return function tilesCreator(entry, emitUpdate) {
|
||||||
const options = {entry, emitUpdate, ownUserId};
|
const options = {entry, emitUpdate, ownUserId};
|
||||||
if (entry.isGap) {
|
if (entry.isGap) {
|
||||||
return new GapTile(options, timeline);
|
return new GapTile(options, room);
|
||||||
} else if (entry.eventType) {
|
} else if (entry.eventType) {
|
||||||
switch (entry.eventType) {
|
switch (entry.eventType) {
|
||||||
case "m.room.message": {
|
case "m.room.message": {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import EventEmitter from "../../EventEmitter.js";
|
import EventEmitter from "../../EventEmitter.js";
|
||||||
import RoomSummary from "./summary.js";
|
import RoomSummary from "./summary.js";
|
||||||
import SyncWriter from "./timeline/persistence/SyncWriter.js";
|
import SyncWriter from "./timeline/persistence/SyncWriter.js";
|
||||||
|
import GapWriter from "./timeline/persistence/GapWriter.js";
|
||||||
import Timeline from "./timeline/Timeline.js";
|
import Timeline from "./timeline/Timeline.js";
|
||||||
import FragmentIdComparer from "./timeline/FragmentIdComparer.js";
|
import FragmentIdComparer from "./timeline/FragmentIdComparer.js";
|
||||||
import SendQueue from "./sending/SendQueue.js";
|
import SendQueue from "./sending/SendQueue.js";
|
||||||
@ -58,6 +59,26 @@ export default class Room extends EventEmitter {
|
|||||||
this._sendQueue.enqueueEvent(eventType, content);
|
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() {
|
get name() {
|
||||||
return this._summary.name;
|
return this._summary.name;
|
||||||
}
|
}
|
||||||
@ -73,7 +94,6 @@ 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,
|
||||||
hsApi: this._hsApi,
|
|
||||||
fragmentIdComparer: this._fragmentIdComparer,
|
fragmentIdComparer: this._fragmentIdComparer,
|
||||||
pendingEvents: this._sendQueue.pendingEvents,
|
pendingEvents: this._sendQueue.pendingEvents,
|
||||||
closeCallback: () => this._timeline = null,
|
closeCallback: () => this._timeline = null,
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
import { SortedArray, MappedList, ConcatList } from "../../../observable/index.js";
|
import { SortedArray, MappedList, ConcatList } from "../../../observable/index.js";
|
||||||
import Direction from "./Direction.js";
|
import Direction from "./Direction.js";
|
||||||
import GapWriter from "./persistence/GapWriter.js";
|
|
||||||
import TimelineReader from "./persistence/TimelineReader.js";
|
import TimelineReader from "./persistence/TimelineReader.js";
|
||||||
import PendingEventEntry from "./entries/PendingEventEntry.js";
|
import PendingEventEntry from "./entries/PendingEventEntry.js";
|
||||||
|
|
||||||
export default class Timeline {
|
export default class Timeline {
|
||||||
constructor({roomId, storage, closeCallback, fragmentIdComparer, pendingEvents, user, hsApi}) {
|
constructor({roomId, storage, closeCallback, fragmentIdComparer, pendingEvents, user}) {
|
||||||
this._roomId = roomId;
|
this._roomId = roomId;
|
||||||
this._storage = storage;
|
this._storage = storage;
|
||||||
this._closeCallback = closeCallback;
|
this._closeCallback = closeCallback;
|
||||||
this._fragmentIdComparer = fragmentIdComparer;
|
this._fragmentIdComparer = fragmentIdComparer;
|
||||||
this._hsApi = hsApi;
|
|
||||||
this._remoteEntries = new SortedArray((a, b) => a.compare(b));
|
this._remoteEntries = new SortedArray((a, b) => a.compare(b));
|
||||||
this._timelineReader = new TimelineReader({
|
this._timelineReader = new TimelineReader({
|
||||||
roomId: this._roomId,
|
roomId: this._roomId,
|
||||||
@ -36,23 +34,11 @@ export default class Timeline {
|
|||||||
this._remoteEntries.setManySorted(newEntries);
|
this._remoteEntries.setManySorted(newEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @public */
|
/** @package */
|
||||||
async fillGap(fragmentEntry, amount) {
|
addGapEntries(newEntries) {
|
||||||
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);
|
|
||||||
this._remoteEntries.setManySorted(newEntries);
|
this._remoteEntries.setManySorted(newEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
// tries to prepend `amount` entries to the `entries` list.
|
// tries to prepend `amount` entries to the `entries` list.
|
||||||
async loadAtTop(amount) {
|
async loadAtTop(amount) {
|
||||||
const firstEventEntry = this._remoteEntries.array.find(e => !!e.eventType);
|
const firstEventEntry = this._remoteEntries.array.find(e => !!e.eventType);
|
||||||
|
Loading…
Reference in New Issue
Block a user