From ef58b9340cde969a29f8f74a243d7ef5ec20631e Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Tue, 28 Dec 2021 20:03:37 -0500 Subject: [PATCH] Remove message limit setting, tweak padding --- lib/core/settings/settings.dart | 19 -------------- lib/core/settings/settings_store.dart | 5 ---- lib/core/settings/settings_store.g.dart | 16 ------------ lib/screens/channel/chat/chat_store.dart | 25 ++++++++++--------- .../chat/emote_menu/emote_menu_panel.dart | 4 +-- 5 files changed, 15 insertions(+), 54 deletions(-) diff --git a/lib/core/settings/settings.dart b/lib/core/settings/settings.dart index 95262074..45001090 100644 --- a/lib/core/settings/settings.dart +++ b/lib/core/settings/settings.dart @@ -21,25 +21,6 @@ class Settings extends StatelessWidget { return ListView( children: [ ProfileCard(authStore: context.read()), - ListTile( - title: Row( - children: [ - const Text('Chat Message Limit'), - const Spacer(), - Text( - settingsStore.messageLimit == 1000 ? 'Unlimited' : '${settingsStore.messageLimit.toInt()}', - style: const TextStyle(fontWeight: FontWeight.bold), - ), - ], - ), - subtitle: Slider.adaptive( - value: settingsStore.messageLimit, - onChanged: (newValue) => settingsStore.messageLimit = newValue, - min: 200, - max: 1000, - divisions: 4, - ), - ), SwitchListTile.adaptive( title: const Text('Enable Video'), value: settingsStore.videoEnabled, diff --git a/lib/core/settings/settings_store.dart b/lib/core/settings/settings_store.dart index a8d1dffd..cd0a4090 100644 --- a/lib/core/settings/settings_store.dart +++ b/lib/core/settings/settings_store.dart @@ -13,9 +13,6 @@ abstract class _SettingsStoreBase with Store { @observable var overlayEnabled = true; - @observable - var messageLimit = 200.0; - @observable var hideBannedMessages = false; @@ -35,14 +32,12 @@ abstract class _SettingsStoreBase with Store { // Initialize settings from stored preferences if any. videoEnabled = prefs.getBool('video_enabled') ?? videoEnabled; overlayEnabled = prefs.getBool('overlay_enabled') ?? overlayEnabled; - messageLimit = prefs.getDouble('message_limit') ?? messageLimit; hideBannedMessages = prefs.getBool('hide_banned_messages') ?? hideBannedMessages; zeroWidthEnabled = prefs.getBool('zero_width_enabled') ?? zeroWidthEnabled; expandInfo = prefs.getBool('expand_info') ?? expandInfo; // Set up reactions to store setting anytime they're changed. // The ReactionDisposer will not be needed since settings will always exist. - reaction((_) => messageLimit, (double newValue) => prefs.setDouble('message_limit', newValue)); reaction((_) => videoEnabled, (bool newValue) => prefs.setBool('video_enabled', newValue)); reaction((_) => overlayEnabled, (bool newValue) => prefs.setBool('overlay_enabled', newValue)); reaction((_) => zeroWidthEnabled, (bool newValue) => prefs.setBool('zero_width_enabled', newValue)); diff --git a/lib/core/settings/settings_store.g.dart b/lib/core/settings/settings_store.g.dart index 807d3d1a..8616721e 100644 --- a/lib/core/settings/settings_store.g.dart +++ b/lib/core/settings/settings_store.g.dart @@ -39,21 +39,6 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { }); } - final _$messageLimitAtom = Atom(name: '_SettingsStoreBase.messageLimit'); - - @override - double get messageLimit { - _$messageLimitAtom.reportRead(); - return super.messageLimit; - } - - @override - set messageLimit(double value) { - _$messageLimitAtom.reportWrite(value, super.messageLimit, () { - super.messageLimit = value; - }); - } - final _$hideBannedMessagesAtom = Atom(name: '_SettingsStoreBase.hideBannedMessages'); @@ -121,7 +106,6 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { return ''' videoEnabled: ${videoEnabled}, overlayEnabled: ${overlayEnabled}, -messageLimit: ${messageLimit}, hideBannedMessages: ${hideBannedMessages}, zeroWidthEnabled: ${zeroWidthEnabled}, fullScreen: ${fullScreen}, diff --git a/lib/screens/channel/chat/chat_store.dart b/lib/screens/channel/chat/chat_store.dart index 70cd1e1a..cf000f0b 100644 --- a/lib/screens/channel/chat/chat_store.dart +++ b/lib/screens/channel/chat/chat_store.dart @@ -185,7 +185,10 @@ abstract class _ChatStoreBase with Store { continue; } - _deleteAndScrollToEnd(); + if (_autoScroll) _deleteAndScrollToEnd(); + + // Hard upper-limit of 10000 messages to prevent infinite messages being added when scrolling. + if (_messages.length >= 10000) _messages.removeRange(0, 2000); } else if (message == 'PING :tmi.twitch.tv') { _channel.sink.add('PONG :tmi.twitch.tv'); return; @@ -196,19 +199,17 @@ abstract class _ChatStoreBase with Store { /// If [_autoScroll] is enabled, removes messages if [_messages] is too large and scrolls to the latest message. @action void _deleteAndScrollToEnd() { - if (_autoScroll) { - // If there are more messages than the limit, remove around 10% of them from the oldest. - if (_messages.length > settings.messageLimit && settings.messageLimit != 1000) _messages.removeRange(0, (settings.messageLimit / 5).ceil()); + // If we reach 1000 messages, remove the oldest 200. + if (_messages.length >= 1000) _messages.removeRange(0, 200); - // Jump to the latest message (bottom of the list/chat). + // Jump to the latest message (bottom of the list/chat). + if (scrollController.hasClients) scrollController.jumpTo(scrollController.position.maxScrollExtent); + + // After the end of the frame, scroll to the bottom of the chat. + // This is a postFrameCallback because the chat should scroll after the widget is built and rendered. + SchedulerBinding.instance?.addPostFrameCallback((_) { if (scrollController.hasClients) scrollController.jumpTo(scrollController.position.maxScrollExtent); - - // After the end of the frame, scroll to the bottom of the chat. - // This is a postFrameCallback because the chat should scroll after the widget is built and rendered. - SchedulerBinding.instance?.addPostFrameCallback((_) { - if (scrollController.hasClients) scrollController.jumpTo(scrollController.position.maxScrollExtent); - }); - } + }); } /// Re-enables [_autoScroll] and jumps to the latest message. diff --git a/lib/screens/channel/chat/emote_menu/emote_menu_panel.dart b/lib/screens/channel/chat/emote_menu/emote_menu_panel.dart index 85096a63..072c7878 100644 --- a/lib/screens/channel/chat/emote_menu/emote_menu_panel.dart +++ b/lib/screens/channel/chat/emote_menu/emote_menu_panel.dart @@ -11,7 +11,7 @@ class EmoteMenuPanel extends StatelessWidget { @override Widget build(BuildContext context) { const headerStyle = TextStyle(fontSize: 20, fontWeight: FontWeight.bold); - const headerPadding = EdgeInsets.fromLTRB(10.0, 30.0, 10.0, 10.0); + const headerPadding = EdgeInsets.fromLTRB(10.0, 30.0, 10.0, 5.0); final globalEmotes = emotes .where((emote) => @@ -38,7 +38,7 @@ class EmoteMenuPanel extends StatelessWidget { if (globalEmotes.isNotEmpty) ...[ const SliverToBoxAdapter( child: Padding( - padding: EdgeInsets.all(10.0), + padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0), child: Text( 'Global Emotes', style: headerStyle,