diff --git a/lib/screens/channel/stores/chat_store.dart b/lib/screens/channel/stores/chat_store.dart index 2595daeb..0bad1baf 100644 --- a/lib/screens/channel/stores/chat_store.dart +++ b/lib/screens/channel/stores/chat_store.dart @@ -103,6 +103,10 @@ abstract class ChatStoreBase with Store { _messages.add(IRCMessage.createNotice(message: 'Connecting to chat...')); + if (settings.chatDelay > 0) { + _messages.add(IRCMessage.createNotice(message: 'Waiting ${settings.chatDelay.toInt()} seconds due to chat delay setting...')); + } + connectToChat(); // Tell the scrollController to determine when auto-scroll should be enabled or disabled. @@ -250,7 +254,7 @@ abstract class ChatStoreBase with Store { // Listen for new messages and forward them to the handler. _channel?.stream.listen( - (data) => _handleIRCData(data.toString()), + (data) => Future.delayed(Duration(seconds: settings.chatDelay.toInt()), () => _handleIRCData(data.toString())), onError: (error) => debugPrint('Chat error: ${error.toString()}'), onDone: () async { if (_channel == null) return; diff --git a/lib/screens/settings/sections/chat_settings.dart b/lib/screens/settings/sections/chat_settings.dart index 5d7859ca..dfe4ca31 100644 --- a/lib/screens/settings/sections/chat_settings.dart +++ b/lib/screens/settings/sections/chat_settings.dart @@ -37,9 +37,25 @@ class _ChatSettingsState extends State { ), ), children: [ + ListTile( + title: Row( + children: [ + const Text('Message Delay'), + const Spacer(), + Text('${settingsStore.chatDelay.toInt()} seconds'), + ], + ), + subtitle: Slider.adaptive( + value: settingsStore.chatDelay, + min: 0.0, + max: 30.0, + divisions: 30, + onChanged: (newValue) => settingsStore.chatDelay = newValue, + ), + ), const SectionHeader( 'Layout', - padding: EdgeInsets.only(left: 15.0, bottom: 5.0, top: 20.0), + padding: sectionPadding, ), SwitchListTile.adaptive( title: const Text('Bottom Bar'), diff --git a/lib/screens/settings/stores/settings_store.dart b/lib/screens/settings/stores/settings_store.dart index f81832e4..ad1bffa6 100644 --- a/lib/screens/settings/stores/settings_store.dart +++ b/lib/screens/settings/stores/settings_store.dart @@ -91,6 +91,8 @@ abstract class _SettingsStoreBase with Store { static const defaultLandscapeChatLeftSide = false; + static const defaultChatDelay = 0.0; + @JsonKey(defaultValue: defaultShowBottomBar) @observable var showBottomBar = defaultShowBottomBar; @@ -173,6 +175,10 @@ abstract class _SettingsStoreBase with Store { @observable var fullScreenChatOverlay = defaultFullScreenChatOverlay; + @JsonKey(defaultValue: defaultChatDelay) + @observable + var chatDelay = defaultChatDelay; + @action void reset() { // * General Settings @@ -202,6 +208,7 @@ abstract class _SettingsStoreBase with Store { emoteAutocomplete = defaultEmoteAutocomplete; landscapeChatWidth = defaultLandscapeChatWidth; landscapeChatLeftSide = false; + chatDelay = defaultChatDelay; // * Other settings sendCrashLogs = defaultSendCrashLogs; diff --git a/lib/screens/settings/stores/settings_store.g.dart b/lib/screens/settings/stores/settings_store.g.dart index 1e7f78ef..b786cdcd 100644 --- a/lib/screens/settings/stores/settings_store.g.dart +++ b/lib/screens/settings/stores/settings_store.g.dart @@ -40,7 +40,8 @@ SettingsStore _$SettingsStoreFromJson(Map json) => ..sendCrashLogs = json['sendCrashLogs'] as bool? ?? true ..fullScreen = json['fullScreen'] as bool? ?? false ..expandInfo = json['expandInfo'] as bool? ?? true - ..fullScreenChatOverlay = json['fullScreenChatOverlay'] as bool? ?? false; + ..fullScreenChatOverlay = json['fullScreenChatOverlay'] as bool? ?? false + ..chatDelay = (json['chatDelay'] as num?)?.toDouble() ?? 0.0; Map _$SettingsStoreToJson(SettingsStore instance) => { @@ -70,6 +71,7 @@ Map _$SettingsStoreToJson(SettingsStore instance) => 'fullScreen': instance.fullScreen, 'expandInfo': instance.expandInfo, 'fullScreenChatOverlay': instance.fullScreenChatOverlay, + 'chatDelay': instance.chatDelay, }; const _$ThemeTypeEnumMap = { @@ -511,6 +513,22 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { }); } + late final _$chatDelayAtom = + Atom(name: '_SettingsStoreBase.chatDelay', context: context); + + @override + double get chatDelay { + _$chatDelayAtom.reportRead(); + return super.chatDelay; + } + + @override + set chatDelay(double value) { + _$chatDelayAtom.reportWrite(value, super.chatDelay, () { + super.chatDelay = value; + }); + } + late final _$_SettingsStoreBaseActionController = ActionController(name: '_SettingsStoreBase', context: context); @@ -553,7 +571,8 @@ landscapeChatLeftSide: ${landscapeChatLeftSide}, sendCrashLogs: ${sendCrashLogs}, fullScreen: ${fullScreen}, expandInfo: ${expandInfo}, -fullScreenChatOverlay: ${fullScreenChatOverlay} +fullScreenChatOverlay: ${fullScreenChatOverlay}, +chatDelay: ${chatDelay} '''; } }