From 6af80f5462e6ec19f4bdad8a0f65771aa44427e7 Mon Sep 17 00:00:00 2001 From: tommyxchow Date: Tue, 23 Nov 2021 20:03:54 -0500 Subject: [PATCH] Fix message limit removal [skip ci] --- lib/screens/channel/chat/chat.dart | 131 ++++++++++++----------- lib/screens/channel/chat/chat_store.dart | 2 +- lib/screens/channel/video_chat.dart | 85 +++++++-------- 3 files changed, 109 insertions(+), 109 deletions(-) diff --git a/lib/screens/channel/chat/chat.dart b/lib/screens/channel/chat/chat.dart index ea3b44cc..da46b718 100644 --- a/lib/screens/channel/chat/chat.dart +++ b/lib/screens/channel/chat/chat.dart @@ -21,79 +21,82 @@ class _ChatState extends State { future: widget.chatStore.getAssets(), builder: (_, snapshot) { if (snapshot.connectionState == ConnectionState.done) { - return Column( - children: [ - Expanded( - child: Stack( - alignment: AlignmentDirectional.bottomCenter, + return GestureDetector( + onTap: () => FocusManager.instance.primaryFocus?.unfocus(), + child: Column( + children: [ + Expanded( + child: Stack( + alignment: AlignmentDirectional.bottomCenter, + children: [ + Observer( + builder: (_) { + return ListView.builder( + addAutomaticKeepAlives: false, + addRepaintBoundaries: false, + itemCount: widget.chatStore.messages.length, + controller: widget.chatStore.scrollController, + itemBuilder: (context, index) { + return widget.chatStore.renderChatMessage(widget.chatStore.messages[index], context); + }, + ); + }, + ), + Observer( + builder: (_) { + return Visibility( + visible: !widget.chatStore.autoScroll, + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 4.0), + width: double.infinity, + child: ElevatedButton( + onPressed: widget.chatStore.resumeScroll, + child: const Text('Resume Scroll'), + ), + ), + ); + }, + ), + ], + ), + ), + Row( children: [ - Observer( - builder: (_) { - return ListView.builder( - addAutomaticKeepAlives: false, - addRepaintBoundaries: false, - itemCount: widget.chatStore.messages.length, - controller: widget.chatStore.scrollController, - itemBuilder: (context, index) { - return widget.chatStore.renderChatMessage(widget.chatStore.messages[index], context); + IconButton( + icon: const Icon(Icons.stacked_bar_chart), + onPressed: () { + showModalBottomSheet( + context: context, + builder: (context) { + return ChatStats( + chatStore: widget.chatStore, + ); }, ); }, ), - Observer( - builder: (_) { - return Visibility( - visible: !widget.chatStore.autoScroll, - child: Container( - padding: const EdgeInsets.symmetric(horizontal: 4.0), - width: double.infinity, - child: ElevatedButton( - onPressed: widget.chatStore.resumeScroll, - child: const Text('Resume Scroll'), + if (context.read().isLoggedIn) + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0), + child: TextField( + decoration: const InputDecoration( + isDense: true, + contentPadding: EdgeInsets.all(10.0), + border: OutlineInputBorder( + borderRadius: BorderRadius.all(Radius.circular(10.0)), + ), + hintText: 'Send a message', ), + controller: widget.chatStore.textController, + onSubmitted: (string) => widget.chatStore.sendMessage(string), ), - ); - }, - ), - ], - ), - ), - Row( - children: [ - IconButton( - icon: const Icon(Icons.stacked_bar_chart), - onPressed: () { - showModalBottomSheet( - context: context, - builder: (context) { - return ChatStats( - chatStore: widget.chatStore, - ); - }, - ); - }, - ), - if (context.read().isLoggedIn) - Expanded( - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0), - child: TextField( - decoration: const InputDecoration( - isDense: true, - contentPadding: EdgeInsets.all(10.0), - border: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(10.0)), - ), - hintText: 'Send a message', - ), - controller: widget.chatStore.textController, - onSubmitted: (string) => widget.chatStore.sendMessage(string), ), ), - ), - ], - ) - ], + ], + ) + ], + ), ); } return const Center( diff --git a/lib/screens/channel/chat/chat_store.dart b/lib/screens/channel/chat/chat_store.dart index cf88a3e6..a5964a91 100644 --- a/lib/screens/channel/chat/chat_store.dart +++ b/lib/screens/channel/chat/chat_store.dart @@ -180,7 +180,7 @@ abstract class _ChatStoreBase with Store { 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, (messages.length - settings.messageLimit * 0.1).ceil()); + messages.removeRange(0, (settings.messageLimit - settings.messageLimit * 0.1).ceil()); } // After the end of the frame, scroll to the bottom of the chat. diff --git a/lib/screens/channel/video_chat.dart b/lib/screens/channel/video_chat.dart index 3d8fadff..90565143 100644 --- a/lib/screens/channel/video_chat.dart +++ b/lib/screens/channel/video_chat.dart @@ -26,55 +26,52 @@ class VideoChat extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( body: SafeArea( - child: GestureDetector( - onTap: () => FocusManager.instance.primaryFocus?.unfocus(), - child: Column( - children: [ - Observer( - builder: (_) { - if (context.read().videoEnabled) { - return AspectRatio( - aspectRatio: 16 / 9, - child: Video( - title: title, - userName: userName, - userLogin: userLogin, - videoStore: VideoStore(), - ), - ); - } - return AppBar( - title: Text( - userName, - style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + child: Column( + children: [ + Observer( + builder: (_) { + if (context.read().videoEnabled) { + return AspectRatio( + aspectRatio: 16 / 9, + child: Video( + title: title, + userName: userName, + userLogin: userLogin, + videoStore: VideoStore(), ), - actions: [ - IconButton( - icon: const Icon(Icons.settings), - onPressed: () { - showModalBottomSheet( - context: context, - builder: (context) { - return Settings(settingsStore: context.read()); - }, - ); - }, - ), - ], ); - }, - ), - Expanded( - child: Chat( - chatStore: ChatStore( - auth: context.read(), - settings: context.read(), - channelName: userLogin, + } + return AppBar( + title: Text( + userName, + style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), + actions: [ + IconButton( + icon: const Icon(Icons.settings), + onPressed: () { + showModalBottomSheet( + context: context, + builder: (context) { + return Settings(settingsStore: context.read()); + }, + ); + }, + ), + ], + ); + }, + ), + Expanded( + child: Chat( + chatStore: ChatStore( + auth: context.read(), + settings: context.read(), + channelName: userLogin, ), ), - ], - ), + ), + ], ), ), );