Skip to content

Commit

Permalink
Allow room moderators to view redacted event content
Browse files Browse the repository at this point in the history
Implements MSC2815

Signed-off-by: Tulir Asokan <[email protected]>
  • Loading branch information
tulir committed Apr 8, 2022
1 parent f963fea commit 3a527b0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7226,6 +7226,32 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
return this.http.authedRequest(callback, Method.Get, path);
}

/**
* Get the content of a redacted event event in a room by its event id.
* @param {string} roomId
* @param {string} eventId
* @param {module:client.callback} callback Optional.
*
* @return {Promise} Resolves to an object containing the event.
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
public unstableFetchRedactedRoomEventContent(
roomId: string,
eventId: string,
callback?: Callback,
): Promise<IMinimalEvent> {
const path = utils.encodeUri(
"/rooms/$roomId/event/$eventId", {
$roomId: roomId,
$eventId: eventId,
},
);
const query = {
"fi.mau.msc2815.include_unredacted_content": "true",
}
return this.http.authedRequest(callback, Method.Get, path, query);
}

/**
* @param {string} roomId
* @param {string} includeMembership the membership type to include in the response
Expand Down
20 changes: 19 additions & 1 deletion src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHan
public error: MatrixError = null;
public forwardLooking = true; // only state events may be backwards looking

/* flag to indicate that the event was redacted, but we fetched the
* unredacted content from the server using room moderator powers.
*/
public viewingRedactedContent = false;

/* If the event is a `m.key.verification.request` (or to_device `m.key.verification.start`) event,
* `Crypto` will set this the `VerificationRequest` for the event
* so it can be easily accessed from the timeline.
Expand Down Expand Up @@ -1142,7 +1147,7 @@ export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHan
* @return {boolean} True if this event has been redacted
*/
public isRedacted(): boolean {
return Boolean(this.getUnsigned().redacted_because);
return Boolean(this.getUnsigned().redacted_because && !this.viewingRedactedContent);
}

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

public showRedactedContent(event: object): void {
const oldUnsigned = this.getUnsigned();
this.event = event;
this.clearEvent = undefined;
if (!this.event.unsigned) {
this.event.unsigned = {};
}
this.event.unsigned.redacted_because = oldUnsigned.redacted_because;
this.viewingRedactedContent = true;
this.setStatus(null);
this.localTimestamp = Date.now() - this.getAge();
}

/**
* Whether the event is in any phase of sending, send failure, waiting for
* remote echo, etc.
Expand Down

0 comments on commit 3a527b0

Please sign in to comment.