mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 12:14:11 +00:00 
			
		
		
		
	Can change conversation visibility
This commit is contained in:
		@@ -1,8 +1,10 @@
 | 
			
		||||
import 'dart:typed_data';
 | 
			
		||||
 | 
			
		||||
import 'package:cached_network_image/cached_network_image.dart';
 | 
			
		||||
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/conversation.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';
 | 
			
		||||
@@ -284,12 +286,34 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
 | 
			
		||||
 | 
			
		||||
  SettingsSection _buildConversationsArea() => SettingsSection(
 | 
			
		||||
        title: tr("Group conversations"),
 | 
			
		||||
        tiles: [
 | 
			
		||||
          SettingsTile(
 | 
			
		||||
            title: tr("Create a new conversation"),
 | 
			
		||||
            onPressed: _createNewGroupConversation,
 | 
			
		||||
          ),
 | 
			
		||||
        ],
 | 
			
		||||
        tiles: _groupSettings.conversations
 | 
			
		||||
            .map(
 | 
			
		||||
              (e) {
 | 
			
		||||
                SettingsTile tile =
 | 
			
		||||
                    MultiChoicesSettingsTile<GroupMembershipLevel>(
 | 
			
		||||
                  title: e.name,
 | 
			
		||||
                  choices: _conversationMinMembershipLevel,
 | 
			
		||||
                  currentValue: e.groupMinMembershipLevel,
 | 
			
		||||
                  leading: e.hasLogo
 | 
			
		||||
                      ? CachedNetworkImage(
 | 
			
		||||
                          imageUrl: e.logoURL,
 | 
			
		||||
                          width: 30,
 | 
			
		||||
                        )
 | 
			
		||||
                      : Icon(Icons.group, size: 30),
 | 
			
		||||
                  onChanged: (c) => _changeConversationVisibility(e, c),
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
                return tile;
 | 
			
		||||
              },
 | 
			
		||||
            )
 | 
			
		||||
            .toList()
 | 
			
		||||
            .cast<SettingsTile>()
 | 
			
		||||
              ..add(
 | 
			
		||||
                SettingsTile(
 | 
			
		||||
                  title: tr("Create a new conversation"),
 | 
			
		||||
                  onPressed: _createNewGroupConversation,
 | 
			
		||||
                ),
 | 
			
		||||
              ),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  void _createNewGroupConversation(BuildContext context) async {
 | 
			
		||||
@@ -329,6 +353,18 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void _changeConversationVisibility(
 | 
			
		||||
      Conversation conv, GroupMembershipLevel newLevel) async {
 | 
			
		||||
    try {
 | 
			
		||||
      await GroupsHelper.setConversationVisibility(conv.id, newLevel);
 | 
			
		||||
 | 
			
		||||
      _key.currentState.refresh();
 | 
			
		||||
    } catch (e, s) {
 | 
			
		||||
      logError(e, s);
 | 
			
		||||
      snack(context, tr("Failed to change conversation visibility level!"));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Widget _buildGroupLogoArea() {
 | 
			
		||||
    return SettingsSection(
 | 
			
		||||
      title: tr("Group logo"),
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,8 @@ class MultiChoicesSettingsTile<T> extends SettingsTile {
 | 
			
		||||
  final List<MultiChoiceEntry<T>> choices;
 | 
			
		||||
  final T currentValue;
 | 
			
		||||
  final Function(T) onChanged;
 | 
			
		||||
  final Widget leading;
 | 
			
		||||
  final Widget trailing;
 | 
			
		||||
 | 
			
		||||
  const MultiChoicesSettingsTile({
 | 
			
		||||
    Key key,
 | 
			
		||||
@@ -18,6 +20,8 @@ class MultiChoicesSettingsTile<T> extends SettingsTile {
 | 
			
		||||
    @required this.choices,
 | 
			
		||||
    @required this.currentValue,
 | 
			
		||||
    @required this.onChanged,
 | 
			
		||||
    this.leading,
 | 
			
		||||
    this.trailing,
 | 
			
		||||
  })  : assert(title != null),
 | 
			
		||||
        assert(choices != null),
 | 
			
		||||
        assert(currentValue != null),
 | 
			
		||||
@@ -26,6 +30,8 @@ class MultiChoicesSettingsTile<T> extends SettingsTile {
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return SettingsTile(
 | 
			
		||||
      leading: leading,
 | 
			
		||||
      trailing: trailing,
 | 
			
		||||
      title: title,
 | 
			
		||||
      subtitle: choices.firstWhere((f) => f.id == currentValue).title,
 | 
			
		||||
      onPressed: (_) => _changeValue(context),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user