From ebe381053ea146e07cd8b9933be2d56d54b45cce Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 4 Aug 2024 01:37:54 +0800 Subject: [PATCH] :sparkles: Load emojis --- lib/bootstrapper.dart | 2 ++ lib/providers/stickers.dart | 35 ++++++++++++++++++++++++++++++- lib/screens/account/stickers.dart | 3 +++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/bootstrapper.dart b/lib/bootstrapper.dart index 7aabad0..d8fe841 100644 --- a/lib/bootstrapper.dart +++ b/lib/bootstrapper.dart @@ -8,6 +8,7 @@ import 'package:solian/providers/auth.dart'; import 'package:solian/providers/content/channel.dart'; import 'package:solian/providers/content/realm.dart'; import 'package:solian/providers/relation.dart'; +import 'package:solian/providers/stickers.dart'; import 'package:solian/providers/theme_switcher.dart'; import 'package:solian/providers/websocket.dart'; import 'package:solian/services.dart'; @@ -116,6 +117,7 @@ class _BootstrapperShellState extends State { Get.find().refreshAvailableRealms(), Get.find().refreshAvailableChannel(), Get.find().refreshRelativeList(), + Get.find().refreshAvailableStickers(), ]); } }, diff --git a/lib/providers/stickers.dart b/lib/providers/stickers.dart index 1920f8e..fe242d5 100644 --- a/lib/providers/stickers.dart +++ b/lib/providers/stickers.dart @@ -1,5 +1,38 @@ import 'package:get/get.dart'; +import 'package:solian/models/pagination.dart'; +import 'package:solian/models/stickers.dart'; +import 'package:solian/services.dart'; class StickerProvider extends GetxController { + final RxMap _aliasImageMapping = RxMap(); + final RxMap> _availableStickers = RxMap(); -} \ No newline at end of file + Future refreshAvailableStickers() async { + final client = ServiceFinder.configureClient('files'); + final resp = await client.get( + '/stickers/manifest?take=100', + ); + if (resp.statusCode == 200) { + final result = PaginationResult.fromJson(resp.body); + final out = result.data?.map((e) => StickerPack.fromJson(e)).toList(); + if (out == null) return; + + for (final pack in out) { + for (final sticker in (pack.stickers ?? List.empty())) { + sticker.pack = pack; + final imageUrl = ServiceFinder.buildUrl( + 'files', + '/attachments/${sticker.attachmentId}', + ); + _aliasImageMapping['${pack.prefix}${sticker.alias}'.camelCase!] = + imageUrl; + if (_availableStickers[pack.prefix] == null) { + _availableStickers[pack.prefix] = List.empty(growable: true); + } + _availableStickers[pack.prefix]!.add(sticker); + } + } + } + _availableStickers.refresh(); + } +} diff --git a/lib/screens/account/stickers.dart b/lib/screens/account/stickers.dart index 2de3cff..64e68d8 100644 --- a/lib/screens/account/stickers.dart +++ b/lib/screens/account/stickers.dart @@ -6,6 +6,7 @@ import 'package:solian/models/pagination.dart'; import 'package:solian/models/stickers.dart'; import 'package:solian/platform.dart'; import 'package:solian/providers/auth.dart'; +import 'package:solian/providers/stickers.dart'; import 'package:solian/services.dart'; import 'package:solian/widgets/stickers/sticker_uploader.dart'; @@ -132,6 +133,8 @@ class _StickerScreenState extends State { @override void dispose() { + final StickerProvider sticker = Get.find(); + sticker.refreshAvailableStickers(); _pagingController.dispose(); super.dispose(); }