Load emojis

This commit is contained in:
LittleSheep 2024-08-04 01:37:54 +08:00
parent 03f2470dae
commit ebe381053e
3 changed files with 39 additions and 1 deletions

View File

@ -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<BootstrapperShell> {
Get.find<RealmProvider>().refreshAvailableRealms(),
Get.find<ChannelProvider>().refreshAvailableChannel(),
Get.find<RelationshipProvider>().refreshRelativeList(),
Get.find<StickerProvider>().refreshAvailableStickers(),
]);
}
},

View File

@ -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<String, String> _aliasImageMapping = RxMap();
final RxMap<String, List<Sticker>> _availableStickers = RxMap();
}
Future<void> 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<Sticker>.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();
}
}

View File

@ -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<StickerScreen> {
@override
void dispose() {
final StickerProvider sticker = Get.find();
sticker.refreshAvailableStickers();
_pagingController.dispose();
super.dispose();
}