Skip to content

Commit

Permalink
Merge branch 'chore/emoji-repo-hashmap-only' into exp/wander
Browse files Browse the repository at this point in the history
  • Loading branch information
4ster1sk committed Nov 12, 2024
2 parents e5daec3 + bb1f335 commit 7e7e771
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 44 deletions.
5 changes: 2 additions & 3 deletions lib/model/misskey_emoji_data.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "package:collection/collection.dart";
import "package:miria/repository/emoji_repository.dart";

sealed class MisskeyEmojiData {
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
48 changes: 23 additions & 25 deletions lib/repository/emoji_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import "package:miria/repository/shared_preference_controller.dart";
import "package:misskey_dart/misskey_dart.dart";

abstract class EmojiRepository {
List<EmojiRepositoryData>? emoji;
Map<String, EmojiRepositoryData>? emojiMap;
Map<String, EmojiRepositoryData>? emoji;
Future<void> loadFromSourceIfNeed();
Future<void> loadFromSource();

Expand Down Expand Up @@ -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<String, EmojiRepositoryData>.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<String, EmojiRepositoryData>.fromIterable(
emoji!,
)
.toList()
..addAll(unicodeEmojis),
key: (e) => (e as EmojiRepositoryData).emoji.baseName,
value: (e) => e,
);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions lib/view/dialogs/note_detail_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class NoteDetailDialogState extends ConsumerState<NoteDetailDialog> {
foundEmojis.addAll(
ref
.read(emojiRepositoryProvider(widget.account))
.emoji
?.where(
.emoji?.values
.where(
(element) =>
element.emoji.baseName
.contains(reactionTextField.text) ||
Expand Down
6 changes: 3 additions & 3 deletions lib/view/reaction_picker_dialog/reaction_picker_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class ReactionPickerContentState extends ConsumerState<ReactionPickerContent> {
categoryList
..clear()
..addAll(
emojiRepository.emoji
?.map((e) => e.category)
emojiRepository.emoji?.values
.map((e) => e.category)
.toSet()
.toList()
.whereNotNull() ??
Expand Down Expand Up @@ -79,7 +79,7 @@ class ReactionPickerContentState extends ConsumerState<ReactionPickerContent> {
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(
Expand Down
13 changes: 2 additions & 11 deletions test/test_util/mock.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1007,24 +1007,15 @@ 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<String, _i19.EmojiRepositoryData>? _emoji) =>
super.noSuchMethod(
Invocation.setter(
#emoji,
_emoji,
),
returnValueForMissingStub: null,
);

@override
set emojiMap(Map<String, _i19.EmojiRepositoryData>? _emojiMap) =>
super.noSuchMethod(
Invocation.setter(
#emojiMap,
_emojiMap,
),
returnValueForMissingStub: null,
);

@override
_i15.Future<void> loadFromSourceIfNeed() => (super.noSuchMethod(
Invocation.method(
Expand Down

0 comments on commit 7e7e771

Please sign in to comment.