diff --git a/lib/models/stickers.dart b/lib/models/stickers.dart index 8976d0c..bc57852 100644 --- a/lib/models/stickers.dart +++ b/lib/models/stickers.dart @@ -32,7 +32,7 @@ class Sticker { required this.account, }); - String get textPlaceholder => '${pack?.prefix}$alias'.camelCase!; + String get textPlaceholder => '${pack?.prefix}$alias'; String get textWarpedPlaceholder => ':$textPlaceholder:'; String get imageUrl => ServiceFinder.buildUrl( diff --git a/lib/providers/stickers.dart b/lib/providers/stickers.dart index 0173f08..1838887 100644 --- a/lib/providers/stickers.dart +++ b/lib/providers/stickers.dart @@ -8,6 +8,9 @@ class StickerProvider extends GetxController { final RxList availableStickers = RxList.empty(growable: true); Future refreshAvailableStickers() async { + availableStickers.clear(); + aliasImageMapping.clear(); + final client = ServiceFinder.configureClient('files'); final resp = await client.get( '/stickers/manifest?take=100', @@ -20,7 +23,7 @@ class StickerProvider extends GetxController { for (final pack in out) { for (final sticker in (pack.stickers ?? List.empty())) { sticker.pack = pack; - aliasImageMapping['${pack.prefix}${sticker.alias}'.camelCase!] = + aliasImageMapping[sticker.textPlaceholder.toUpperCase()] = sticker.imageUrl; availableStickers.add(sticker); } diff --git a/lib/screens/account/stickers.dart b/lib/screens/account/stickers.dart index 17c0701..fe2a763 100644 --- a/lib/screens/account/stickers.dart +++ b/lib/screens/account/stickers.dart @@ -70,7 +70,7 @@ class _StickerScreenState extends State { ); return ListTile( title: Text(item.name), - subtitle: Text(':${'$prefix${item.alias}'.camelCase}:'), + subtitle: Text(item.textWarpedPlaceholder), contentPadding: const EdgeInsets.only(left: 16, right: 14), trailing: Row( mainAxisSize: MainAxisSize.min, @@ -174,9 +174,10 @@ class _StickerScreenState extends State { maxLines: 1, overflow: TextOverflow.ellipsis, ), - children: item.stickers - ?.map((x) => _buildEmoteEntry(x, item.prefix)) - .toList() ?? + children: item.stickers?.map((x) { + x.pack = item; + return _buildEmoteEntry(x, item.prefix); + }).toList() ?? List.empty(), ); }, diff --git a/lib/widgets/chat/chat_message_input.dart b/lib/widgets/chat/chat_message_input.dart index 90ab56d..685d092 100644 --- a/lib/widgets/chat/chat_message_input.dart +++ b/lib/widgets/chat/chat_message_input.dart @@ -239,7 +239,7 @@ class _ChatMessageInputState extends State { if (suggestion.type == 'emotes') { insertText = suggestion.content; startText = replaceText.replaceFirstMapped( - RegExp(r':(?:([a-z0-9_+-]+)~)?([a-z0-9_+-]+)$'), + RegExp(r':(?:([-\w]+)~)?([-\w]+)$'), (Match m) => insertText, ); } @@ -247,7 +247,7 @@ class _ChatMessageInputState extends State { if (suggestion.type == 'users') { insertText = suggestion.content; startText = replaceText.replaceFirstMapped( - RegExp(r'(?:\s|^)@([a-z0-9_+-]+)$'), + RegExp(r'(?:\s|^)@([-\w]+)$'), (Match m) => insertText, ); } @@ -349,15 +349,17 @@ class _ChatMessageInputState extends State { final searchText = _textController.text .substring(0, _textController.selection.baseOffset); - final emojiMatch = - RegExp(r':(?:([a-z0-9_+-]+)~)?([a-z0-9_+-]+)$') - .firstMatch(searchText); + final emojiMatch = RegExp(r':(?:([-\w]+)~)?([-\w]+)$') + .firstMatch(searchText); if (emojiMatch != null) { final StickerProvider stickers = Get.find(); final emoteSearch = emojiMatch[2]!; return stickers.availableStickers - .where((x) => - x.textWarpedPlaceholder.contains(emoteSearch)) + .where( + (x) => x.textWarpedPlaceholder + .toUpperCase() + .contains(emoteSearch.toUpperCase()), + ) .map( (x) => ChatMessageSuggestion( type: 'emotes', @@ -379,8 +381,8 @@ class _ChatMessageInputState extends State { .toList(); } - final userMatch = RegExp(r'(?:\s|^)@([a-z0-9_+-]+)$') - .firstMatch(searchText); + final userMatch = + RegExp(r'(?:\s|^)@([-\w]+)$').firstMatch(searchText); if (userMatch != null) { final userSearch = userMatch[1]!.toLowerCase(); final AuthProvider auth = Get.find(); diff --git a/lib/widgets/markdown_text_content.dart b/lib/widgets/markdown_text_content.dart index f41fd5e..f0e995f 100644 --- a/lib/widgets/markdown_text_content.dart +++ b/lib/widgets/markdown_text_content.dart @@ -24,9 +24,9 @@ class MarkdownTextContent extends StatelessWidget { }); Widget _buildContent(BuildContext context) { - final emojiMatch = RegExp(r':([a-z0-9_+-]+):').allMatches(content); - final isOnlyEmoji = - content.replaceAll(RegExp(r':([a-z0-9_+-]+):'), '').trim().isEmpty; + final emojiRegex = RegExp(r':([-\w]+):'); + final emojiMatch = emojiRegex.allMatches(content); + final isOnlyEmoji = content.replaceAll(emojiRegex, '').trim().isEmpty; return Markdown( shrinkWrap: true, @@ -89,7 +89,7 @@ class MarkdownTextContent extends StatelessWidget { switch (segments[0]) { case 'stickers': final StickerProvider sticker = Get.find(); - url = sticker.aliasImageMapping[segments[1]]!; + url = sticker.aliasImageMapping[segments[1].toUpperCase()]!; if (emojiMatch.length <= 1 && isOnlyEmoji) { width = 112; height = 112; @@ -161,12 +161,12 @@ class _UserNameCardInlineSyntax extends InlineSyntax { } class _CustomEmoteInlineSyntax extends InlineSyntax { - _CustomEmoteInlineSyntax() : super(r':([a-z0-9_+-]+):'); + _CustomEmoteInlineSyntax() : super(r':([-\w]+):'); @override bool onMatch(markdown.InlineParser parser, Match match) { final StickerProvider sticker = Get.find(); - final alias = match[1]!; + final alias = match[1]!.toUpperCase(); if (sticker.aliasImageMapping[alias] == null) { parser.advanceBy(1); return false;