Skip to content

Commit 10dfbbd

Browse files
authored
Merge pull request #101 from GetStream/feature/offlineStorage
update llc dependency and hotfixes
2 parents 05fd585 + 52369f4 commit 10dfbbd

File tree

7 files changed

+40
-22
lines changed

7 files changed

+40
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.2.9+1
2+
3+
- Update llc dependency
4+
- Minor bug fixes
5+
16
## 0.2.9
27

38
- Update llc dependency

example/pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: example
22
description: A new Flutter project.
3-
4-
version: 1.0.12+13
3+
version: 1.0.20+21
54

65
environment:
76
sdk: ">=2.2.2 <3.0.0"

lib/src/channels_bloc.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ class ChannelsBlocState extends State<ChannelsBloc>
135135
newChannels.insert(0, _hiddenChannels[hiddenIndex]);
136136
_hiddenChannels.removeAt(hiddenIndex);
137137
} else {
138-
if (client.state.channels[e.cid] != null) {
138+
if (client.state?.channels != null &&
139+
client.state?.channels[e.cid] != null) {
139140
newChannels.insert(0, client.state.channels[e.cid]);
140141
}
141142
}

lib/src/message_list_view.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class MessageListView extends StatefulWidget {
139139
class _MessageListViewState extends State<MessageListView> {
140140
static const _newMessageLoadingOffset = 100;
141141
final ScrollController _scrollController = ScrollController();
142-
bool _isBottom = true;
142+
bool _bottomWasVisible = true;
143143
bool _topWasVisible = false;
144144
List<Message> _messages = [];
145145
List<Message> _newMessageList = [];
@@ -333,7 +333,11 @@ class _MessageListViewState extends State<MessageListView> {
333333
onVisibilityChanged: (visibility) {
334334
final topIsVisible = visibility.visibleBounds != Rect.zero;
335335
if (topIsVisible && !_topWasVisible) {
336-
streamChannel.queryMessages();
336+
if (widget.parentMessage == null) {
337+
streamChannel.queryMessages();
338+
} else {
339+
streamChannel.getReplies(widget.parentMessage.id);
340+
}
337341
}
338342
_topWasVisible = topIsVisible;
339343
},
@@ -368,12 +372,15 @@ class _MessageListViewState extends State<MessageListView> {
368372
return VisibilityDetector(
369373
key: ValueKey<String>('BOTTOM-MESSAGE'),
370374
onVisibilityChanged: (visibility) {
371-
_isBottom = visibility.visibleBounds != Rect.zero;
372-
if (_isBottom && streamChannel.channel.config?.readEvents == true) {
375+
final isVisible = visibility.visibleBounds != Rect.zero;
376+
if (isVisible &&
377+
!_bottomWasVisible &&
378+
streamChannel.channel.config?.readEvents == true) {
373379
if (streamChannel.channel.state.unreadCount > 0) {
374380
streamChannel.channel.markRead();
375381
}
376382
}
383+
_bottomWasVisible = isVisible;
377384
},
378385
child: messageWidget,
379386
);
@@ -437,7 +444,8 @@ class _MessageListViewState extends State<MessageListView> {
437444
?.read
438445
?.where((element) => element.user.id != userId)
439446
?.where((read) =>
440-
read.lastRead.isAfter(message.createdAt) &&
447+
(read.lastRead.isAfter(message.createdAt) ||
448+
read.lastRead.isAtSameMomentAs(message.createdAt)) &&
441449
(index == 0 ||
442450
read.lastRead.isBefore(messages[index - 1].createdAt)))
443451
?.toList();
@@ -483,9 +491,6 @@ class _MessageListViewState extends State<MessageListView> {
483491
super.initState();
484492

485493
final streamChannel = StreamChannel.of(context);
486-
if (streamChannel.channel.state.unreadCount > 0) {
487-
streamChannel.channel.markRead();
488-
}
489494

490495
Stream<List<Message>> stream;
491496

lib/src/stream_channel.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class StreamChannelState extends State<StreamChannel> {
5454

5555
/// Calls [channel.query] updating [queryMessage] stream
5656
void queryMessages() {
57-
if (_paginationEnded) {
57+
if (_queryMessageController.value == true || _paginationEnded) {
5858
return;
5959
}
6060

@@ -65,15 +65,18 @@ class StreamChannelState extends State<StreamChannel> {
6565
firstId = channel.state.messages.first.id;
6666
}
6767

68+
final messageLimit = 50;
69+
6870
widget.channel
6971
.query(
7072
messagesPagination: PaginationParams(
7173
lessThan: firstId,
72-
limit: 100,
74+
limit: messageLimit,
7375
),
76+
preferOffline: true,
7477
)
7578
.then((res) {
76-
if (res.messages.isEmpty) {
79+
if (res.messages.isEmpty || res.messages.length < messageLimit) {
7780
_paginationEnded = true;
7881
}
7982
_queryMessageController.add(false);
@@ -84,7 +87,7 @@ class StreamChannelState extends State<StreamChannel> {
8487

8588
/// Calls [channel.getReplies] updating [queryMessage] stream
8689
Future<void> getReplies(String parentId) async {
87-
if (_paginationEnded) {
90+
if (_queryMessageController.value == true || _paginationEnded) {
8891
return;
8992
}
9093

@@ -99,16 +102,18 @@ class StreamChannelState extends State<StreamChannel> {
99102
}
100103
}
101104

105+
final messageLimit = 50;
102106
return widget.channel
103107
.getReplies(
104108
parentId,
105109
PaginationParams(
106110
lessThan: firstId,
107-
limit: 100,
111+
limit: messageLimit,
108112
),
113+
preferOffline: true,
109114
)
110115
.then((res) {
111-
if (res.messages.isEmpty) {
116+
if (res.messages.isEmpty || res.messages.length < messageLimit) {
112117
_paginationEnded = true;
113118
}
114119
_queryMessageController.add(false);

lib/src/thread_header.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
8282
actions: <Widget>[
8383
Container(
8484
child: showBackButton
85-
? StreamBackButton(
86-
onPressed: onBackPressed,
87-
icon: Icons.close,
85+
? AspectRatio(
86+
aspectRatio: 1,
87+
child: StreamBackButton(
88+
onPressed: onBackPressed,
89+
icon: Icons.close,
90+
),
8891
)
8992
: SizedBox(),
9093
),

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: stream_chat_flutter
22
homepage: https://github.com/GetStream/stream-chat-flutter
33
description: Stream Chat official Flutter SDK. Build your own chat experience using Dart and Flutter.
4-
version: 0.2.9
4+
version: 0.2.9+1
55
repository: https://github.com/GetStream/stream-chat-flutter
66
issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues
77

@@ -23,7 +23,7 @@ dependencies:
2323
file_picker: ^2.0.0
2424
image_picker: ^0.6.7+2
2525
flutter_keyboard_visibility: ^3.2.1
26-
stream_chat: ^0.2.6
26+
stream_chat: ^0.2.7+1
2727
mime: ^0.9.6+3
2828
visibility_detector: ^0.1.5
2929
http_parser: ^3.1.4

0 commit comments

Comments
 (0)