diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index c41b23743..8dcdfebe1 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -3968,5 +3968,6 @@ "roomFull": "This room is already at capacity.", "topicNotSet": "The topic has not been set.", "capacityNotSet": "This room has no capacity limit.", - "roomCapacityHasBeenChanged": "Room capacity changed" + "roomCapacityHasBeenChanged": "Room capacity changed", + "roomExceedsCapacity": "Room exceeds capacity. Consider removing students from the room, or raising the capacity." } \ No newline at end of file diff --git a/lib/pages/chat_list/space_view.dart b/lib/pages/chat_list/space_view.dart index 8ee62ae30..306cbecee 100644 --- a/lib/pages/chat_list/space_view.dart +++ b/lib/pages/chat_list/space_view.dart @@ -209,6 +209,15 @@ class _SpaceViewState extends State { await waitForRoom; }, ); + if (await room.leaveIfFull()) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 10), + content: Text(L10n.of(context)!.roomFull), + ), + ); + return; + } if (joinResult.error != null) return; } // Pangea# @@ -242,7 +251,10 @@ class _SpaceViewState extends State { ), message: spaceChild?.topic ?? room?.topic, actions: [ - if (room == null) + // #Pangea + // if (room == null) + if (room == null || room.membership == Membership.leave) + // Pangea# SheetAction( key: SpaceChildContextAction.join, label: L10n.of(context)!.joinRoom, @@ -275,8 +287,9 @@ class _SpaceViewState extends State { : L10n.of(context)!.archive, icon: Icons.architecture_outlined, ), - // Pangea# - if (room != null) + // if (room != null) + if (room != null && room.membership != Membership.leave) + // Pangea# SheetAction( key: SpaceChildContextAction.leave, label: L10n.of(context)!.leave, @@ -321,7 +334,7 @@ class _SpaceViewState extends State { case SpaceChildContextAction.archive: widget.controller.cancelAction(); // #Pangea - if (room == null) return; + if (room == null || room.membership == Membership.leave) return; // Pangea# widget.controller.toggleSelection(room.id); room.isSpace @@ -341,7 +354,7 @@ class _SpaceViewState extends State { case SpaceChildContextAction.addToSpace: widget.controller.cancelAction(); // #Pangea - if (room == null) return; + if (room == null || room.membership == Membership.leave) return; // Pangea# widget.controller.toggleSelection(room.id); await widget.controller.addToSpace(); diff --git a/lib/pangea/pages/class_settings/p_class_widgets/room_capacity_button.dart b/lib/pangea/pages/class_settings/p_class_widgets/room_capacity_button.dart index 7c66dfa83..b67bebc3a 100644 --- a/lib/pangea/pages/class_settings/p_class_widgets/room_capacity_button.dart +++ b/lib/pangea/pages/class_settings/p_class_widgets/room_capacity_button.dart @@ -23,6 +23,7 @@ class RoomCapacityButtonState extends State { Room? room; ChatDetailsController? controller; String? capacity; + String? nonAdmins; RoomCapacityButtonState({Key? key}); @@ -31,13 +32,33 @@ class RoomCapacityButtonState extends State { super.initState(); room = widget.room; controller = widget.controller; + capacity = room?.capacity; + room?.numNonAdmins.then( + (value) => setState(() { + nonAdmins = value.toString(); + overCapacity(); + }), + ); + } + + Future overCapacity() async { + if ((room?.isRoomAdmin ?? false) && + capacity != null && + nonAdmins != null && + int.parse(nonAdmins!) > int.parse(capacity!)) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + L10n.of(context)!.roomExceedsCapacity, + ), + ), + ); + } } @override Widget build(BuildContext context) { final iconColor = Theme.of(context).textTheme.bodyLarge!.color; - // Edit - use FutureBuilder to allow async call - // String nonAdmins = (await room.numNonAdmins).toString(); return Column( children: [ ListTile( @@ -49,9 +70,9 @@ class RoomCapacityButtonState extends State { child: const Icon(Icons.reduce_capacity), ), subtitle: Text( - // Edit - // '$nonAdmins/${room.capacity}', - (room?.capacity ?? capacity ?? L10n.of(context)!.capacityNotSet), + (capacity != null && nonAdmins != null) + ? '$nonAdmins/$capacity' + : (capacity ?? L10n.of(context)!.capacityNotSet), ), title: Text( L10n.of(context)!.roomCapacity, @@ -71,7 +92,7 @@ class RoomCapacityButtonState extends State { Future setClassCapacity() async { final TextEditingController myTextFieldController = - TextEditingController(text: (room?.capacity ?? capacity ?? '')); + TextEditingController(text: (capacity ?? '')); showDialog( context: context, useRootNavigator: false, @@ -101,7 +122,9 @@ class RoomCapacityButtonState extends State { final success = await showFutureLoadingDialog( context: context, future: () => ((room != null) - ? (room!.updateRoomCapacity(myTextFieldController.text)) + ? (room!.updateRoomCapacity( + capacity = myTextFieldController.text, + )) : setCapacity(myTextFieldController.text)), ); if (success.error == null) {