Remove message limit setting, tweak padding

This commit is contained in:
Tommy Chow 2021-12-28 20:03:37 -05:00
parent 816d3ce2c3
commit ef58b9340c
5 changed files with 15 additions and 54 deletions

View file

@ -21,25 +21,6 @@ class Settings extends StatelessWidget {
return ListView(
children: [
ProfileCard(authStore: context.read<AuthStore>()),
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,

View file

@ -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));

View file

@ -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},

View file

@ -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.

View file

@ -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,