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 {UpdateAction} from "../UpdateAction.js";
|
2020-08-17 18:41:39 +05:30
|
|
|
import {ViewModel} from "../../../../ViewModel.js";
|
2021-02-26 15:10:08 +05:30
|
|
|
import {SendStatus} from "../../../../../matrix/room/sending/PendingEvent.js";
|
2019-06-13 01:27:13 +05:30
|
|
|
|
2020-08-17 18:41:39 +05:30
|
|
|
export class SimpleTile extends ViewModel {
|
2020-10-26 21:48:17 +05:30
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
this._entry = options.entry;
|
2019-03-09 00:34:56 +05:30
|
|
|
}
|
|
|
|
// view model props for all subclasses
|
|
|
|
// hmmm, could also do instanceof ... ?
|
|
|
|
get shape() {
|
2019-06-13 01:27:13 +05:30
|
|
|
return null;
|
2019-03-09 00:34:56 +05:30
|
|
|
// "gap" | "message" | "image" | ... ?
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't show display name / avatar
|
2021-05-17 15:45:13 +05:30
|
|
|
// probably only for BaseMessageTiles of some sort?
|
2019-03-09 00:34:56 +05:30
|
|
|
get isContinuation() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasDateSeparator() {
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-21 18:56:56 +05:30
|
|
|
|
|
|
|
get internalId() {
|
|
|
|
return this._entry.asEventKey().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
get isPending() {
|
|
|
|
return this._entry.isPending;
|
|
|
|
}
|
2020-11-19 00:36:34 +05:30
|
|
|
|
2021-02-26 15:10:08 +05:30
|
|
|
get isUnsent() {
|
|
|
|
return this._entry.isPending && this._entry.status !== SendStatus.Sent;
|
|
|
|
}
|
|
|
|
|
2020-11-19 00:36:34 +05:30
|
|
|
abortSending() {
|
|
|
|
this._entry.pendingEvent?.abort();
|
|
|
|
}
|
|
|
|
|
2020-03-21 18:58:09 +05:30
|
|
|
// TilesCollection contract below
|
|
|
|
setUpdateEmit(emitUpdate) {
|
2020-09-14 21:14:22 +05:30
|
|
|
this.updateOptions({emitChange: paramName => {
|
2021-03-09 02:53:52 +05:30
|
|
|
// it can happen that after some network call
|
|
|
|
// we switched away from the room and the response
|
|
|
|
// comes in, triggering an emitChange in a tile that
|
|
|
|
// has been disposed already (and hence the change
|
|
|
|
// callback has been cleared by dispose) We should just ignore this.
|
2020-09-14 21:14:22 +05:30
|
|
|
if (emitUpdate) {
|
|
|
|
emitUpdate(this, paramName);
|
|
|
|
}
|
|
|
|
}});
|
2020-03-21 18:58:09 +05:30
|
|
|
}
|
|
|
|
|
2019-06-01 21:59:02 +05:30
|
|
|
get upperEntry() {
|
|
|
|
return this._entry;
|
2019-03-09 00:34:56 +05:30
|
|
|
}
|
|
|
|
|
2019-06-01 21:59:02 +05:30
|
|
|
get lowerEntry() {
|
|
|
|
return this._entry;
|
2019-03-09 00:34:56 +05:30
|
|
|
}
|
|
|
|
|
2019-06-01 21:59:02 +05:30
|
|
|
compareEntry(entry) {
|
|
|
|
return this._entry.compare(entry);
|
2019-03-09 00:34:56 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// update received for already included (falls within sort keys) entry
|
2021-05-25 16:28:20 +05:30
|
|
|
updateEntry(entry, param) {
|
|
|
|
const renderedAsRedacted = this.shape === "redacted";
|
2021-05-27 12:40:10 +05:30
|
|
|
if (!entry.isGap && entry.isRedacted !== renderedAsRedacted) {
|
2021-05-20 16:45:35 +05:30
|
|
|
// recreate the tile if the entry becomes redacted
|
2021-05-25 16:28:20 +05:30
|
|
|
return UpdateAction.Replace("shape");
|
2021-05-20 16:45:35 +05:30
|
|
|
} else {
|
|
|
|
this._entry = entry;
|
2021-05-25 16:28:20 +05:30
|
|
|
return UpdateAction.Update(param);
|
2021-05-20 16:45:35 +05:30
|
|
|
}
|
2019-03-09 05:10:03 +05:30
|
|
|
}
|
2019-03-09 00:34:56 +05:30
|
|
|
|
2019-03-09 05:10:03 +05:30
|
|
|
// return whether the tile should be removed
|
|
|
|
// as SimpleTile only has one entry, the tile should be removed
|
|
|
|
removeEntry(entry) {
|
|
|
|
return true;
|
2019-03-09 00:34:56 +05:30
|
|
|
}
|
|
|
|
|
2019-03-09 05:10:03 +05:30
|
|
|
// SimpleTile can only contain 1 entry
|
2019-03-09 00:34:56 +05:30
|
|
|
tryIncludeEntry() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// let item know it has a new sibling
|
|
|
|
updatePreviousSibling(prev) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// let item know it has a new sibling
|
|
|
|
updateNextSibling(next) {
|
|
|
|
|
|
|
|
}
|
2020-09-14 21:14:22 +05:30
|
|
|
|
|
|
|
dispose() {
|
|
|
|
this.setUpdateEmit(null);
|
|
|
|
super.dispose();
|
|
|
|
}
|
2020-03-21 18:56:56 +05:30
|
|
|
// TilesCollection contract above
|
2021-05-20 18:23:17 +05:30
|
|
|
|
|
|
|
get _room() {
|
|
|
|
return this.getOption("room");
|
|
|
|
}
|
2021-05-31 17:22:03 +05:30
|
|
|
|
|
|
|
get _powerLevels() {
|
|
|
|
return this.getOption("timeline").powerLevels;
|
|
|
|
}
|
2019-03-09 00:34:56 +05:30
|
|
|
}
|