Follow the manifest to load emotes

This commit is contained in:
LittleSheep 2024-08-04 01:53:52 +08:00
parent ebe381053e
commit 8067c35c70
3 changed files with 19 additions and 10 deletions

View File

@ -11,6 +11,7 @@ import 'package:solian/bootstrapper.dart';
import 'package:solian/firebase_options.dart'; import 'package:solian/firebase_options.dart';
import 'package:solian/platform.dart'; import 'package:solian/platform.dart';
import 'package:solian/providers/attachment_uploader.dart'; import 'package:solian/providers/attachment_uploader.dart';
import 'package:solian/providers/stickers.dart';
import 'package:solian/providers/theme_switcher.dart'; import 'package:solian/providers/theme_switcher.dart';
import 'package:solian/providers/websocket.dart'; import 'package:solian/providers/websocket.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
@ -120,6 +121,7 @@ class SolianApp extends StatelessWidget {
Get.lazyPut(() => AuthProvider()); Get.lazyPut(() => AuthProvider());
Get.lazyPut(() => RelationshipProvider()); Get.lazyPut(() => RelationshipProvider());
Get.lazyPut(() => PostProvider()); Get.lazyPut(() => PostProvider());
Get.lazyPut(() => StickerProvider());
Get.lazyPut(() => AttachmentProvider()); Get.lazyPut(() => AttachmentProvider());
Get.lazyPut(() => WebSocketProvider()); Get.lazyPut(() => WebSocketProvider());
Get.lazyPut(() => StatusProvider()); Get.lazyPut(() => StatusProvider());

View File

@ -4,8 +4,8 @@ import 'package:solian/models/stickers.dart';
import 'package:solian/services.dart'; import 'package:solian/services.dart';
class StickerProvider extends GetxController { class StickerProvider extends GetxController {
final RxMap<String, String> _aliasImageMapping = RxMap(); final RxMap<String, String> aliasImageMapping = RxMap();
final RxMap<String, List<Sticker>> _availableStickers = RxMap(); final RxMap<String, List<Sticker>> availableStickers = RxMap();
Future<void> refreshAvailableStickers() async { Future<void> refreshAvailableStickers() async {
final client = ServiceFinder.configureClient('files'); final client = ServiceFinder.configureClient('files');
@ -24,15 +24,15 @@ class StickerProvider extends GetxController {
'files', 'files',
'/attachments/${sticker.attachmentId}', '/attachments/${sticker.attachmentId}',
); );
_aliasImageMapping['${pack.prefix}${sticker.alias}'.camelCase!] = aliasImageMapping['${pack.prefix}${sticker.alias}'.camelCase!] =
imageUrl; imageUrl;
if (_availableStickers[pack.prefix] == null) { if (availableStickers[pack.prefix] == null) {
_availableStickers[pack.prefix] = List.empty(growable: true); availableStickers[pack.prefix] = List.empty(growable: true);
} }
_availableStickers[pack.prefix]!.add(sticker); availableStickers[pack.prefix]!.add(sticker);
} }
} }
} }
_availableStickers.refresh(); availableStickers.refresh();
} }
} }

View File

@ -1,7 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_markdown_selectionarea/flutter_markdown.dart'; import 'package:flutter_markdown_selectionarea/flutter_markdown.dart';
import 'package:get/get.dart';
import 'package:markdown/markdown.dart' as markdown; import 'package:markdown/markdown.dart' as markdown;
import 'package:markdown/markdown.dart'; import 'package:markdown/markdown.dart';
import 'package:solian/providers/stickers.dart';
import 'package:url_launcher/url_launcher_string.dart'; import 'package:url_launcher/url_launcher_string.dart';
import 'account/account_profile_popup.dart'; import 'account/account_profile_popup.dart';
@ -101,10 +103,15 @@ class _CustomEmoteInlineSyntax extends InlineSyntax {
@override @override
bool onMatch(markdown.InlineParser parser, Match match) { bool onMatch(markdown.InlineParser parser, Match match) {
// final alias = match[1]!; final StickerProvider sticker = Get.find();
// TODO mapping things... final alias = match[1]!;
if (sticker.aliasImageMapping[alias] == null) {
parser.advanceBy(1);
return false;
}
final element = markdown.Element.empty('img'); final element = markdown.Element.empty('img');
element.attributes['src'] = 'https://www.twitch.tv/creatorcamp/assets/uploads/lul.png'; element.attributes['src'] = sticker.aliasImageMapping[alias]!;
parser.addNode(element); parser.addNode(element);
return true; return true;