Fix local room encryption status always not enabled (#30461)

* Fix local room encryption status always not enabled

* refactor: put back the e2e test after merge

* fix: look at e2eStatus in composer of local room

* doc: add docs to `LocalRoom.isEncryptionEnabled`

* test(e2e): check composer doesn't display unencrypted state

* test: update existing tests

* test(e2e): update existing tests

* refactor: move room encryption check in a dedicated function

* refactor: make `isEncryptionEnabled` cleaner

* test: add tests for `LocalRoom.isEncrypted`

* doc: fix `useIsEncrypted` comment

---------

Co-authored-by: Florian Duros <florian.duros@ormaz.fr>
This commit is contained in:
Valere Fedronic
2025-09-10 15:09:17 +00:00
committed by GitHub
co-authored by Florian Duros
parent 8a1fc65beb
commit cd7f1a0638
9 changed files with 106 additions and 35 deletions
+23 -1
View File
@@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
Please see LICENSE files in the repository root for full details.
*/
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
import { Direction, EventType, type MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
import { LocalRoom, LocalRoomState, LOCAL_ROOM_ID_PREFIX } from "../../../src/models/LocalRoom";
import { createTestClient } from "../../test-utils";
@@ -79,4 +79,26 @@ describe("LocalRoom", () => {
});
});
});
it("should return false for isEncryptionEnabled with no state", () => {
expect(room.isEncryptionEnabled()).toBe(false);
});
it("should return true for isEncryptionEnabled with an encryption state event", () => {
const encryptionEvent = new MatrixEvent({
type: EventType.RoomEncryption,
state_key: "",
content: {
algorithm: "m.megolm.v1.aes-sha2",
},
sender: "@test:localhost",
room_id: room.roomId,
event_id: "$test:localhost",
});
const roomState = room.getLiveTimeline().getState(Direction.Forward);
roomState?.setStateEvents([encryptionEvent]);
expect(room.isEncryptionEnabled()).toBe(true);
});
});