Skip to content

Commit 3a527b0

Browse files
committed
Allow room moderators to view redacted event content
Implements MSC2815 Signed-off-by: Tulir Asokan <[email protected]>
1 parent f963fea commit 3a527b0

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/client.ts

+26
Original file line numberDiff line numberDiff line change
@@ -7226,6 +7226,32 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
72267226
return this.http.authedRequest(callback, Method.Get, path);
72277227
}
72287228

7229+
/**
7230+
* Get the content of a redacted event event in a room by its event id.
7231+
* @param {string} roomId
7232+
* @param {string} eventId
7233+
* @param {module:client.callback} callback Optional.
7234+
*
7235+
* @return {Promise} Resolves to an object containing the event.
7236+
* @return {module:http-api.MatrixError} Rejects: with an error response.
7237+
*/
7238+
public unstableFetchRedactedRoomEventContent(
7239+
roomId: string,
7240+
eventId: string,
7241+
callback?: Callback,
7242+
): Promise<IMinimalEvent> {
7243+
const path = utils.encodeUri(
7244+
"/rooms/$roomId/event/$eventId", {
7245+
$roomId: roomId,
7246+
$eventId: eventId,
7247+
},
7248+
);
7249+
const query = {
7250+
"fi.mau.msc2815.include_unredacted_content": "true",
7251+
}
7252+
return this.http.authedRequest(callback, Method.Get, path, query);
7253+
}
7254+
72297255
/**
72307256
* @param {string} roomId
72317257
* @param {string} includeMembership the membership type to include in the response

src/models/event.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHan
284284
public error: MatrixError = null;
285285
public forwardLooking = true; // only state events may be backwards looking
286286

287+
/* flag to indicate that the event was redacted, but we fetched the
288+
* unredacted content from the server using room moderator powers.
289+
*/
290+
public viewingRedactedContent = false;
291+
287292
/* If the event is a `m.key.verification.request` (or to_device `m.key.verification.start`) event,
288293
* `Crypto` will set this the `VerificationRequest` for the event
289294
* so it can be easily accessed from the timeline.
@@ -1142,7 +1147,7 @@ export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHan
11421147
* @return {boolean} True if this event has been redacted
11431148
*/
11441149
public isRedacted(): boolean {
1145-
return Boolean(this.getUnsigned().redacted_because);
1150+
return Boolean(this.getUnsigned().redacted_because && !this.viewingRedactedContent);
11461151
}
11471152

11481153
/**
@@ -1267,6 +1272,19 @@ export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHan
12671272
this.localTimestamp = Date.now() - this.getAge();
12681273
}
12691274

1275+
public showRedactedContent(event: object): void {
1276+
const oldUnsigned = this.getUnsigned();
1277+
this.event = event;
1278+
this.clearEvent = undefined;
1279+
if (!this.event.unsigned) {
1280+
this.event.unsigned = {};
1281+
}
1282+
this.event.unsigned.redacted_because = oldUnsigned.redacted_because;
1283+
this.viewingRedactedContent = true;
1284+
this.setStatus(null);
1285+
this.localTimestamp = Date.now() - this.getAge();
1286+
}
1287+
12701288
/**
12711289
* Whether the event is in any phase of sending, send failure, waiting for
12721290
* remote echo, etc.

0 commit comments

Comments
 (0)