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";
|
2021-04-28 17:40:54 +05:30
|
|
|
import {getIdentifierColorNumber, avatarInitials, getAvatarHttpUrl} from "../../../../avatar.js";
|
2019-03-09 05:10:03 +05:30
|
|
|
|
2021-05-17 15:45:13 +05:30
|
|
|
export class BaseMessageTile extends SimpleTile {
|
2019-03-09 05:10:03 +05:30
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2019-07-29 23:23:07 +05:30
|
|
|
this._isOwn = this._entry.sender === options.ownUserId;
|
2020-08-19 13:57:27 +05:30
|
|
|
this._date = this._entry.timestamp ? new Date(this._entry.timestamp) : null;
|
2019-06-16 19:09:24 +05:30
|
|
|
this._isContinuation = false;
|
2019-03-09 05:10:03 +05:30
|
|
|
}
|
|
|
|
|
2020-10-28 22:07:45 +05:30
|
|
|
get _room() {
|
|
|
|
return this.getOption("room");
|
|
|
|
}
|
|
|
|
|
|
|
|
get _mediaRepository() {
|
|
|
|
return this._room.mediaRepository;
|
|
|
|
}
|
|
|
|
|
2020-09-11 15:13:40 +05:30
|
|
|
get displayName() {
|
|
|
|
return this._entry.displayName || this.sender;
|
|
|
|
}
|
|
|
|
|
2019-03-09 05:10:03 +05:30
|
|
|
get sender() {
|
2020-09-11 15:13:40 +05:30
|
|
|
return this._entry.sender;
|
2019-03-09 05:10:03 +05:30
|
|
|
}
|
|
|
|
|
2020-08-20 21:02:18 +05:30
|
|
|
// Avatar view model contract
|
2020-08-20 19:33:52 +05:30
|
|
|
get avatarColorNumber() {
|
2020-08-13 16:11:00 +05:30
|
|
|
return getIdentifierColorNumber(this._entry.sender);
|
|
|
|
}
|
|
|
|
|
2021-04-28 17:40:54 +05:30
|
|
|
avatarUrl(size) {
|
|
|
|
return getAvatarHttpUrl(this._entry.avatarUrl, size, this.platform, this._mediaRepository);
|
2020-08-20 19:33:52 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
get avatarLetter() {
|
|
|
|
return avatarInitials(this.sender);
|
|
|
|
}
|
|
|
|
|
2020-08-20 21:02:18 +05:30
|
|
|
get avatarTitle() {
|
2020-09-11 15:13:40 +05:30
|
|
|
return this.displayName;
|
2020-08-20 21:02:18 +05:30
|
|
|
}
|
|
|
|
|
2019-03-09 05:10:03 +05:30
|
|
|
get date() {
|
2020-08-19 13:57:27 +05:30
|
|
|
return this._date && this._date.toLocaleDateString({}, {month: "numeric", day: "numeric"});
|
2019-03-09 05:10:03 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
get time() {
|
2020-08-19 13:57:27 +05:30
|
|
|
return this._date && this._date.toLocaleTimeString({}, {hour: "numeric", minute: "2-digit"});
|
2019-03-09 05:10:03 +05:30
|
|
|
}
|
|
|
|
|
2019-06-16 14:23:23 +05:30
|
|
|
get isOwn() {
|
|
|
|
return this._isOwn;
|
|
|
|
}
|
|
|
|
|
2019-06-16 19:09:24 +05:30
|
|
|
get isContinuation() {
|
|
|
|
return this._isContinuation;
|
|
|
|
}
|
|
|
|
|
2020-09-08 14:20:39 +05:30
|
|
|
get isUnverified() {
|
|
|
|
return this._entry.isUnverified;
|
|
|
|
}
|
|
|
|
|
2019-03-09 05:10:03 +05:30
|
|
|
_getContent() {
|
2019-07-29 13:57:12 +05:30
|
|
|
return this._entry.content;
|
2019-03-09 05:10:03 +05:30
|
|
|
}
|
2019-06-16 19:09:24 +05:30
|
|
|
|
|
|
|
updatePreviousSibling(prev) {
|
|
|
|
super.updatePreviousSibling(prev);
|
2020-08-19 13:58:09 +05:30
|
|
|
let isContinuation = false;
|
2021-05-17 15:45:13 +05:30
|
|
|
if (prev && prev instanceof BaseMessageTile && prev.sender === this.sender) {
|
2020-08-19 13:58:09 +05:30
|
|
|
// timestamp is null for pending events
|
2020-10-26 20:14:11 +05:30
|
|
|
const myTimestamp = this._entry.timestamp || this.clock.now();
|
|
|
|
const otherTimestamp = prev._entry.timestamp || this.clock.now();
|
2020-08-19 13:58:09 +05:30
|
|
|
// other message was sent less than 5min ago
|
|
|
|
isContinuation = (myTimestamp - otherTimestamp) < (5 * 60 * 1000);
|
|
|
|
}
|
2019-06-16 19:09:24 +05:30
|
|
|
if (isContinuation !== this._isContinuation) {
|
|
|
|
this._isContinuation = isContinuation;
|
2020-08-17 18:41:39 +05:30
|
|
|
this.emitChange("isContinuation");
|
2019-06-16 19:09:24 +05:30
|
|
|
}
|
|
|
|
}
|
2021-05-20 18:23:17 +05:30
|
|
|
|
|
|
|
redact(reason) {
|
|
|
|
this._room.sendRedaction(this._entry.id, reason);
|
|
|
|
}
|
2019-03-09 05:10:03 +05:30
|
|
|
}
|