diff --git a/lib/screens/channel/chat/emote_menu/emote_menu.dart b/lib/screens/channel/chat/emote_menu/emote_menu.dart index 739faf65..de8f8011 100644 --- a/lib/screens/channel/chat/emote_menu/emote_menu.dart +++ b/lib/screens/channel/chat/emote_menu/emote_menu.dart @@ -4,6 +4,7 @@ import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:frosty/screens/channel/chat/emote_menu/emote_menu_panel.dart'; import 'package:frosty/screens/channel/chat/emote_menu/recent_emotes_panel.dart'; import 'package:frosty/screens/channel/stores/chat_store.dart'; +import 'package:frosty/widgets/alert_message.dart'; import 'package:frosty/widgets/button.dart'; class EmoteMenu extends StatefulWidget { @@ -41,33 +42,55 @@ class _EmoteMenuState extends State { SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( - children: sections - .mapIndexed( - (index, section) => Padding( - padding: const EdgeInsets.only(right: 5.0), - child: Observer( - builder: (context) => Button( - onPressed: () { - _pageContoller.animateToPage( - index, - duration: const Duration(milliseconds: 200), - curve: Curves.ease, - ); - widget.chatStore.assetsStore.emoteMenuIndex = index; - }, - color: index == widget.chatStore.assetsStore.emoteMenuIndex ? Theme.of(context).colorScheme.secondary : Colors.grey, - child: Text( - section, - style: const TextStyle( - letterSpacing: 0.8, - fontWeight: FontWeight.w600, - ), + children: [ + ...sections.mapIndexed( + (index, section) => Padding( + padding: const EdgeInsets.only(right: 5.0), + child: Observer( + builder: (context) => Button( + onPressed: () { + _pageContoller.animateToPage( + index, + duration: const Duration(milliseconds: 200), + curve: Curves.ease, + ); + widget.chatStore.assetsStore.emoteMenuIndex = index; + }, + color: index == widget.chatStore.assetsStore.emoteMenuIndex ? Theme.of(context).colorScheme.secondary : Colors.grey, + child: Text( + section, + style: const TextStyle( + letterSpacing: 0.8, + fontWeight: FontWeight.w600, ), ), ), ), - ) - .toList(), + ), + ), + Button( + onPressed: () async { + await widget.chatStore.getAssets(); + + if (!mounted) return; + + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: AlertMessage(message: 'Emotes refreshed'), + behavior: SnackBarBehavior.floating, + ), + ); + }, + color: Theme.of(context).colorScheme.secondary, + child: const Text( + 'REFRESH EMOTES', + style: TextStyle( + letterSpacing: 0.8, + fontWeight: FontWeight.w600, + ), + ), + ), + ], ), ), Expanded( diff --git a/lib/screens/channel/stores/chat_assets_store.dart b/lib/screens/channel/stores/chat_assets_store.dart index 0b0f52a5..43610631 100644 --- a/lib/screens/channel/stores/chat_assets_store.dart +++ b/lib/screens/channel/stores/chat_assets_store.dart @@ -159,10 +159,8 @@ abstract class ChatAssetsStoreBase with Store { required Function onError, }) => Future.wait([ - twitchApi - .getBadgesGlobal() - .then((badges) => twitchBadgesToObject.addAll(badges)) - .then((_) => twitchApi.getBadgesChannel(id: channelId).then((badges) => twitchBadgesToObject.addAll(badges)).catchError(onError)), + twitchApi.getBadgesGlobal().then((badges) => twitchBadgesToObject.addAll(badges)).catchError(onError), + twitchApi.getBadgesChannel(id: channelId).then((badges) => twitchBadgesToObject.addAll(badges)).catchError(onError), ffzApi.getBadges().then((badges) => _userToFFZBadges = badges).catchError(onError), sevenTVApi.getBadges().then((badges) => _userTo7TVBadges = badges).catchError(onError), bttvApi.getBadges().then((badges) => _userToBTTVBadges = badges).catchError(onError), diff --git a/lib/screens/channel/stores/chat_store.dart b/lib/screens/channel/stores/chat_store.dart index b8d1d4e9..31c36b54 100644 --- a/lib/screens/channel/stores/chat_store.dart +++ b/lib/screens/channel/stores/chat_store.dart @@ -231,19 +231,8 @@ abstract class ChatStoreBase with Store { } else if (message.contains('Welcome, GLHF!')) { _messages.add(IRCMessage.createNotice(message: "Connected to $displayName${regexEnglish.hasMatch(displayName) ? '' : ' ($channelName)'}'s chat!")); - // Fetch the assets used in chat including badges and emotes. - assetsStore.assetsFuture( - channelId: channelId, - headers: auth.headersTwitch, - onEmoteError: (error) { - debugPrint(error.toString()); - return []; - }, - onBadgeError: (error) { - debugPrint(error.toString()); - return []; - }, - ); + getAssets(); + // Reset exponential backoff if successfully connected. _retries = 0; _backoffTime = 0; @@ -251,6 +240,21 @@ abstract class ChatStoreBase with Store { } } + // Fetch the assets used in chat including badges and emotes. + @action + Future getAssets() async => assetsStore.assetsFuture( + channelId: channelId, + headers: auth.headersTwitch, + onEmoteError: (error) { + debugPrint(error.toString()); + return []; + }, + onBadgeError: (error) { + debugPrint(error.toString()); + return []; + }, + ); + /// Re-enables [_autoScroll] and jumps to the latest message. @action void resumeScroll() {