Skip to content

Commit

Permalink
Merge pull request #101 from GetStream/feature/offlineStorage
Browse files Browse the repository at this point in the history
update llc dependency and hotfixes
  • Loading branch information
imtoori authored Oct 12, 2020
2 parents 05fd585 + 52369f4 commit 10dfbbd
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.9+1

- Update llc dependency
- Minor bug fixes

## 0.2.9

- Update llc dependency
Expand Down
3 changes: 1 addition & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 2 additions & 1 deletion lib/src/channels_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ class ChannelsBlocState extends State<ChannelsBloc>
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]);
}
}
Expand Down
21 changes: 13 additions & 8 deletions lib/src/message_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class MessageListView extends StatefulWidget {
class _MessageListViewState extends State<MessageListView> {
static const _newMessageLoadingOffset = 100;
final ScrollController _scrollController = ScrollController();
bool _isBottom = true;
bool _bottomWasVisible = true;
bool _topWasVisible = false;
List<Message> _messages = [];
List<Message> _newMessageList = [];
Expand Down Expand Up @@ -333,7 +333,11 @@ class _MessageListViewState extends State<MessageListView> {
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;
},
Expand Down Expand Up @@ -368,12 +372,15 @@ class _MessageListViewState extends State<MessageListView> {
return VisibilityDetector(
key: ValueKey<String>('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,
);
Expand Down Expand Up @@ -437,7 +444,8 @@ class _MessageListViewState extends State<MessageListView> {
?.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();
Expand Down Expand Up @@ -483,9 +491,6 @@ class _MessageListViewState extends State<MessageListView> {
super.initState();

final streamChannel = StreamChannel.of(context);
if (streamChannel.channel.state.unreadCount > 0) {
streamChannel.channel.markRead();
}

Stream<List<Message>> stream;

Expand Down
17 changes: 11 additions & 6 deletions lib/src/stream_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class StreamChannelState extends State<StreamChannel> {

/// Calls [channel.query] updating [queryMessage] stream
void queryMessages() {
if (_paginationEnded) {
if (_queryMessageController.value == true || _paginationEnded) {
return;
}

Expand All @@ -65,15 +65,18 @@ class StreamChannelState extends State<StreamChannel> {
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);
Expand All @@ -84,7 +87,7 @@ class StreamChannelState extends State<StreamChannel> {

/// Calls [channel.getReplies] updating [queryMessage] stream
Future<void> getReplies(String parentId) async {
if (_paginationEnded) {
if (_queryMessageController.value == true || _paginationEnded) {
return;
}

Expand All @@ -99,16 +102,18 @@ class StreamChannelState extends State<StreamChannel> {
}
}

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);
Expand Down
9 changes: 6 additions & 3 deletions lib/src/thread_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
actions: <Widget>[
Container(
child: showBackButton
? StreamBackButton(
onPressed: onBackPressed,
icon: Icons.close,
? AspectRatio(
aspectRatio: 1,
child: StreamBackButton(
onPressed: onBackPressed,
icon: Icons.close,
),
)
: SizedBox(),
),
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: stream_chat_flutter
homepage: https://github.com/GetStream/stream-chat-flutter
description: Stream Chat official Flutter SDK. Build your own chat experience using Dart and Flutter.
version: 0.2.9
version: 0.2.9+1
repository: https://github.com/GetStream/stream-chat-flutter
issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues

Expand All @@ -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
Expand Down

0 comments on commit 10dfbbd

Please sign in to comment.