Add capacity option when creating room
This commit is contained in:
parent
ff198f64bc
commit
7fd7ec2d7c
7 changed files with 109 additions and 64 deletions
|
|
@ -3967,5 +3967,6 @@
|
|||
"roomCapacity": "Room Capacity",
|
||||
"roomFull": "This room is already at capacity.",
|
||||
"topicNotSet": "The topic has not been set.",
|
||||
"capacityNotSet": "This room has no capacity limit."
|
||||
"capacityNotSet": "This room has no capacity limit.",
|
||||
"roomCapacityHasBeenChanged": "Room capacity changed"
|
||||
}
|
||||
|
|
@ -4,7 +4,6 @@ import 'package:file_picker/file_picker.dart';
|
|||
import 'package:fluffychat/pages/chat_details/chat_details_view.dart';
|
||||
import 'package:fluffychat/pages/settings/settings.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/class_description_button.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/room_capacity_button.dart';
|
||||
import 'package:fluffychat/pangea/utils/set_class_name.dart';
|
||||
import 'package:fluffychat/pangea/widgets/class/add_space_toggles.dart';
|
||||
import 'package:fluffychat/pangea/widgets/conversation_bot/conversation_bot_settings.dart';
|
||||
|
|
@ -233,13 +232,6 @@ class ChatDetailsController extends State<ChatDetails> {
|
|||
// Pangea#
|
||||
}
|
||||
|
||||
// #Pangea
|
||||
void setCapacityAction() async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
||||
setClassCapacity(room, context);
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
void setGuestAccess() async {
|
||||
final room = Matrix.of(context).client.getRoomById(roomId!)!;
|
||||
final currentGuestAccess = room.guestAccess;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ import 'dart:typed_data';
|
|||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:fluffychat/pages/new_group/new_group_view.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/chat_topic_model.dart';
|
||||
import 'package:fluffychat/pangea/models/lemma.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/room_capacity_button.dart';
|
||||
import 'package:fluffychat/pangea/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/utils/class_chat_power_levels.dart';
|
||||
import 'package:fluffychat/pangea/utils/firebase_analytics.dart';
|
||||
|
|
@ -51,6 +53,8 @@ class NewGroupController extends State<NewGroup> {
|
|||
final GlobalKey<AddToSpaceState> addToSpaceKey = GlobalKey<AddToSpaceState>();
|
||||
final GlobalKey<ConversationBotSettingsState> addConversationBotKey =
|
||||
GlobalKey<ConversationBotSettingsState>();
|
||||
final GlobalKey<RoomCapacityButtonState> addCapacityKey =
|
||||
GlobalKey<RoomCapacityButtonState>();
|
||||
|
||||
ChatTopic chatTopic = ChatTopic.empty;
|
||||
|
||||
|
|
@ -147,10 +151,16 @@ class NewGroupController extends State<NewGroup> {
|
|||
visibility: sdk.Visibility.public,
|
||||
);
|
||||
}
|
||||
//#Pangea
|
||||
// #Pangea
|
||||
GoogleAnalytics.createChat(roomId);
|
||||
await addToSpaceKey.currentState!.addSpaces(roomId);
|
||||
//Pangea#
|
||||
|
||||
final capacity = addCapacityKey.currentState?.capacity;
|
||||
final room = client.getRoomById(roomId);
|
||||
if (capacity != null && room != null) {
|
||||
room.updateRoomCapacity(capacity);
|
||||
}
|
||||
// Pangea#
|
||||
context.go('/rooms/$roomId/invite');
|
||||
} catch (e, s) {
|
||||
sdk.Logs().d('Unable to create group', e, s);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/pages/new_group/new_group.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/room_capacity_button.dart';
|
||||
import 'package:fluffychat/pangea/widgets/class/add_class_and_invite.dart';
|
||||
import 'package:fluffychat/pangea/widgets/class/add_space_toggles.dart';
|
||||
import 'package:fluffychat/pangea/widgets/conversation_bot/conversation_bot_settings.dart';
|
||||
|
|
@ -87,6 +88,9 @@ class NewGroupView extends StatelessWidget {
|
|||
// ),
|
||||
// ),
|
||||
// ),
|
||||
RoomCapacityButton(
|
||||
key: controller.addCapacityKey,
|
||||
),
|
||||
ConversationBotSettings(
|
||||
key: controller.addConversationBotKey,
|
||||
activeSpaceId: controller.activeSpaceId,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import 'package:fluffychat/pages/new_space/new_space_view.dart';
|
|||
import 'package:fluffychat/pangea/constants/class_default_values.dart';
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/room_capacity_button.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/room_rules_editor.dart';
|
||||
import 'package:fluffychat/pangea/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/utils/class_chat_power_levels.dart';
|
||||
|
|
@ -38,6 +39,8 @@ class NewSpaceController extends State<NewSpace> {
|
|||
final GlobalKey<AddToSpaceState> addToSpaceKey = GlobalKey<AddToSpaceState>();
|
||||
final GlobalKey<ClassSettingsState> classSettingsKey =
|
||||
GlobalKey<ClassSettingsState>();
|
||||
final GlobalKey<RoomCapacityButtonState> addCapacityKey =
|
||||
GlobalKey<RoomCapacityButtonState>();
|
||||
|
||||
//Pangea#
|
||||
bool loading = false;
|
||||
|
|
@ -200,6 +203,11 @@ class NewSpaceController extends State<NewSpace> {
|
|||
}
|
||||
await Future.wait(futures);
|
||||
|
||||
final capacity = addCapacityKey.currentState?.capacity;
|
||||
final space = client.getRoomById(spaceId);
|
||||
if (capacity != null && space != null) {
|
||||
space.updateRoomCapacity(capacity);
|
||||
}
|
||||
final newChatRoomId = await Matrix.of(context).client.createGroupChat(
|
||||
enableEncryption: false,
|
||||
preset: sdk.CreateRoomPreset.publicChat,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/extensions/client_extension/client_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/room_capacity_button.dart';
|
||||
import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/room_rules_editor.dart';
|
||||
import 'package:fluffychat/pangea/widgets/class/add_class_and_invite.dart';
|
||||
import 'package:fluffychat/pangea/widgets/class/add_space_toggles.dart';
|
||||
|
|
@ -130,6 +131,10 @@ class NewSpaceView extends StatelessWidget {
|
|||
// ),
|
||||
// ),
|
||||
// const SizedBox(height: 16),
|
||||
|
||||
RoomCapacityButton(
|
||||
key: controller.addCapacityKey,
|
||||
),
|
||||
if (controller.newClassMode)
|
||||
ClassSettings(
|
||||
key: controller.classSettingsKey,
|
||||
|
|
|
|||
|
|
@ -6,24 +6,43 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
class RoomCapacityButton extends StatelessWidget {
|
||||
final Room room;
|
||||
class RoomCapacityButton extends StatefulWidget {
|
||||
final Room? room;
|
||||
final ChatDetailsController? controller;
|
||||
const RoomCapacityButton({
|
||||
super.key,
|
||||
required this.room,
|
||||
this.room,
|
||||
this.controller,
|
||||
});
|
||||
|
||||
@override
|
||||
RoomCapacityButtonState createState() => RoomCapacityButtonState();
|
||||
}
|
||||
|
||||
class RoomCapacityButtonState extends State<RoomCapacityButton> {
|
||||
Room? room;
|
||||
ChatDetailsController? controller;
|
||||
String? capacity;
|
||||
|
||||
RoomCapacityButtonState({Key? key});
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
room = widget.room;
|
||||
controller = widget.controller;
|
||||
}
|
||||
|
||||
@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;
|
||||
// String nonAdmins = (await room.numNonAdmins).toString();
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
onTap: room.isRoomAdmin ? controller!.setCapacityAction : null,
|
||||
onTap: () =>
|
||||
((room?.isRoomAdmin ?? true) ? (setClassCapacity()) : null),
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
foregroundColor: iconColor,
|
||||
|
|
@ -32,7 +51,7 @@ class RoomCapacityButton extends StatelessWidget {
|
|||
subtitle: Text(
|
||||
// Edit
|
||||
// '$nonAdmins/${room.capacity}',
|
||||
(room.capacity ?? L10n.of(context)!.capacityNotSet),
|
||||
(room?.capacity ?? capacity ?? L10n.of(context)!.capacityNotSet),
|
||||
),
|
||||
title: Text(
|
||||
L10n.of(context)!.roomCapacity,
|
||||
|
|
@ -45,54 +64,60 @@ class RoomCapacityButton extends StatelessWidget {
|
|||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void setClassCapacity(Room room, BuildContext context) {
|
||||
final TextEditingController myTextFieldController =
|
||||
TextEditingController(text: (room.capacity ?? ''));
|
||||
showDialog(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: Text(
|
||||
L10n.of(context)!.roomCapacity,
|
||||
),
|
||||
content: TextFormField(
|
||||
controller: myTextFieldController,
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 2,
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
Future<void> setCapacity(String newCapacity) async {
|
||||
capacity = newCapacity;
|
||||
}
|
||||
|
||||
Future<void> setClassCapacity() async {
|
||||
final TextEditingController myTextFieldController =
|
||||
TextEditingController(text: (room?.capacity ?? capacity ?? ''));
|
||||
showDialog(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: Text(
|
||||
L10n.of(context)!.roomCapacity,
|
||||
),
|
||||
content: TextFormField(
|
||||
controller: myTextFieldController,
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 3,
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(L10n.of(context)!.cancel),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text(L10n.of(context)!.ok),
|
||||
onPressed: () async {
|
||||
if (myTextFieldController.text == "") return;
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => ((room != null)
|
||||
? (room!.updateRoomCapacity(myTextFieldController.text))
|
||||
: setCapacity(myTextFieldController.text)),
|
||||
);
|
||||
if (success.error == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
L10n.of(context)!.roomCapacityHasBeenChanged,
|
||||
),
|
||||
),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(L10n.of(context)!.cancel),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text(L10n.of(context)!.ok),
|
||||
onPressed: () async {
|
||||
if (myTextFieldController.text == "") return;
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.updateRoomCapacity(myTextFieldController.text),
|
||||
);
|
||||
if (success.error == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
L10n.of(context)!.groupDescriptionHasBeenChanged,
|
||||
), // Edit
|
||||
),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue