diff --git a/lib/screens/channel/stores/chat_store.dart b/lib/screens/channel/stores/chat_store.dart index 5aa25260..efab450b 100644 --- a/lib/screens/channel/stores/chat_store.dart +++ b/lib/screens/channel/stores/chat_store.dart @@ -19,6 +19,7 @@ part 'chat_store.g.dart'; class ChatStore = _ChatStoreBase with _$ChatStore; abstract class _ChatStoreBase with Store { + static const _messageUpperLimit = 7500; static const _messageLimit = 5000; /// The provided auth store to determine login status, get the token, and use the headers for requests. @@ -195,6 +196,10 @@ abstract class _ChatStoreBase with Store { }); } + // Remove messages when an upper limit is reached. + // This will prevent an infinite amount of messages when autoscroll is off. + if (_messages.length >= _messageUpperLimit) _messages.removeRange(0, 500); + // Hard upper-limit of 5000 messages to prevent infinite messages being added when scrolling. } else if (message == 'PING :tmi.twitch.tv') { _channel?.sink.add('PONG :tmi.twitch.tv'); @@ -240,7 +245,8 @@ abstract class _ChatStoreBase with Store { }); } - void reconnect() async { + @action + void reconnect() { _channel?.sink.close(1001); _channel = WebSocketChannel.connect(Uri.parse('wss://irc-ws.chat.twitch.tv:443')); diff --git a/lib/screens/channel/stores/chat_store.g.dart b/lib/screens/channel/stores/chat_store.g.dart index 9cb2a66a..c3add336 100644 --- a/lib/screens/channel/stores/chat_store.g.dart +++ b/lib/screens/channel/stores/chat_store.g.dart @@ -85,6 +85,17 @@ mixin _$ChatStore on _ChatStoreBase, Store { } } + @override + void reconnect() { + final _$actionInfo = _$_ChatStoreBaseActionController.startAction( + name: '_ChatStoreBase.reconnect'); + try { + return super.reconnect(); + } finally { + _$_ChatStoreBaseActionController.endAction(_$actionInfo); + } + } + @override void sendMessage(String message) { final _$actionInfo = _$_ChatStoreBaseActionController.startAction(