From bb1f33508574041517c8cc60e4489b06ca59c4f4 Mon Sep 17 00:00:00 2001 From: 4sterisk <4sterisk@ymail.ne.jp> Date: Tue, 12 Nov 2024 17:16:10 +0900 Subject: [PATCH] =?UTF-8?q?List=E3=81=A7=E3=81=AEEmojiRepositoryData?= =?UTF-8?q?=E3=81=AE=E4=BF=9D=E6=8C=81=E3=82=92=E3=82=84=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/model/misskey_emoji_data.dart | 5 +- lib/repository/emoji_repository.dart | 48 +++++++++---------- lib/view/dialogs/note_detail_dialog.dart | 4 +- .../reaction_picker_content.dart | 6 +-- test/test_util/mock.mocks.dart | 13 +---- 5 files changed, 32 insertions(+), 44 deletions(-) diff --git a/lib/model/misskey_emoji_data.dart b/lib/model/misskey_emoji_data.dart index 5f28692df..9ffc2efba 100644 --- a/lib/model/misskey_emoji_data.dart +++ b/lib/model/misskey_emoji_data.dart @@ -1,4 +1,3 @@ -import "package:collection/collection.dart"; import "package:miria/repository/emoji_repository.dart"; sealed class MisskeyEmojiData { @@ -46,7 +45,7 @@ sealed class MisskeyEmojiData { assert(repository != null); final name = customEmojiRegExp.firstMatch(emojiName)?.group(1) ?? emojiName; - final found = repository!.emojiMap?[name]; + final found = repository!.emoji?[name]; if (found != null) { return found.emoji; @@ -61,7 +60,7 @@ sealed class MisskeyEmojiData { assert(repository != null); final name = customEmojiRegExp2.firstMatch(emojiName)?.group(1) ?? emojiName; - final found = repository!.emojiMap?[name]; + final found = repository!.emoji?[name]; if (found != null) { return found.emoji; } else { diff --git a/lib/repository/emoji_repository.dart b/lib/repository/emoji_repository.dart index f02276d35..d75a5eb80 100644 --- a/lib/repository/emoji_repository.dart +++ b/lib/repository/emoji_repository.dart @@ -13,8 +13,7 @@ import "package:miria/repository/shared_preference_controller.dart"; import "package:misskey_dart/misskey_dart.dart"; abstract class EmojiRepository { - List? emoji; - Map? emojiMap; + Map? emoji; Future loadFromSourceIfNeed(); Future loadFromSource(); @@ -134,27 +133,26 @@ class EmojiRepositoryImpl extends EmojiRepository { ), ); - emoji = response.emojis - .map( - (e) => EmojiRepositoryData( - emoji: CustomEmojiData( - baseName: e.name, - hostedName: ":${e.name}@.:", - url: e.url, - isCurrentServer: true, - isSensitive: e.isSensitive, + + emoji = HashMap.fromIterable( + response.emojis + .map( + (e) => EmojiRepositoryData( + emoji: CustomEmojiData( + baseName: e.name, + hostedName: ":${e.name}@.:", + url: e.url, + isCurrentServer: true, + isSensitive: e.isSensitive, + ), + category: e.category ?? "", + kanaName: toH(format(e.name)), + aliases: e.aliases, + kanaAliases: e.aliases.map((e2) => format(toH(e2))).toList(), ), - category: e.category ?? "", - kanaName: toH(format(e.name)), - aliases: e.aliases, - kanaAliases: e.aliases.map((e2) => format(toH(e2))).toList(), - ), - ) - .toList(); - emoji!.addAll(unicodeEmojis); - - emojiMap = HashMap.fromIterable( - emoji!, + ) + .toList() + ..addAll(unicodeEmojis), key: (e) => (e as EmojiRepositoryData).emoji.baseName, value: (e) => e, ); @@ -189,8 +187,8 @@ class EmojiRepositoryImpl extends EmojiRepository { final converted = format(const KanaKit().toHiragana(name)); - return emoji - ?.where((element) => emojiSearchCondition(name, converted, element)) + return emoji?.values + .where((element) => emojiSearchCondition(name, converted, element)) .sorted((a, b) { final aValue = [ if (a.emoji.baseName.contains(name)) a.emoji.baseName, @@ -224,7 +222,7 @@ class EmojiRepositoryImpl extends EmojiRepository { return []; } else { return reactionDeck - .map((e) => emojiMap?[e]) + .map((e) => emoji?[e]) .whereNotNull() .map((e) => e.emoji) .toList(); diff --git a/lib/view/dialogs/note_detail_dialog.dart b/lib/view/dialogs/note_detail_dialog.dart index eb2a8ab6f..80026711f 100644 --- a/lib/view/dialogs/note_detail_dialog.dart +++ b/lib/view/dialogs/note_detail_dialog.dart @@ -40,8 +40,8 @@ class NoteDetailDialogState extends ConsumerState { foundEmojis.addAll( ref .read(emojiRepositoryProvider(widget.account)) - .emoji - ?.where( + .emoji?.values + .where( (element) => element.emoji.baseName .contains(reactionTextField.text) || diff --git a/lib/view/reaction_picker_dialog/reaction_picker_content.dart b/lib/view/reaction_picker_dialog/reaction_picker_content.dart index 967ed7b69..b0849020a 100644 --- a/lib/view/reaction_picker_dialog/reaction_picker_content.dart +++ b/lib/view/reaction_picker_dialog/reaction_picker_content.dart @@ -40,8 +40,8 @@ class ReactionPickerContentState extends ConsumerState { categoryList ..clear() ..addAll( - emojiRepository.emoji - ?.map((e) => e.category) + emojiRepository.emoji?.values + .map((e) => e.category) .toSet() .toList() .whereNotNull() ?? @@ -74,7 +74,7 @@ class ReactionPickerContentState extends ConsumerState { runSpacing: 5, crossAxisAlignment: WrapCrossAlignment.start, children: [ - for (final emoji in (emojiRepository.emoji ?? []).where( + for (final emoji in (emojiRepository.emoji?.values ?? []).where( (element) => element.category == categoryList[index], )) EmojiButton( diff --git a/test/test_util/mock.mocks.dart b/test/test_util/mock.mocks.dart index 6b0aba293..51bf20425 100644 --- a/test/test_util/mock.mocks.dart +++ b/test/test_util/mock.mocks.dart @@ -1007,7 +1007,8 @@ class MockAccountSettingsRepository extends _i1.Mock /// See the documentation for Mockito's code generation for more information. class MockEmojiRepository extends _i1.Mock implements _i19.EmojiRepository { @override - set emoji(List<_i19.EmojiRepositoryData>? _emoji) => super.noSuchMethod( + set emoji(Map? _emoji) => + super.noSuchMethod( Invocation.setter( #emoji, _emoji, @@ -1015,16 +1016,6 @@ class MockEmojiRepository extends _i1.Mock implements _i19.EmojiRepository { returnValueForMissingStub: null, ); - @override - set emojiMap(Map? _emojiMap) => - super.noSuchMethod( - Invocation.setter( - #emojiMap, - _emojiMap, - ), - returnValueForMissingStub: null, - ); - @override _i15.Future loadFromSourceIfNeed() => (super.noSuchMethod( Invocation.method(