Strip relates_to from encrypted events' original contents.
This commit is contained in:
parent
fa985f8f16
commit
2375bf061c
2 changed files with 15 additions and 11 deletions
|
@ -28,9 +28,7 @@ export const SendStatus = createEnum(
|
||||||
"Error",
|
"Error",
|
||||||
);
|
);
|
||||||
|
|
||||||
const preservedContentFields = {
|
const preservedContentFields = [ "m.relates_to" ];
|
||||||
"m.room.message": [ "m.relates_to" ]
|
|
||||||
};
|
|
||||||
|
|
||||||
export class PendingEvent {
|
export class PendingEvent {
|
||||||
constructor({data, remove, emitUpdate, attachments}) {
|
constructor({data, remove, emitUpdate, attachments}) {
|
||||||
|
@ -100,14 +98,19 @@ export class PendingEvent {
|
||||||
this._emitUpdate("status");
|
this._emitUpdate("status");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get cleanedContent() {
|
||||||
|
const content = Object.assign({}, this._data.content);
|
||||||
|
for (const field of preservedContentFields) {
|
||||||
|
delete content[field];
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
_preserveContentFields(into) {
|
_preserveContentFields(into) {
|
||||||
const preservedFields = preservedContentFields[this.eventType];
|
const content = this._data.content;
|
||||||
if (preservedFields) {
|
for (const field of preservedContentFields) {
|
||||||
const content = this._data.content;
|
if (content[field] !== undefined) {
|
||||||
for (const field of preservedFields) {
|
into[field] = content[field];
|
||||||
if (content[field] !== undefined) {
|
|
||||||
into[field] = content[field];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,8 +97,9 @@ export class SendQueue {
|
||||||
}
|
}
|
||||||
if (pendingEvent.needsEncryption) {
|
if (pendingEvent.needsEncryption) {
|
||||||
pendingEvent.setEncrypting();
|
pendingEvent.setEncrypting();
|
||||||
|
const cleanedContent = pendingEvent.cleanedContent;
|
||||||
const {type, content} = await log.wrap("encrypt", log => this._roomEncryption.encrypt(
|
const {type, content} = await log.wrap("encrypt", log => this._roomEncryption.encrypt(
|
||||||
pendingEvent.eventType, pendingEvent.content, this._hsApi, log));
|
pendingEvent.eventType, cleanedContent, this._hsApi, log));
|
||||||
pendingEvent.setEncrypted(type, content);
|
pendingEvent.setEncrypted(type, content);
|
||||||
await this._tryUpdateEvent(pendingEvent);
|
await this._tryUpdateEvent(pendingEvent);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue