This repository has been archived on 2022-08-19. You can view files and clone it, but cannot push or open issues or pull requests.
hydrogen-web/src/domain/session/room/timeline/tiles/GapTile.js

63 lines
1.5 KiB
JavaScript
Raw Normal View History

import {SimpleTile} from "./SimpleTile.js";
import {UpdateAction} from "../UpdateAction.js";
2019-03-09 00:34:56 +05:30
export 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");
2019-03-09 05:10:03 +05:30
try {
2019-06-02 19:16:24 +05:30
await this._timeline.fillGap(this._entry, 10);
2019-03-09 05:10:03 +05:30
} catch (err) {
2019-06-02 19:16:24 +05:30
console.error(`timeline.fillGap(): ${err.message}:\n${err.stack}`);
2019-03-09 05:10:03 +05:30
this._error = err;
this.emitUpdate("error");
2019-06-02 19:16:24 +05:30
} finally {
this._loading = false;
this.emitUpdate("isLoading");
2019-03-09 05:10:03 +05:30
}
}
}
updateEntry(entry, params) {
super.updateEntry(entry, params);
if (!entry.isGap) {
return UpdateAction.Remove();
} else {
return UpdateAction.Nothing();
}
}
get shape() {
return "gap";
}
2019-03-09 05:10:03 +05:30
get isLoading() {
return this._loading;
}
get isUp() {
return this._entry.direction.isBackward;
}
get isDown() {
return this._entry.direction.isForward;
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
}
}