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
+24 -1
View File
@@ -6,7 +6,14 @@ 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, Room, PendingEventOrdering } from "matrix-js-sdk/src/matrix";
import {
type MatrixClient,
Room,
PendingEventOrdering,
MatrixEvent,
Direction,
EventType,
} from "matrix-js-sdk/src/matrix";
import { type Member } from "../utils/direct-messages";
@@ -50,4 +57,20 @@ export class LocalRoom extends Room {
public get isError(): boolean {
return this.state === LocalRoomState.ERROR;
}
/**
* Check if encryption is enabled in this room.
* True if the room has any encryption state event
*/
public isEncryptionEnabled(): boolean {
const roomState = this.getLiveTimeline().getState(Direction.Forward);
if (!roomState) return false;
const stateEvents = roomState.getStateEvents(EventType.RoomEncryption);
if (stateEvents.length === 0) return false;
// if there is an encryption state event, it is encrypted.
// Regardless of the content/algorithm, we assume it is encrypted.
return stateEvents[0] instanceof MatrixEvent;
}
}