You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
Prune both clear & wire content on redaction (#2346)
This commit is contained in:
committed by
GitHub
parent
dea3f52fe9
commit
6b5f4aa0a9
@ -57,4 +57,31 @@ describe('MatrixEvent', () => {
|
|||||||
expect(a.toSnapshot().isEquivalentTo(a)).toBe(true);
|
expect(a.toSnapshot().isEquivalentTo(a)).toBe(true);
|
||||||
expect(a.toSnapshot().isEquivalentTo(b)).toBe(false);
|
expect(a.toSnapshot().isEquivalentTo(b)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should prune clearEvent when being redacted", () => {
|
||||||
|
const ev = new MatrixEvent({
|
||||||
|
type: "m.room.message",
|
||||||
|
content: {
|
||||||
|
body: "Test",
|
||||||
|
},
|
||||||
|
event_id: "$event1:server",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(ev.getContent().body).toBe("Test");
|
||||||
|
expect(ev.getWireContent().body).toBe("Test");
|
||||||
|
ev.makeEncrypted("m.room.encrypted", { ciphertext: "xyz" }, "", "");
|
||||||
|
expect(ev.getContent().body).toBe("Test");
|
||||||
|
expect(ev.getWireContent().body).toBeUndefined();
|
||||||
|
expect(ev.getWireContent().ciphertext).toBe("xyz");
|
||||||
|
|
||||||
|
const redaction = new MatrixEvent({
|
||||||
|
type: "m.room.redaction",
|
||||||
|
redacts: ev.getId(),
|
||||||
|
});
|
||||||
|
|
||||||
|
ev.makeRedacted(redaction);
|
||||||
|
expect(ev.getContent().body).toBeUndefined();
|
||||||
|
expect(ev.getWireContent().body).toBeUndefined();
|
||||||
|
expect(ev.getWireContent().ciphertext).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1112,23 +1112,21 @@ export class MatrixEvent extends TypedEventEmitter<EmittedEvents, MatrixEventHan
|
|||||||
}
|
}
|
||||||
this.event.unsigned.redacted_because = redactionEvent.event as IEvent;
|
this.event.unsigned.redacted_because = redactionEvent.event as IEvent;
|
||||||
|
|
||||||
let key;
|
for (const key in this.event) {
|
||||||
for (key in this.event) {
|
if (this.event.hasOwnProperty(key) && !REDACT_KEEP_KEYS.has(key)) {
|
||||||
if (!this.event.hasOwnProperty(key)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!REDACT_KEEP_KEYS.has(key)) {
|
|
||||||
delete this.event[key];
|
delete this.event[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the event is encrypted prune the decrypted bits
|
||||||
|
if (this.isEncrypted()) {
|
||||||
|
this.clearEvent = null;
|
||||||
|
}
|
||||||
|
|
||||||
const keeps = REDACT_KEEP_CONTENT_MAP[this.getType()] || {};
|
const keeps = REDACT_KEEP_CONTENT_MAP[this.getType()] || {};
|
||||||
const content = this.getContent();
|
const content = this.getContent();
|
||||||
for (key in content) {
|
for (const key in content) {
|
||||||
if (!content.hasOwnProperty(key)) {
|
if (content.hasOwnProperty(key) && !keeps[key]) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!keeps[key]) {
|
|
||||||
delete content[key];
|
delete content[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1589,7 +1587,7 @@ const REDACT_KEEP_KEYS = new Set([
|
|||||||
'content', 'unsigned', 'origin_server_ts',
|
'content', 'unsigned', 'origin_server_ts',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// a map from event type to the .content keys we keep when an event is redacted
|
// a map from state event type to the .content keys we keep when an event is redacted
|
||||||
const REDACT_KEEP_CONTENT_MAP = {
|
const REDACT_KEEP_CONTENT_MAP = {
|
||||||
[EventType.RoomMember]: { 'membership': 1 },
|
[EventType.RoomMember]: { 'membership': 1 },
|
||||||
[EventType.RoomCreate]: { 'creator': 1 },
|
[EventType.RoomCreate]: { 'creator': 1 },
|
||||||
|
Reference in New Issue
Block a user