Merge pull request #341 from pangeachat/limit-add-to-space
Limit add to space
This commit is contained in:
commit
1507a0b32f
5 changed files with 49 additions and 7 deletions
|
|
@ -3970,5 +3970,8 @@
|
|||
"capacitySetTooLow": "Room capacity cannot be set below the current number of non-admins.",
|
||||
"roomCapacityExplanation": "Room capacity limits the number of non-admins allowed in a room.",
|
||||
"enterNumber": "Please enter a whole number value.",
|
||||
"buildTranslation": "Build your translation from the choices above"
|
||||
"buildTranslation": "Build your translation from the choices above",
|
||||
"nonexistentSelection": "Selection no longer exists.",
|
||||
"cantAddSpaceChild": "You do not have permission to add a child to this space.",
|
||||
"roomAddedToSpace": "Room(s) have been added to the selected space."
|
||||
}
|
||||
|
|
@ -797,6 +797,10 @@ class ChatListController extends State<ChatList>
|
|||
// Pangea#
|
||||
|
||||
Future<void> addToSpace() async {
|
||||
// #Pangea
|
||||
final firstSelectedRoom =
|
||||
Matrix.of(context).client.getRoomById(selectedRoomIds.toList().first);
|
||||
// Pangea#
|
||||
final selectedSpace = await showConfirmationDialog<String>(
|
||||
context: context,
|
||||
title: L10n.of(context)!.addToSpace,
|
||||
|
|
@ -815,8 +819,9 @@ class ChatListController extends State<ChatList>
|
|||
&&
|
||||
selectedRoomIds
|
||||
.map((id) => Matrix.of(context).client.getRoomById(id))
|
||||
.where((e) => !(e?.isPangeaClass ?? true))
|
||||
.every((e) => r.canIAddSpaceChild(e)),
|
||||
// Only show non-recursion-causing spaces
|
||||
// Performs a few other checks as well
|
||||
.every((e) => r.canAddAsParentOf(e)),
|
||||
//Pangea#
|
||||
)
|
||||
.map(
|
||||
|
|
@ -826,6 +831,13 @@ class ChatListController extends State<ChatList>
|
|||
// label: space
|
||||
// .getLocalizedDisplayname(MatrixLocals(L10n.of(context)!)),
|
||||
label: space.nameIncludingParents(context),
|
||||
// If user is not admin of space, button is grayed out
|
||||
textStyle: TextStyle(
|
||||
color: (firstSelectedRoom == null ||
|
||||
(firstSelectedRoom.isSpace && !space.isRoomAdmin))
|
||||
? Theme.of(context).colorScheme.outline
|
||||
: Theme.of(context).colorScheme.surfaceTint,
|
||||
),
|
||||
// Pangea#
|
||||
),
|
||||
)
|
||||
|
|
@ -837,12 +849,20 @@ class ChatListController extends State<ChatList>
|
|||
future: () async {
|
||||
final space = Matrix.of(context).client.getRoomById(selectedSpace)!;
|
||||
// #Pangea
|
||||
if (firstSelectedRoom == null) {
|
||||
throw L10n.of(context)!.nonexistentSelection;
|
||||
}
|
||||
// If user is not admin of the would-be parent space, does not allow
|
||||
if (firstSelectedRoom.isSpace && !space.isRoomAdmin) {
|
||||
throw L10n.of(context)!.cantAddSpaceChild;
|
||||
}
|
||||
await pangeaAddToSpace(
|
||||
space,
|
||||
selectedRoomIds.toList(),
|
||||
context,
|
||||
pangeaController,
|
||||
);
|
||||
|
||||
// if (space.canSendDefaultStates) {
|
||||
// for (final roomId in selectedRoomIds) {
|
||||
// await space.setSpaceChild(roomId);
|
||||
|
|
@ -855,7 +875,10 @@ class ChatListController extends State<ChatList>
|
|||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(L10n.of(context)!.chatHasBeenAddedToThisSpace),
|
||||
// #Pangea
|
||||
// content: Text(L10n.of(context)!.chatHasBeenAddedToThisSpace),
|
||||
content: Text(L10n.of(context)!.roomAddedToSpace),
|
||||
// Pangea#
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,4 +127,14 @@ extension ChildrenAndParentsRoomExtension on Room {
|
|||
}
|
||||
return childIds;
|
||||
}
|
||||
|
||||
// Checks if has permissions to add child chat
|
||||
// Or whether potential child space is ancestor of this
|
||||
bool _canAddAsParentOf(Room? child) {
|
||||
if (child == null || !child.isSpace) {
|
||||
return _canIAddSpaceChild(child);
|
||||
}
|
||||
if (id == child.id) return false;
|
||||
return !child._allSpaceChildRoomIds.contains(id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,8 @@ extension PangeaRoom on Room {
|
|||
|
||||
List<String> get allSpaceChildRoomIds => _allSpaceChildRoomIds;
|
||||
|
||||
bool canAddAsParentOf(Room? child) => _canAddAsParentOf(child);
|
||||
|
||||
// class_and_exchange_settings
|
||||
|
||||
DateTime? get rulesUpdatedAt => _rulesUpdatedAt;
|
||||
|
|
|
|||
|
|
@ -144,9 +144,13 @@ class AddToSpaceState extends State<AddToSpaceToggles> {
|
|||
|
||||
Widget getAddToSpaceToggleItem(int index) {
|
||||
final Room possibleParent = possibleParents[index];
|
||||
final bool canAdd = !(!possibleParent.isRoomAdmin &&
|
||||
widget.mode == AddToClassMode.exchange) &&
|
||||
possibleParent.canIAddSpaceChild(room);
|
||||
final bool canAdd = (room?.isSpace ?? false)
|
||||
// Room is space
|
||||
? possibleParent.isRoomAdmin &&
|
||||
room!.isRoomAdmin &&
|
||||
possibleParent.canAddAsParentOf(room)
|
||||
// Room is null or chat
|
||||
: possibleParent.canAddAsParentOf(room);
|
||||
|
||||
return Opacity(
|
||||
opacity: canAdd ? 1 : 0.5,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue