mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Can create group conversations
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:comunic/helpers/groups_helper.dart';
|
||||
import 'package:comunic/helpers/server_config_helper.dart';
|
||||
import 'package:comunic/models/advanced_group_info.dart';
|
||||
import 'package:comunic/models/group.dart';
|
||||
import 'package:comunic/models/new_group_conversation.dart';
|
||||
import 'package:comunic/ui/dialogs/input_user_password_dialog.dart';
|
||||
import 'package:comunic/ui/dialogs/multi_choices_dialog.dart';
|
||||
import 'package:comunic/ui/dialogs/virtual_directory_dialog.dart';
|
||||
@ -17,6 +19,7 @@ import 'package:comunic/ui/widgets/settings/text_settings_edit_tile.dart';
|
||||
import 'package:comunic/utils/files_utils.dart';
|
||||
import 'package:comunic/utils/input_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/log_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:identicon/identicon.dart';
|
||||
@ -85,6 +88,7 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
|
||||
HeadSpacerSection(),
|
||||
_buildGeneralSection(),
|
||||
_buildAccessRestrictions(),
|
||||
_buildConversationsArea(),
|
||||
_buildGroupLogoArea(),
|
||||
_buildDangerZone(),
|
||||
],
|
||||
@ -256,6 +260,75 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
|
||||
],
|
||||
);
|
||||
|
||||
List<MultiChoiceEntry<GroupMembershipLevel>>
|
||||
get _conversationMinMembershipLevel => [
|
||||
MultiChoiceEntry(
|
||||
id: GroupMembershipLevel.ADMINISTRATOR,
|
||||
title: tr("Administrators only"),
|
||||
subtitle: tr(
|
||||
"Only the administrators of the group can access the conversation"),
|
||||
),
|
||||
MultiChoiceEntry(
|
||||
id: GroupMembershipLevel.MODERATOR,
|
||||
title: tr("Moderators and administrators"),
|
||||
subtitle: tr(
|
||||
"Only moderators and administrators of the group can access the conversation"),
|
||||
),
|
||||
MultiChoiceEntry(
|
||||
id: GroupMembershipLevel.MEMBER,
|
||||
title: tr("All members"),
|
||||
subtitle: tr(
|
||||
"All the members of the group can access the conversation"),
|
||||
),
|
||||
];
|
||||
|
||||
SettingsSection _buildConversationsArea() => SettingsSection(
|
||||
title: tr("Group conversations"),
|
||||
tiles: [
|
||||
SettingsTile(
|
||||
title: tr("Create a new conversation"),
|
||||
onPressed: _createNewGroupConversation,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
void _createNewGroupConversation(BuildContext context) async {
|
||||
try {
|
||||
final name = await askUserString(
|
||||
context: context,
|
||||
title: tr("New conversation name"),
|
||||
message: tr("Please give a name to the new conversation"),
|
||||
defaultValue: "",
|
||||
hint: tr("Name"),
|
||||
minLength: 1,
|
||||
maxLength: ServerConfigurationHelper
|
||||
.config.conversationsPolicy.maxConversationNameLen,
|
||||
);
|
||||
|
||||
if (name == null) return;
|
||||
|
||||
final visibility = await showMultiChoicesDialog(
|
||||
context: context,
|
||||
choices: _conversationMinMembershipLevel,
|
||||
defaultChoice: GroupMembershipLevel.MEMBER,
|
||||
title: tr("Conversation visibility"),
|
||||
);
|
||||
|
||||
if (visibility == null) return;
|
||||
|
||||
await GroupsHelper.createGroupConversation(NewGroupConversation(
|
||||
groupID: _groupSettings.id,
|
||||
name: name,
|
||||
minMembershipLevel: visibility,
|
||||
));
|
||||
|
||||
_key.currentState.refresh();
|
||||
} catch (e, s) {
|
||||
logError(e, s);
|
||||
snack(context, tr("Failed to create a conversation!"));
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildGroupLogoArea() {
|
||||
return SettingsSection(
|
||||
title: tr("Group logo"),
|
||||
|
Reference in New Issue
Block a user