render redacted messages

This commit is contained in:
Bruno Windels 2021-05-20 13:15:35 +02:00
parent 94b0bc82ef
commit 780ad44032
4 changed files with 41 additions and 2 deletions

View file

@ -0,0 +1,27 @@
/*
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.
*/
import {BaseTextTile} from "./BaseTextTile.js";
export class RedactedTile extends BaseTextTile {
get shape() {
return "message-status"
}
_getBodyAsString() {
return "This message has been deleted.";
}
}

View file

@ -84,9 +84,14 @@ export class SimpleTile extends ViewModel {
// update received for already included (falls within sort keys) entry // update received for already included (falls within sort keys) entry
updateEntry(entry, params) { updateEntry(entry, params) {
if (entry.isRedacted) {
// recreate the tile if the entry becomes redacted
return UpdateAction.Replace(params);
} else {
this._entry = entry; this._entry = entry;
return UpdateAction.Update(params); return UpdateAction.Update(params);
} }
}
// return whether the tile should be removed // return whether the tile should be removed
// as SimpleTile only has one entry, the tile should be removed // as SimpleTile only has one entry, the tile should be removed

View file

@ -16,6 +16,7 @@ limitations under the License.
import {GapTile} from "./tiles/GapTile.js"; import {GapTile} from "./tiles/GapTile.js";
import {TextTile} from "./tiles/TextTile.js"; import {TextTile} from "./tiles/TextTile.js";
import {RedactedTile} from "./tiles/RedactedTile.js";
import {ImageTile} from "./tiles/ImageTile.js"; import {ImageTile} from "./tiles/ImageTile.js";
import {VideoTile} from "./tiles/VideoTile.js"; import {VideoTile} from "./tiles/VideoTile.js";
import {FileTile} from "./tiles/FileTile.js"; import {FileTile} from "./tiles/FileTile.js";
@ -31,6 +32,8 @@ export function tilesCreator(baseOptions) {
const options = Object.assign({entry, emitUpdate}, baseOptions); const options = Object.assign({entry, emitUpdate}, baseOptions);
if (entry.isGap) { if (entry.isGap) {
return new GapTile(options); return new GapTile(options);
} else if (entry.isRedacted) {
return new RedactedTile(options);
} else if (entry.isPending && entry.pendingEvent.isMissingAttachments) { } else if (entry.isPending && entry.pendingEvent.isMissingAttachments) {
return new MissingAttachmentTile(options); return new MissingAttachmentTile(options);
} else if (entry.eventType) { } else if (entry.eventType) {

View file

@ -112,4 +112,8 @@ export class EventEntry extends BaseEntry {
get relatedEventId() { get relatedEventId() {
return this._eventEntry.event.redacts; return this._eventEntry.event.redacts;
} }
get isRedacted() {
return !!this._eventEntry.event.unsigned?.redacted_because;
}
} }