From 780ad44032b5e8a90933680f575de015ef076e89 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 20 May 2021 13:15:35 +0200 Subject: [PATCH] render redacted messages --- .../room/timeline/tiles/RedactedTile.js | 27 +++++++++++++++++++ .../session/room/timeline/tiles/SimpleTile.js | 9 +++++-- .../session/room/timeline/tilesCreator.js | 3 +++ .../room/timeline/entries/EventEntry.js | 4 +++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/domain/session/room/timeline/tiles/RedactedTile.js diff --git a/src/domain/session/room/timeline/tiles/RedactedTile.js b/src/domain/session/room/timeline/tiles/RedactedTile.js new file mode 100644 index 00000000..9349f06e --- /dev/null +++ b/src/domain/session/room/timeline/tiles/RedactedTile.js @@ -0,0 +1,27 @@ +/* +Copyright 2020 Bruno Windels + +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."; + } +} diff --git a/src/domain/session/room/timeline/tiles/SimpleTile.js b/src/domain/session/room/timeline/tiles/SimpleTile.js index ea5640bd..977e2410 100644 --- a/src/domain/session/room/timeline/tiles/SimpleTile.js +++ b/src/domain/session/room/timeline/tiles/SimpleTile.js @@ -84,8 +84,13 @@ export class SimpleTile extends ViewModel { // update received for already included (falls within sort keys) entry updateEntry(entry, params) { - this._entry = entry; - return UpdateAction.Update(params); + if (entry.isRedacted) { + // recreate the tile if the entry becomes redacted + return UpdateAction.Replace(params); + } else { + this._entry = entry; + return UpdateAction.Update(params); + } } // return whether the tile should be removed diff --git a/src/domain/session/room/timeline/tilesCreator.js b/src/domain/session/room/timeline/tilesCreator.js index ed43cd3a..af91cac7 100644 --- a/src/domain/session/room/timeline/tilesCreator.js +++ b/src/domain/session/room/timeline/tilesCreator.js @@ -16,6 +16,7 @@ limitations under the License. import {GapTile} from "./tiles/GapTile.js"; import {TextTile} from "./tiles/TextTile.js"; +import {RedactedTile} from "./tiles/RedactedTile.js"; import {ImageTile} from "./tiles/ImageTile.js"; import {VideoTile} from "./tiles/VideoTile.js"; import {FileTile} from "./tiles/FileTile.js"; @@ -31,6 +32,8 @@ export function tilesCreator(baseOptions) { const options = Object.assign({entry, emitUpdate}, baseOptions); if (entry.isGap) { return new GapTile(options); + } else if (entry.isRedacted) { + return new RedactedTile(options); } else if (entry.isPending && entry.pendingEvent.isMissingAttachments) { return new MissingAttachmentTile(options); } else if (entry.eventType) { diff --git a/src/matrix/room/timeline/entries/EventEntry.js b/src/matrix/room/timeline/entries/EventEntry.js index 5f2496d8..561c9f8e 100644 --- a/src/matrix/room/timeline/entries/EventEntry.js +++ b/src/matrix/room/timeline/entries/EventEntry.js @@ -112,4 +112,8 @@ export class EventEntry extends BaseEntry { get relatedEventId() { return this._eventEntry.event.redacts; } + + get isRedacted() { + return !!this._eventEntry.event.unsigned?.redacted_because; + } } \ No newline at end of file