From fcd3227ef568ddf5a6d97838cb39c4576c548356 Mon Sep 17 00:00:00 2001 From: Krille Date: Wed, 24 Jul 2024 08:37:16 +0200 Subject: [PATCH] fix: Display only available join rules --- .../chat_access_settings_controller.dart | 30 +++++++++++++++++++ .../chat_access_settings_page.dart | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/pages/chat_access_settings/chat_access_settings_controller.dart b/lib/pages/chat_access_settings/chat_access_settings_controller.dart index c0ab1fa7a..fd7624790 100644 --- a/lib/pages/chat_access_settings/chat_access_settings_controller.dart +++ b/lib/pages/chat_access_settings/chat_access_settings_controller.dart @@ -24,6 +24,36 @@ class ChatAccessSettingsController extends State { bool guestAccessLoading = false; Room get room => Matrix.of(context).client.getRoomById(widget.roomId)!; + String get roomVersion => + room + .getState(EventTypes.RoomCreate)! + .content + .tryGet('room_version') ?? + 'Unknown'; + + /// Calculates which join rules are available based on the information on + /// https://spec.matrix.org/v1.11/rooms/#feature-matrix + List get availableJoinRules { + final joinRules = Set.from(JoinRules.values); + + final roomVersionInt = int.tryParse(roomVersion); + + // Knock is only supported for rooms up from version 7: + if (roomVersionInt != null && roomVersionInt <= 6) { + joinRules.remove(JoinRules.knock); + } + + // Not yet supported in FluffyChat: + joinRules.remove(JoinRules.restricted); + joinRules.remove(JoinRules.knockRestricted); + + // If an unsupported join rule is the current join rule, display it: + final currentJoinRule = room.joinRules; + if (currentJoinRule != null) joinRules.add(currentJoinRule); + + return joinRules.toList(); + } + void setJoinRule(JoinRules? newJoinRules) async { if (newJoinRules == null) return; setState(() { diff --git a/lib/pages/chat_access_settings/chat_access_settings_page.dart b/lib/pages/chat_access_settings/chat_access_settings_page.dart index 7de6f3793..c23d9dc6b 100644 --- a/lib/pages/chat_access_settings/chat_access_settings_page.dart +++ b/lib/pages/chat_access_settings/chat_access_settings_page.dart @@ -66,7 +66,7 @@ class ChatAccessSettingsPageView extends StatelessWidget { ), ), ), - for (final joinRule in JoinRules.values) + for (final joinRule in controller.availableJoinRules) if (joinRule != JoinRules.private) RadioListTile.adaptive( title: Text(