diff --git a/lib/lists/custom_emojies_list.dart b/lib/lists/custom_emojies_list.dart index d967008..043ec56 100644 --- a/lib/lists/custom_emojies_list.dart +++ b/lib/lists/custom_emojies_list.dart @@ -6,6 +6,10 @@ import 'package:comunic/models/custom_emoji.dart'; /// @author Pierre HUBERT class CustomEmojiesList extends AbstractList { + /// Check if an emoji, identified by its shortcut, is present in this list + bool hasShortcut(String shortcut) => + firstWhere((f) => f.shortcut == shortcut, orElse: () => null) != null; + /// Serialize this list List> toSerializableList() => map((f) => f.toMap()).toList(); diff --git a/lib/ui/routes/account_settings/custom_emojies_account_settings.dart b/lib/ui/routes/account_settings/custom_emojies_account_settings.dart index b34985c..953a67f 100644 --- a/lib/ui/routes/account_settings/custom_emojies_account_settings.dart +++ b/lib/ui/routes/account_settings/custom_emojies_account_settings.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:comunic/helpers/settings_helper.dart'; import 'package:comunic/helpers/users_helper.dart'; +import 'package:comunic/lists/custom_emojies_list.dart'; import 'package:comunic/models/new_emoji.dart'; import 'package:comunic/models/user.dart'; import 'package:comunic/ui/widgets/async_screen_widget.dart'; @@ -90,7 +91,9 @@ class _CustomEmojiesAccountBodyState extends State<_CustomEmojiesAccountBody> { try { final newEmoji = await showDialog( context: context, - builder: (c) => _NewCustomEmojiDialog(), + builder: (c) => _NewCustomEmojiDialog( + currentList: _user.customEmojies, + ), ); if (newEmoji == null) return; @@ -107,6 +110,14 @@ class _CustomEmojiesAccountBodyState extends State<_CustomEmojiesAccountBody> { /// Dialog used to upload new custom emojies class _NewCustomEmojiDialog extends StatefulWidget { + final CustomEmojiesList currentList; + + const _NewCustomEmojiDialog({ + Key key, + @required this.currentList, + }) : assert(currentList != null), + super(key: key); + @override _NewCustomEmojiDialogState createState() => _NewCustomEmojiDialogState(); } @@ -120,7 +131,9 @@ class _NewCustomEmojiDialogState extends State<_NewCustomEmojiDialog> { String get _shortcut => _controller.text; bool get _shortcutValid => - _shortcut.isNotEmpty && validateShortcut(_shortcut); + _shortcut.isNotEmpty && + validateShortcut(_shortcut) && + !widget.currentList.hasShortcut(_shortcut); bool get _valid => _hasImage && _shortcutValid;