Add chat message delay setting (#90)

This commit is contained in:
Tommy Chow 2022-05-24 23:45:14 -04:00
parent 639f8d372c
commit 2ba2b72851
4 changed files with 50 additions and 4 deletions

View file

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

View file

@ -37,9 +37,25 @@ class _ChatSettingsState extends State<ChatSettings> {
),
),
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'),

View file

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

View file

@ -40,7 +40,8 @@ SettingsStore _$SettingsStoreFromJson(Map<String, dynamic> 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<String, dynamic> _$SettingsStoreToJson(SettingsStore instance) =>
<String, dynamic>{
@ -70,6 +71,7 @@ Map<String, dynamic> _$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}
''';
}
}