You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-06 12:02:40 +03:00
Fix spec compliance issue around encrypted m.relates_to
(#3178)
* Fix spec compliance issue around encrypted `m.relates_to` * Add test
This commit is contained in:
committed by
GitHub
parent
9c8093eb3e
commit
d80b7499fd
@@ -16,7 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import { MatrixEvent, MatrixEventEvent } from "../../../src/models/event";
|
import { MatrixEvent, MatrixEventEvent } from "../../../src/models/event";
|
||||||
import { emitPromise } from "../../test-utils/test-utils";
|
import { emitPromise } from "../../test-utils/test-utils";
|
||||||
import { Crypto } from "../../../src/crypto";
|
import { Crypto, IEventDecryptionResult } from "../../../src/crypto";
|
||||||
|
|
||||||
describe("MatrixEvent", () => {
|
describe("MatrixEvent", () => {
|
||||||
it("should create copies of itself", () => {
|
it("should create copies of itself", () => {
|
||||||
@@ -182,4 +182,38 @@ describe("MatrixEvent", () => {
|
|||||||
expect(encryptedEvent.getType()).toEqual("m.room.message");
|
expect(encryptedEvent.getType()).toEqual("m.room.message");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("replyEventId", () => {
|
||||||
|
it("should ignore 'm.relates_to' from encrypted content even if cleartext lacks one", async () => {
|
||||||
|
const eventId = "test_encrypted_event";
|
||||||
|
const encryptedEvent = new MatrixEvent({
|
||||||
|
event_id: eventId,
|
||||||
|
type: "m.room.encrypted",
|
||||||
|
content: {
|
||||||
|
ciphertext: "secrets",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const crypto = {
|
||||||
|
decryptEvent: jest.fn().mockImplementationOnce(() => {
|
||||||
|
return Promise.resolve<IEventDecryptionResult>({
|
||||||
|
clearEvent: {
|
||||||
|
type: "m.room.message",
|
||||||
|
content: {
|
||||||
|
"m.relates_to": {
|
||||||
|
"m.in_reply_to": {
|
||||||
|
event_id: "!anotherEvent",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
} as unknown as Crypto;
|
||||||
|
|
||||||
|
await encryptedEvent.attemptDecryption(crypto);
|
||||||
|
expect(encryptedEvent.getType()).toEqual("m.room.message");
|
||||||
|
expect(encryptedEvent.replyEventId).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -576,13 +576,7 @@ export class MatrixEvent extends TypedEventEmitter<MatrixEventEmittedEvents, Mat
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get replyEventId(): string | undefined {
|
public get replyEventId(): string | undefined {
|
||||||
// We're prefer ev.getContent() over ev.getWireContent() to make sure
|
return this.getWireContent()["m.relates_to"]?.["m.in_reply_to"]?.event_id;
|
||||||
// we grab the latest edit with potentially new relations. But we also
|
|
||||||
// can't just rely on ev.getContent() by itself because historically we
|
|
||||||
// still show the reply from the original message even though the edit
|
|
||||||
// event does not include the relation reply.
|
|
||||||
const mRelatesTo = this.getContent()["m.relates_to"] || this.getWireContent()["m.relates_to"];
|
|
||||||
return mRelatesTo?.["m.in_reply_to"]?.event_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get relationEventId(): string | undefined {
|
public get relationEventId(): string | undefined {
|
||||||
|
Reference in New Issue
Block a user