hydrogen-web/src/domain/session/room/timeline/tiles/GapTile.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-03-09 00:34:56 +05:30
import SimpleTile from "./SimpleTile";
export default class GapTile extends SimpleTile {
2019-03-09 05:10:03 +05:30
constructor(options, timeline) {
super(options);
2019-03-09 00:34:56 +05:30
this._timeline = timeline;
2019-03-09 05:10:03 +05:30
this._loading = false;
this._error = null;
2019-03-09 00:34:56 +05:30
}
2019-03-09 05:10:03 +05:30
async fill() {
// prevent doing this twice
if (!this._loading) {
this._loading = true;
this._emitUpdate("isLoading");
try {
return await this._timeline.fillGap(this._entry, 10);
} catch (err) {
this._loading = false;
this._error = err;
this._emitUpdate("isLoading");
this._emitUpdate("error");
}
}
}
get isLoading() {
return this._loading;
}
get direction() {
return this._entry.direction;
2019-03-09 05:10:03 +05:30
}
get error() {
if (this._error) {
const dir = this._entry.prev_batch ? "previous" : "next";
return `Could not load ${dir} messages: ${this._error.message}`;
}
return null;
2019-03-09 00:34:56 +05:30
}
}