fix(core): Channel doesn't auto display again after being hidden.
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
## Upcoming
|
||||||
|
|
||||||
|
- [[#1356]](https://github.com/GetStream/stream-chat-flutter/issues/1356) Channel doesn't auto display again after being
|
||||||
|
hidden.
|
||||||
|
|
||||||
## 6.0.0
|
## 6.0.0
|
||||||
|
|
||||||
- Updated dependencies to resolvable versions.
|
- Updated dependencies to resolvable versions.
|
||||||
|
|||||||
@@ -387,12 +387,20 @@ class StreamChannelState extends State<StreamChannel> {
|
|||||||
(it) => it.user.id == channel.client.state.currentUser?.id,
|
(it) => it.user.id == channel.client.state.currentUser?.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (read != null &&
|
if (read == null) return;
|
||||||
!(channel.state!.messages
|
|
||||||
.any((it) => it.createdAt.compareTo(read.lastRead) > 0) &&
|
final messages = channel.state!.messages;
|
||||||
channel.state!.messages
|
final lastRead = read.lastRead;
|
||||||
.any((it) => it.createdAt.compareTo(read.lastRead) <= 0))) {
|
|
||||||
_futures.add(_loadChannelAtTimestamp(read.lastRead));
|
final hasNewMessages =
|
||||||
|
messages.any((it) => it.createdAt.isAfter(lastRead));
|
||||||
|
final hasOldMessages =
|
||||||
|
messages.any((it) => it.createdAt.isBeforeOrEqualTo(lastRead));
|
||||||
|
|
||||||
|
// Only load messages if the unread message is in-between the messages.
|
||||||
|
// Otherwise, we can just load the channel normally.
|
||||||
|
if (hasNewMessages && hasOldMessages) {
|
||||||
|
_futures.add(_loadChannelAtTimestamp(lastRead));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -449,3 +457,9 @@ class StreamChannelState extends State<StreamChannel> {
|
|||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension on DateTime {
|
||||||
|
bool isBeforeOrEqualTo(DateTime other) {
|
||||||
|
return isBefore(other) || isAtSameMomentAs(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -101,14 +101,19 @@ class StreamChannelListEventHandler {
|
|||||||
/// we are currently watching.
|
/// we are currently watching.
|
||||||
///
|
///
|
||||||
/// By default, this moves the channel to the top of the list.
|
/// By default, this moves the channel to the top of the list.
|
||||||
void onMessageNew(Event event, StreamChannelListController controller) {
|
void onMessageNew(Event event, StreamChannelListController controller) async {
|
||||||
final channelCid = event.cid;
|
final channelCid = event.cid;
|
||||||
if (channelCid == null) return;
|
if (channelCid == null) return;
|
||||||
|
|
||||||
final channels = [...controller.currentItems];
|
final channels = [...controller.currentItems];
|
||||||
|
|
||||||
final channelIndex = channels.indexWhere((it) => it.cid == channelCid);
|
final channelIndex = channels.indexWhere((it) => it.cid == channelCid);
|
||||||
if (channelIndex <= 0) return;
|
if (channelIndex <= 0) {
|
||||||
|
// If the channel is not in the list, It might be hidden.
|
||||||
|
// So, we just refresh the list.
|
||||||
|
await controller.refresh(resetValue: false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final channel = channels.removeAt(channelIndex);
|
final channel = channels.removeAt(channelIndex);
|
||||||
channels.insert(0, channel);
|
channels.insert(0, channel);
|
||||||
|
|||||||
Reference in New Issue
Block a user