From efced086411990da6e51be1474eb0cb1481e8b53 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Mon, 12 Oct 2020 11:15:37 +0200 Subject: [PATCH] update llc dependency and hotfixes --- example/pubspec.yaml | 3 +-- lib/src/channels_bloc.dart | 3 ++- lib/src/message_list_view.dart | 21 +++++++++++++-------- lib/src/stream_channel.dart | 17 +++++++++++------ lib/src/thread_header.dart | 9 ++++++--- pubspec.yaml | 2 +- 6 files changed, 34 insertions(+), 21 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index c4c1f8cb..2ecf9668 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,7 +1,6 @@ name: example description: A new Flutter project. - -version: 1.0.12+13 +version: 1.0.20+21 environment: sdk: ">=2.2.2 <3.0.0" diff --git a/lib/src/channels_bloc.dart b/lib/src/channels_bloc.dart index df6f641b..3af2300d 100644 --- a/lib/src/channels_bloc.dart +++ b/lib/src/channels_bloc.dart @@ -135,7 +135,8 @@ class ChannelsBlocState extends State newChannels.insert(0, _hiddenChannels[hiddenIndex]); _hiddenChannels.removeAt(hiddenIndex); } else { - if (client.state.channels[e.cid] != null) { + if (client.state?.channels != null && + client.state?.channels[e.cid] != null) { newChannels.insert(0, client.state.channels[e.cid]); } } diff --git a/lib/src/message_list_view.dart b/lib/src/message_list_view.dart index 545f42eb..51b26c2a 100644 --- a/lib/src/message_list_view.dart +++ b/lib/src/message_list_view.dart @@ -139,7 +139,7 @@ class MessageListView extends StatefulWidget { class _MessageListViewState extends State { static const _newMessageLoadingOffset = 100; final ScrollController _scrollController = ScrollController(); - bool _isBottom = true; + bool _bottomWasVisible = true; bool _topWasVisible = false; List _messages = []; List _newMessageList = []; @@ -333,7 +333,11 @@ class _MessageListViewState extends State { onVisibilityChanged: (visibility) { final topIsVisible = visibility.visibleBounds != Rect.zero; if (topIsVisible && !_topWasVisible) { - streamChannel.queryMessages(); + if (widget.parentMessage == null) { + streamChannel.queryMessages(); + } else { + streamChannel.getReplies(widget.parentMessage.id); + } } _topWasVisible = topIsVisible; }, @@ -368,12 +372,15 @@ class _MessageListViewState extends State { return VisibilityDetector( key: ValueKey('BOTTOM-MESSAGE'), onVisibilityChanged: (visibility) { - _isBottom = visibility.visibleBounds != Rect.zero; - if (_isBottom && streamChannel.channel.config?.readEvents == true) { + final isVisible = visibility.visibleBounds != Rect.zero; + if (isVisible && + !_bottomWasVisible && + streamChannel.channel.config?.readEvents == true) { if (streamChannel.channel.state.unreadCount > 0) { streamChannel.channel.markRead(); } } + _bottomWasVisible = isVisible; }, child: messageWidget, ); @@ -437,7 +444,8 @@ class _MessageListViewState extends State { ?.read ?.where((element) => element.user.id != userId) ?.where((read) => - read.lastRead.isAfter(message.createdAt) && + (read.lastRead.isAfter(message.createdAt) || + read.lastRead.isAtSameMomentAs(message.createdAt)) && (index == 0 || read.lastRead.isBefore(messages[index - 1].createdAt))) ?.toList(); @@ -483,9 +491,6 @@ class _MessageListViewState extends State { super.initState(); final streamChannel = StreamChannel.of(context); - if (streamChannel.channel.state.unreadCount > 0) { - streamChannel.channel.markRead(); - } Stream> stream; diff --git a/lib/src/stream_channel.dart b/lib/src/stream_channel.dart index 62775281..21ee99f3 100644 --- a/lib/src/stream_channel.dart +++ b/lib/src/stream_channel.dart @@ -54,7 +54,7 @@ class StreamChannelState extends State { /// Calls [channel.query] updating [queryMessage] stream void queryMessages() { - if (_paginationEnded) { + if (_queryMessageController.value == true || _paginationEnded) { return; } @@ -65,15 +65,18 @@ class StreamChannelState extends State { firstId = channel.state.messages.first.id; } + final messageLimit = 50; + widget.channel .query( messagesPagination: PaginationParams( lessThan: firstId, - limit: 100, + limit: messageLimit, ), + preferOffline: true, ) .then((res) { - if (res.messages.isEmpty) { + if (res.messages.isEmpty || res.messages.length < messageLimit) { _paginationEnded = true; } _queryMessageController.add(false); @@ -84,7 +87,7 @@ class StreamChannelState extends State { /// Calls [channel.getReplies] updating [queryMessage] stream Future getReplies(String parentId) async { - if (_paginationEnded) { + if (_queryMessageController.value == true || _paginationEnded) { return; } @@ -99,16 +102,18 @@ class StreamChannelState extends State { } } + final messageLimit = 50; return widget.channel .getReplies( parentId, PaginationParams( lessThan: firstId, - limit: 100, + limit: messageLimit, ), + preferOffline: true, ) .then((res) { - if (res.messages.isEmpty) { + if (res.messages.isEmpty || res.messages.length < messageLimit) { _paginationEnded = true; } _queryMessageController.add(false); diff --git a/lib/src/thread_header.dart b/lib/src/thread_header.dart index 9fba3e34..993a3047 100644 --- a/lib/src/thread_header.dart +++ b/lib/src/thread_header.dart @@ -82,9 +82,12 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget { actions: [ Container( child: showBackButton - ? StreamBackButton( - onPressed: onBackPressed, - icon: Icons.close, + ? AspectRatio( + aspectRatio: 1, + child: StreamBackButton( + onPressed: onBackPressed, + icon: Icons.close, + ), ) : SizedBox(), ), diff --git a/pubspec.yaml b/pubspec.yaml index 916a732b..6f240111 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,7 +23,7 @@ dependencies: file_picker: ^2.0.0 image_picker: ^0.6.7+2 flutter_keyboard_visibility: ^3.2.1 - stream_chat: ^0.2.6 + stream_chat: ^0.2.7+1 mime: ^0.9.6+3 visibility_detector: ^0.1.5 http_parser: ^3.1.4