mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Can create a group
This commit is contained in:
		@@ -126,6 +126,17 @@ class GroupsHelper {
 | 
				
			|||||||
          .map((f) => cast<int>(f))
 | 
					          .map((f) => cast<int>(f))
 | 
				
			||||||
          .toSet();
 | 
					          .toSet();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /// Create a new group
 | 
				
			||||||
 | 
					  ///
 | 
				
			||||||
 | 
					  /// Throws in case of failure
 | 
				
			||||||
 | 
					  static Future<int> create(String name) async {
 | 
				
			||||||
 | 
					    final result = await APIRequest.withLogin("groups/create")
 | 
				
			||||||
 | 
					        .addString("name", name)
 | 
				
			||||||
 | 
					        .execWithThrow();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return result.getObject()["id"];
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Perform a simple membership request
 | 
					  /// Perform a simple membership request
 | 
				
			||||||
  Future<bool> _simpleMembershipRequest(int groupID, String uri,
 | 
					  Future<bool> _simpleMembershipRequest(int groupID, String uri,
 | 
				
			||||||
          {Map<String, String> args}) async =>
 | 
					          {Map<String, String> args}) async =>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -54,28 +54,38 @@ class _GroupsListScreenState extends SafeState<GroupsListScreen> {
 | 
				
			|||||||
          onRefresh: () => this._refreshList(),
 | 
					          onRefresh: () => this._refreshList(),
 | 
				
			||||||
          child: _groups == null
 | 
					          child: _groups == null
 | 
				
			||||||
              ? Container()
 | 
					              ? Container()
 | 
				
			||||||
              : ListView(
 | 
					              : Stack(children: [_buildGroupsList(), _buildCreateButton()]),
 | 
				
			||||||
                  children: _groups.values
 | 
					 | 
				
			||||||
                      .map((g) => ListTile(
 | 
					 | 
				
			||||||
                            leading: GroupIcon(group: g),
 | 
					 | 
				
			||||||
                            title: Text(g.displayName),
 | 
					 | 
				
			||||||
                            subtitle: GroupMembershipWidget(
 | 
					 | 
				
			||||||
                              group: g,
 | 
					 | 
				
			||||||
                              onUpdated: () =>
 | 
					 | 
				
			||||||
                                  _refreshIndicatorKey.currentState.show(),
 | 
					 | 
				
			||||||
                            ),
 | 
					 | 
				
			||||||
                            trailing: IconButton(
 | 
					 | 
				
			||||||
                                icon: Icon(Icons.delete),
 | 
					 | 
				
			||||||
                                onPressed: () => _deleteGroup(g)),
 | 
					 | 
				
			||||||
                    onTap: () => MainController.of(context).openGroup(g.id),
 | 
					 | 
				
			||||||
                          ))
 | 
					 | 
				
			||||||
                      .toList(),
 | 
					 | 
				
			||||||
                ),
 | 
					 | 
				
			||||||
        ))
 | 
					        ))
 | 
				
			||||||
      ],
 | 
					      ],
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Widget _buildGroupsList() => ListView(
 | 
				
			||||||
 | 
					        children: _groups.values
 | 
				
			||||||
 | 
					            .map((g) => ListTile(
 | 
				
			||||||
 | 
					                  leading: GroupIcon(group: g),
 | 
				
			||||||
 | 
					                  title: Text(g.displayName),
 | 
				
			||||||
 | 
					                  subtitle: GroupMembershipWidget(
 | 
				
			||||||
 | 
					                    group: g,
 | 
				
			||||||
 | 
					                    onUpdated: () => _refreshIndicatorKey.currentState.show(),
 | 
				
			||||||
 | 
					                  ),
 | 
				
			||||||
 | 
					                  trailing: IconButton(
 | 
				
			||||||
 | 
					                      icon: Icon(Icons.delete),
 | 
				
			||||||
 | 
					                      onPressed: () => _deleteGroup(g)),
 | 
				
			||||||
 | 
					                  onTap: () => MainController.of(context).openGroup(g.id),
 | 
				
			||||||
 | 
					                ))
 | 
				
			||||||
 | 
					            .toList(),
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Widget _buildCreateButton() => Positioned(
 | 
				
			||||||
 | 
					        right: 15,
 | 
				
			||||||
 | 
					        bottom: 15,
 | 
				
			||||||
 | 
					        child: FloatingActionButton(
 | 
				
			||||||
 | 
					          child: Icon(Icons.add),
 | 
				
			||||||
 | 
					          onPressed: _createGroup,
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Refresh the list of groups
 | 
					  /// Refresh the list of groups
 | 
				
			||||||
  Future<void> _refreshList() async {
 | 
					  Future<void> _refreshList() async {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
@@ -109,4 +119,27 @@ class _GroupsListScreenState extends SafeState<GroupsListScreen> {
 | 
				
			|||||||
    // Refresh the list of groups
 | 
					    // Refresh the list of groups
 | 
				
			||||||
    _refreshIndicatorKey.currentState.show();
 | 
					    _refreshIndicatorKey.currentState.show();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /// Add a group
 | 
				
			||||||
 | 
					  void _createGroup() async {
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      final name = await askUserString(
 | 
				
			||||||
 | 
					        context: context,
 | 
				
			||||||
 | 
					        title: tr("Group name"),
 | 
				
			||||||
 | 
					        message: tr("Name of the group to create"),
 | 
				
			||||||
 | 
					        defaultValue: "",
 | 
				
			||||||
 | 
					        hint: tr("Name of the group"),
 | 
				
			||||||
 | 
					        maxLength: 50,
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (name == null) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      final groupID = await GroupsHelper.create(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      MainController.of(context).openGroup(groupID);
 | 
				
			||||||
 | 
					    } catch (e, s) {
 | 
				
			||||||
 | 
					      print("Could not create a new group! $e\n$s");
 | 
				
			||||||
 | 
					      showSimpleSnack(context, tr("Could not create a new group!"));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
import 'package:comunic/helpers/preferences_helper.dart';
 | 
					import 'package:comunic/helpers/preferences_helper.dart';
 | 
				
			||||||
import 'package:comunic/ui/routes/full_screen_image.dart';
 | 
					import 'package:comunic/ui/routes/full_screen_image.dart';
 | 
				
			||||||
 | 
					import 'package:comunic/ui/widgets/dialogs/auto_sized_dialog_content_widget.dart';
 | 
				
			||||||
import 'package:comunic/utils/intl_utils.dart';
 | 
					import 'package:comunic/utils/intl_utils.dart';
 | 
				
			||||||
import 'package:flutter/material.dart';
 | 
					import 'package:flutter/material.dart';
 | 
				
			||||||
import 'package:html/parser.dart';
 | 
					import 'package:html/parser.dart';
 | 
				
			||||||
@@ -86,12 +87,14 @@ Future<String> askUserString({
 | 
				
			|||||||
  @required String message,
 | 
					  @required String message,
 | 
				
			||||||
  @required String defaultValue,
 | 
					  @required String defaultValue,
 | 
				
			||||||
  @required String hint,
 | 
					  @required String hint,
 | 
				
			||||||
 | 
					  int maxLength = 200,
 | 
				
			||||||
}) async {
 | 
					}) async {
 | 
				
			||||||
  assert(context != null);
 | 
					  assert(context != null);
 | 
				
			||||||
  assert(title != null);
 | 
					  assert(title != null);
 | 
				
			||||||
  assert(message != null);
 | 
					  assert(message != null);
 | 
				
			||||||
  assert(defaultValue != null);
 | 
					  assert(defaultValue != null);
 | 
				
			||||||
  assert(hint != null);
 | 
					  assert(hint != null);
 | 
				
			||||||
 | 
					  assert(maxLength != null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  TextEditingController controller = TextEditingController(text: defaultValue);
 | 
					  TextEditingController controller = TextEditingController(text: defaultValue);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -99,24 +102,21 @@ Future<String> askUserString({
 | 
				
			|||||||
      context: context,
 | 
					      context: context,
 | 
				
			||||||
      builder: (c) => AlertDialog(
 | 
					      builder: (c) => AlertDialog(
 | 
				
			||||||
            title: Text(title),
 | 
					            title: Text(title),
 | 
				
			||||||
            content: Container(
 | 
					            content: AutoSizeDialogContentWidget(
 | 
				
			||||||
              height: MediaQuery.of(context).size.height - 50,
 | 
					              child: Column(
 | 
				
			||||||
              child: SingleChildScrollView(
 | 
					                children: <Widget>[
 | 
				
			||||||
                child: Column(
 | 
					                  Text(message),
 | 
				
			||||||
                  children: <Widget>[
 | 
					                  TextField(
 | 
				
			||||||
                    Text(message),
 | 
					                    controller: controller,
 | 
				
			||||||
                    TextField(
 | 
					                    maxLines: null,
 | 
				
			||||||
                      controller: controller,
 | 
					                    maxLength: maxLength,
 | 
				
			||||||
                      maxLines: null,
 | 
					                    keyboardType: TextInputType.text,
 | 
				
			||||||
                      maxLength: 200,
 | 
					                    decoration: InputDecoration(
 | 
				
			||||||
                      keyboardType: TextInputType.text,
 | 
					                      labelText: hint,
 | 
				
			||||||
                      decoration: InputDecoration(
 | 
					                      alignLabelWithHint: true,
 | 
				
			||||||
                        labelText: hint,
 | 
					                    ),
 | 
				
			||||||
                        alignLabelWithHint: true,
 | 
					                  )
 | 
				
			||||||
                      ),
 | 
					                ],
 | 
				
			||||||
                    )
 | 
					 | 
				
			||||||
                  ],
 | 
					 | 
				
			||||||
                ),
 | 
					 | 
				
			||||||
              ),
 | 
					              ),
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
            actions: <Widget>[
 | 
					            actions: <Widget>[
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user