2021-05-17 14:57:30 +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.
|
|
|
|
*/
|
|
|
|
|
2021-05-17 15:44:15 +05:30
|
|
|
import {BaseMessageTile} from "./BaseMessageTile.js";
|
2021-05-17 14:57:30 +05:30
|
|
|
import {stringAsBody} from "../MessageBody.js";
|
2021-07-17 02:06:26 +05:30
|
|
|
import {createEnum} from "../../../../../utils/enum.js";
|
|
|
|
|
2021-07-17 02:16:25 +05:30
|
|
|
export const BodyFormat = createEnum("Plain", "Html");
|
2021-05-17 14:57:30 +05:30
|
|
|
|
2021-05-17 15:44:15 +05:30
|
|
|
export class BaseTextTile extends BaseMessageTile {
|
2021-05-17 14:57:30 +05:30
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
this._messageBody = null;
|
2021-07-17 02:06:26 +05:30
|
|
|
this._format = null
|
2021-05-17 14:57:30 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
get shape() {
|
|
|
|
return "message";
|
|
|
|
}
|
|
|
|
|
2021-07-17 02:51:39 +05:30
|
|
|
_parseBody(body) {
|
2021-07-17 02:58:18 +05:30
|
|
|
return stringAsBody(body);
|
2021-05-17 14:57:30 +05:30
|
|
|
}
|
|
|
|
|
2021-07-13 01:17:22 +05:30
|
|
|
_getBodyFormat() {
|
2021-07-17 02:16:25 +05:30
|
|
|
return BodyFormat.Plain;
|
2021-07-13 01:17:22 +05:30
|
|
|
}
|
|
|
|
|
2021-05-17 14:57:30 +05:30
|
|
|
get body() {
|
2021-07-07 04:44:04 +05:30
|
|
|
const body = this._getBody();
|
2021-07-13 01:17:22 +05:30
|
|
|
const format = this._getBodyFormat();
|
2021-07-17 02:23:14 +05:30
|
|
|
// body is a string, so we can check for difference by just
|
2021-05-17 14:57:30 +05:30
|
|
|
// doing an equality check
|
2021-07-07 04:44:04 +05:30
|
|
|
// Even if the body hasn't changed, but the format has, we need
|
|
|
|
// to re-fill our cache.
|
2021-07-17 02:06:26 +05:30
|
|
|
if (!this._messageBody || this._messageBody.sourceString !== body || this._format !== format) {
|
2021-05-17 14:57:30 +05:30
|
|
|
// body with markup is an array of parts,
|
|
|
|
// so we should not recreate it for the same body string,
|
|
|
|
// or else the equality check in the binding will always fail.
|
|
|
|
// So cache it here.
|
2021-07-13 01:17:22 +05:30
|
|
|
this._messageBody = this._parseBody(body, format);
|
2021-07-17 02:13:40 +05:30
|
|
|
this._format = format;
|
2021-05-17 14:57:30 +05:30
|
|
|
}
|
|
|
|
return this._messageBody;
|
|
|
|
}
|
|
|
|
}
|