Add support for restricted join rule
This commit is contained in:
parent
0f65f3e7f5
commit
7cab2cba7c
|
|
@ -3154,6 +3154,24 @@
|
||||||
},
|
},
|
||||||
"restricted": "Restricted",
|
"restricted": "Restricted",
|
||||||
"@restricted": {},
|
"@restricted": {},
|
||||||
|
},
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
},
|
||||||
"knockRestricted": "Knock restricted",
|
"knockRestricted": "Knock restricted",
|
||||||
"@knockRestricted": {},
|
"@knockRestricted": {},
|
||||||
"goToSpace": "Go to space: {space}",
|
"goToSpace": "Go to space: {space}",
|
||||||
|
|
|
||||||
|
|
@ -3154,6 +3154,24 @@
|
||||||
"space": {}
|
"space": {}
|
||||||
},
|
},
|
||||||
"markAsUnread": "Отметить как непрочитанное",
|
"markAsUnread": "Отметить как непрочитанное",
|
||||||
|
|
||||||
|
"spaceMemberOf": "Участники пространства {spaces}",
|
||||||
|
"@spaceMemberOf": {
|
||||||
|
"type": "String",
|
||||||
|
"placeholders": {
|
||||||
|
"spaces": {
|
||||||
|
"type": "String"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"spaceMemberOfCanKnock": "Участники пространства {spaces} (по запросу)",
|
||||||
|
"@spaceMemberOfCanKnock": {
|
||||||
|
"type": "String",
|
||||||
|
"placeholders": {
|
||||||
|
"spaces": {
|
||||||
|
"type": "String"
|
||||||
|
}
|
||||||
|
},
|
||||||
"userLevel": "{level} - Пользователь",
|
"userLevel": "{level} - Пользователь",
|
||||||
"@userLevel": {
|
"@userLevel": {
|
||||||
"type": "String",
|
"type": "String",
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,16 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
|
||||||
bool historyVisibilityLoading = false;
|
bool historyVisibilityLoading = false;
|
||||||
bool guestAccessLoading = false;
|
bool guestAccessLoading = false;
|
||||||
Room get room => Matrix.of(context).client.getRoomById(widget.roomId)!;
|
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 =>
|
String get roomVersion =>
|
||||||
room
|
room
|
||||||
|
|
@ -46,9 +56,12 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
|
||||||
joinRules.remove(JoinRules.knock);
|
joinRules.remove(JoinRules.knock);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not yet supported in FluffyChat:
|
if (knownSpaceParents.isEmpty) {
|
||||||
joinRules.remove(JoinRules.restricted);
|
joinRules.remove(JoinRules.restricted);
|
||||||
joinRules.remove(JoinRules.knockRestricted);
|
if (roomVersionInt != null && roomVersionInt <= 6) {
|
||||||
|
joinRules.remove(JoinRules.knockRestricted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If an unsupported join rule is the current join rule, display it:
|
// If an unsupported join rule is the current join rule, display it:
|
||||||
final currentJoinRule = room.joinRules;
|
final currentJoinRule = room.joinRules;
|
||||||
|
|
@ -64,7 +77,13 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await room.setJoinRules(newJoinRules);
|
await room.setJoinRules(
|
||||||
|
newJoinRules,
|
||||||
|
allowConditionRoomId: {JoinRules.restricted, JoinRules.knockRestricted}
|
||||||
|
.contains(newJoinRules)
|
||||||
|
? knownSpaceParents.first.id
|
||||||
|
: null,
|
||||||
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().w('Unable to change join rules', e, s);
|
Logs().w('Unable to change join rules', e, s);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
|
|
@ -297,4 +316,4 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ChatAccessSettingsPageView(this);
|
return ChatAccessSettingsPageView(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -45,19 +45,27 @@ class ChatAccessSettingsPageView extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
for (final historyVisibility in HistoryVisibility.values)
|
RadioGroup<HistoryVisibility>(
|
||||||
RadioListTile<HistoryVisibility>.adaptive(
|
groupValue: room.historyVisibility,
|
||||||
title: Text(
|
onChanged: controller.historyVisibilityLoading ||
|
||||||
historyVisibility
|
!room.canChangeHistoryVisibility
|
||||||
.getLocalizedString(MatrixLocals(L10n.of(context))),
|
? (_) {}
|
||||||
),
|
: controller.setHistoryVisibility,
|
||||||
value: historyVisibility,
|
child: Column(
|
||||||
groupValue: room.historyVisibility,
|
mainAxisSize: MainAxisSize.min,
|
||||||
onChanged: controller.historyVisibilityLoading ||
|
children: [
|
||||||
!room.canChangeHistoryVisibility
|
for (final historyVisibility in HistoryVisibility.values)
|
||||||
? null
|
RadioListTile<HistoryVisibility>.adaptive(
|
||||||
: controller.setHistoryVisibility,
|
title: Text(
|
||||||
|
historyVisibility.getLocalizedString(
|
||||||
|
MatrixLocals(L10n.of(context)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
value: historyVisibility,
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
Divider(color: theme.dividerColor),
|
Divider(color: theme.dividerColor),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
|
|
@ -68,19 +76,28 @@ class ChatAccessSettingsPageView extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
for (final joinRule in controller.availableJoinRules)
|
RadioGroup(
|
||||||
if (joinRule != JoinRules.private)
|
groupValue: room.joinRules,
|
||||||
RadioListTile<JoinRules>.adaptive(
|
onChanged: controller.setJoinRule,
|
||||||
title: Text(
|
child: Column(
|
||||||
joinRule.localizedString(L10n.of(context)),
|
mainAxisSize: MainAxisSize.min,
|
||||||
),
|
children: [
|
||||||
value: joinRule,
|
for (final joinRule in controller.availableJoinRules)
|
||||||
groupValue: room.joinRules,
|
if (joinRule != JoinRules.private)
|
||||||
onChanged: controller.joinRulesLoading ||
|
RadioListTile<JoinRules>.adaptive(
|
||||||
!room.canChangeJoinRules
|
enabled: !controller.joinRulesLoading &&
|
||||||
? null
|
room.canChangeJoinRules,
|
||||||
: controller.setJoinRule,
|
title: Text(
|
||||||
),
|
joinRule.localizedString(
|
||||||
|
L10n.of(context),
|
||||||
|
controller.knownSpaceParents,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
value: joinRule,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
Divider(color: theme.dividerColor),
|
Divider(color: theme.dividerColor),
|
||||||
if ({JoinRules.public, JoinRules.knock}
|
if ({JoinRules.public, JoinRules.knock}
|
||||||
.contains(room.joinRules)) ...[
|
.contains(room.joinRules)) ...[
|
||||||
|
|
@ -93,20 +110,26 @@ class ChatAccessSettingsPageView extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
for (final guestAccess in GuestAccess.values)
|
RadioGroup(
|
||||||
RadioListTile<GuestAccess>.adaptive(
|
groupValue: room.guestAccess,
|
||||||
title: Text(
|
onChanged: controller.setGuestAccess,
|
||||||
guestAccess.getLocalizedString(
|
child: Column(
|
||||||
MatrixLocals(L10n.of(context)),
|
mainAxisSize: MainAxisSize.min,
|
||||||
),
|
children: [
|
||||||
),
|
for (final guestAccess in GuestAccess.values)
|
||||||
value: guestAccess,
|
RadioListTile<GuestAccess>.adaptive(
|
||||||
groupValue: room.guestAccess,
|
enabled: !controller.guestAccessLoading &&
|
||||||
onChanged: controller.guestAccessLoading ||
|
room.canChangeGuestAccess,
|
||||||
!room.canChangeGuestAccess
|
title: Text(
|
||||||
? null
|
guestAccess.getLocalizedString(
|
||||||
: controller.setGuestAccess,
|
MatrixLocals(L10n.of(context)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
value: guestAccess,
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
Divider(color: theme.dividerColor),
|
Divider(color: theme.dividerColor),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
|
|
@ -260,7 +283,7 @@ class _AliasListTile extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension JoinRulesDisplayString on JoinRules {
|
extension JoinRulesDisplayString on JoinRules {
|
||||||
String localizedString(L10n l10n) {
|
String localizedString(L10n l10n, Set<Room> spaceParents) {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case JoinRules.public:
|
case JoinRules.public:
|
||||||
return l10n.anyoneCanJoin;
|
return l10n.anyoneCanJoin;
|
||||||
|
|
@ -271,9 +294,17 @@ extension JoinRulesDisplayString on JoinRules {
|
||||||
case JoinRules.private:
|
case JoinRules.private:
|
||||||
return l10n.noOneCanJoin;
|
return l10n.noOneCanJoin;
|
||||||
case JoinRules.restricted:
|
case JoinRules.restricted:
|
||||||
return l10n.restricted;
|
return l10n.spaceMemberOf(
|
||||||
|
spaceParents
|
||||||
|
.map((space) => space.getLocalizedDisplayname(MatrixLocals(l10n)))
|
||||||
|
.join(', '),
|
||||||
|
);
|
||||||
case JoinRules.knockRestricted:
|
case JoinRules.knockRestricted:
|
||||||
return l10n.knockRestricted;
|
return l10n.spaceMemberOfCanKnock(
|
||||||
|
spaceParents
|
||||||
|
.map((space) => space.getLocalizedDisplayname(MatrixLocals(l10n)))
|
||||||
|
.join(', '),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue