diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 84703a551..c8224dccb 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -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." } \ No newline at end of file diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 58b3f9223..f8faceec5 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -797,6 +797,10 @@ class ChatListController extends State // Pangea# Future addToSpace() async { + // #Pangea + final firstSelectedRoom = + Matrix.of(context).client.getRoomById(selectedRoomIds.toList().first); + // Pangea# final selectedSpace = await showConfirmationDialog( context: context, title: L10n.of(context)!.addToSpace, @@ -825,6 +829,12 @@ class ChatListController extends State // label: space // .getLocalizedDisplayname(MatrixLocals(L10n.of(context)!)), label: space.nameIncludingParents(context), + textStyle: TextStyle( + color: (firstSelectedRoom == null || + (firstSelectedRoom.isSpace && !space.isRoomAdmin)) + ? Theme.of(context).colorScheme.outline + : Theme.of(context).colorScheme.surfaceTint, + ), // Pangea# ), ) @@ -836,12 +846,19 @@ class ChatListController extends State future: () async { final space = Matrix.of(context).client.getRoomById(selectedSpace)!; // #Pangea + if (firstSelectedRoom == null) { + throw L10n.of(context)!.nonexistentSelection; + } + 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); @@ -854,7 +871,10 @@ class ChatListController extends State 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# ), ); } diff --git a/lib/pangea/extensions/pangea_room_extension/children_and_parents_extension.dart b/lib/pangea/extensions/pangea_room_extension/children_and_parents_extension.dart index b0350853d..24dad6c41 100644 --- a/lib/pangea/extensions/pangea_room_extension/children_and_parents_extension.dart +++ b/lib/pangea/extensions/pangea_room_extension/children_and_parents_extension.dart @@ -128,15 +128,13 @@ extension ChildrenAndParentsRoomExtension on Room { return childIds; } - // Checks if has permissions to add child to space - // And whether potential child space is ancestor of this + // 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 _isRoomAdmin && - child._isRoomAdmin && - !child._allSpaceChildRoomIds.contains(id); + return !child._allSpaceChildRoomIds.contains(id); } } diff --git a/lib/pangea/widgets/class/add_space_toggles.dart b/lib/pangea/widgets/class/add_space_toggles.dart index 69122356b..c2ed32efe 100644 --- a/lib/pangea/widgets/class/add_space_toggles.dart +++ b/lib/pangea/widgets/class/add_space_toggles.dart @@ -144,9 +144,13 @@ class AddToSpaceState extends State { Widget getAddToSpaceToggleItem(int index) { final Room possibleParent = possibleParents[index]; - final bool canAdd = !(!possibleParent.isRoomAdmin && - widget.mode == AddToClassMode.exchange) && - possibleParent.canAddAsParentOf(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,