Fix some capacity enforcement bugs
This commit is contained in:
parent
7fd7ec2d7c
commit
db61c1f1cf
3 changed files with 50 additions and 13 deletions
|
|
@ -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."
|
||||
}
|
||||
|
|
@ -209,6 +209,15 @@ class _SpaceViewState extends State<SpaceView> {
|
|||
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<SpaceView> {
|
|||
),
|
||||
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<SpaceView> {
|
|||
: 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<SpaceView> {
|
|||
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<SpaceView> {
|
|||
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();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ class RoomCapacityButtonState extends State<RoomCapacityButton> {
|
|||
Room? room;
|
||||
ChatDetailsController? controller;
|
||||
String? capacity;
|
||||
String? nonAdmins;
|
||||
|
||||
RoomCapacityButtonState({Key? key});
|
||||
|
||||
|
|
@ -31,13 +32,33 @@ class RoomCapacityButtonState extends State<RoomCapacityButton> {
|
|||
super.initState();
|
||||
room = widget.room;
|
||||
controller = widget.controller;
|
||||
capacity = room?.capacity;
|
||||
room?.numNonAdmins.then(
|
||||
(value) => setState(() {
|
||||
nonAdmins = value.toString();
|
||||
overCapacity();
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> 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<RoomCapacityButton> {
|
|||
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<RoomCapacityButton> {
|
|||
|
||||
Future<void> 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<RoomCapacityButton> {
|
|||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue