feat: Add support for restricted join rule

This commit is contained in:
Christian Kußowski 2025-10-19 14:23:05 +02:00
parent 9eb1f4fc1e
commit d6dcbe0421
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
3 changed files with 56 additions and 8 deletions

View file

@ -3392,5 +3392,23 @@
"type": "int"
}
}
},
"spaceMemberOf": "Space member of {spaces}",
"@spaceMemberOf": {
"type": "String",
"placeholders": {
"spaces": {
"type": "String"
}
}
},
"spaceMemberOfCanKnock": "Space member of {spaces} can knock",
"@spaceMemberOfCanKnock": {
"type": "String",
"placeholders": {
"spaces": {
"type": "String"
}
}
}
}

View file

@ -26,6 +26,16 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
bool historyVisibilityLoading = false;
bool guestAccessLoading = false;
Room get room => Matrix.of(context).client.getRoomById(widget.roomId)!;
Set<Room> get knownSpaceParents => {
...room.client.rooms.where(
(space) =>
space.isSpace &&
space.spaceChildren.any((child) => child.roomId == room.id),
),
...room.spaceParents
.map((parent) => room.client.getRoomById(parent.roomId ?? ''))
.whereType<Room>(),
};
String get roomVersion =>
room
@ -46,9 +56,12 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
joinRules.remove(JoinRules.knock);
}
// Not yet supported in FluffyChat:
joinRules.remove(JoinRules.restricted);
joinRules.remove(JoinRules.knockRestricted);
if (knownSpaceParents.isEmpty) {
joinRules.remove(JoinRules.restricted);
if (roomVersionInt != null && roomVersionInt <= 6) {
joinRules.remove(JoinRules.knockRestricted);
}
}
// If an unsupported join rule is the current join rule, display it:
final currentJoinRule = room.joinRules;
@ -64,7 +77,13 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
});
try {
await room.setJoinRules(newJoinRules);
await room.setJoinRules(
newJoinRules,
allowConditionRoomId: {JoinRules.restricted, JoinRules.knockRestricted}
.contains(newJoinRules)
? knownSpaceParents.first.id
: null,
);
} catch (e, s) {
Logs().w('Unable to change join rules', e, s);
if (mounted) {

View file

@ -88,7 +88,10 @@ class ChatAccessSettingsPageView extends StatelessWidget {
enabled: !controller.joinRulesLoading &&
room.canChangeJoinRules,
title: Text(
joinRule.localizedString(L10n.of(context)),
joinRule.localizedString(
L10n.of(context),
controller.knownSpaceParents,
),
),
value: joinRule,
),
@ -280,7 +283,7 @@ class _AliasListTile extends StatelessWidget {
}
extension JoinRulesDisplayString on JoinRules {
String localizedString(L10n l10n) {
String localizedString(L10n l10n, Set<Room> spaceParents) {
switch (this) {
case JoinRules.public:
return l10n.anyoneCanJoin;
@ -291,9 +294,17 @@ extension JoinRulesDisplayString on JoinRules {
case JoinRules.private:
return l10n.noOneCanJoin;
case JoinRules.restricted:
return l10n.restricted;
return l10n.spaceMemberOf(
spaceParents
.map((space) => space.getLocalizedDisplayname(MatrixLocals(l10n)))
.join(', '),
);
case JoinRules.knockRestricted:
return l10n.knockRestricted;
return l10n.spaceMemberOfCanKnock(
spaceParents
.map((space) => space.getLocalizedDisplayname(MatrixLocals(l10n)))
.join(', '),
);
}
}
}