provide redact method on tile and room

also add some logging
This commit is contained in:
Bruno Windels 2021-05-20 14:53:17 +02:00
parent 9721432a8c
commit 8a8c5569dc
5 changed files with 19 additions and 4 deletions

View file

@ -97,4 +97,8 @@ export class BaseMessageTile extends SimpleTile {
this.emitChange("isContinuation");
}
}
redact(reason) {
this._room.sendRedaction(this._entry.id, reason);
}
}

View file

@ -24,10 +24,6 @@ export class GapTile extends SimpleTile {
this._error = null;
}
get _room() {
return this.getOption("room");
}
async fill() {
// prevent doing this twice
if (!this._loading) {

View file

@ -118,4 +118,8 @@ export class SimpleTile extends ViewModel {
super.dispose();
}
// TilesCollection contract above
get _room() {
return this.getOption("room");
}
}

View file

@ -297,6 +297,14 @@ export class Room extends BaseRoom {
});
}
/** @public */
sendRedaction(eventIdOrTxnId, reason, log = null) {
this._platform.logger.wrapOrRun(log, "redact", log => {
log.set("id", this.id);
return this._sendQueue.enqueueRedaction(eventIdOrTxnId, reason, log);
});
}
/** @public */
async ensureMessageKeyIsShared(log = null) {
if (!this._roomEncryption) {

View file

@ -201,6 +201,7 @@ export class SendQueue {
async enqueueRedaction(eventIdOrTxnId, reason, log) {
if (isTxnId(eventIdOrTxnId)) {
log.set("txnIdToRedact", eventIdOrTxnId);
const txnId = eventIdOrTxnId;
const pe = this._pendingEvents.array.find(pe => pe.txnId === txnId);
if (pe && !pe.remoteId && pe.status !== SendStatus.Sending) {
@ -216,6 +217,8 @@ export class SendQueue {
// and a bit complicated to fix.
return;
}
} else {
log.set("eventIdToRedact", eventIdOrTxnId);
}
await this._enqueueEvent(REDACTION_TYPE, {reason}, null, eventIdOrTxnId, log);
}