2020-08-05 22:08:55 +05:30
|
|
|
/*
|
|
|
|
Copyright 2020 Bruno Windels <bruno@windels.cloud>
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-04-21 00:56:39 +05:30
|
|
|
import {SimpleTile} from "./SimpleTile.js";
|
|
|
|
import {UpdateAction} from "../UpdateAction.js";
|
2019-03-09 00:34:56 +05:30
|
|
|
|
2020-04-21 00:56:39 +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;
|
2020-08-17 18:41:39 +05:30
|
|
|
this.emitChange("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;
|
2020-08-17 18:41:39 +05:30
|
|
|
this.emitChange("error");
|
2020-08-20 18:58:22 +05:30
|
|
|
// rethrow so caller of this method
|
|
|
|
// knows not to keep calling this for now
|
|
|
|
throw err;
|
2019-06-02 19:16:24 +05:30
|
|
|
} finally {
|
|
|
|
this._loading = false;
|
2020-08-17 18:41:39 +05:30
|
|
|
this.emitChange("isLoading");
|
2019-03-09 05:10:03 +05:30
|
|
|
}
|
|
|
|
}
|
2020-08-17 21:11:10 +05:30
|
|
|
// edgeReached will have been updated by fillGap
|
|
|
|
return this._entry.edgeReached;
|
2019-03-09 05:10:03 +05:30
|
|
|
}
|
|
|
|
|
2019-06-16 20:17:56 +05:30
|
|
|
updateEntry(entry, params) {
|
|
|
|
super.updateEntry(entry, params);
|
2019-06-13 01:27:13 +05:30
|
|
|
if (!entry.isGap) {
|
|
|
|
return UpdateAction.Remove();
|
|
|
|
} else {
|
|
|
|
return UpdateAction.Nothing();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 03:33:55 +05:30
|
|
|
get shape() {
|
|
|
|
return "gap";
|
|
|
|
}
|
|
|
|
|
2019-03-09 05:10:03 +05:30
|
|
|
get isLoading() {
|
|
|
|
return this._loading;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|