Merge pull request #1517 from GetStream/fix/channel-mute
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
## Upcoming
|
||||
|
||||
🐞 Fixed
|
||||
|
||||
- [[#1355]](https://github.com/GetStream/stream-chat-flutter/issues/1355) Fixed error while hiding channel and clearing
|
||||
message history.
|
||||
|
||||
✅ Added
|
||||
|
||||
- Expose `ChannelMute` class. [#1473](https://github.com/GetStream/stream-chat-flutter/issues/1473)
|
||||
|
||||
@@ -1485,19 +1485,11 @@ class Channel {
|
||||
/// will be removed for the user.
|
||||
Future<EmptyResponse> hide({bool clearHistory = false}) async {
|
||||
_checkInitialized();
|
||||
final response = await _client.hideChannel(
|
||||
return _client.hideChannel(
|
||||
id!,
|
||||
type,
|
||||
clearHistory: clearHistory,
|
||||
);
|
||||
if (clearHistory) {
|
||||
state!.truncate();
|
||||
final cid = _cid;
|
||||
if (cid != null) {
|
||||
await _client.chatPersistenceClient?.deleteMessageByCid(cid);
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/// Removes the hidden status for the channel.
|
||||
|
||||
@@ -1567,7 +1567,7 @@ class ClientState {
|
||||
_client.on(EventType.channelHidden).listen((event) async {
|
||||
final eventChannel = event.channel!;
|
||||
await _client.chatPersistenceClient?.deleteChannels([eventChannel.cid]);
|
||||
channels[eventChannel.cid]?.dispose();
|
||||
channels.remove(eventChannel.cid)?.dispose();
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -1606,7 +1606,7 @@ class ClientState {
|
||||
.listen((Event event) async {
|
||||
final eventChannel = event.channel!;
|
||||
await _client.chatPersistenceClient?.deleteChannels([eventChannel.cid]);
|
||||
channels[eventChannel.cid]?.dispose();
|
||||
channels.remove(eventChannel.cid)?.dispose();
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -1713,9 +1713,9 @@ class ClientState {
|
||||
_unreadChannelsController.close();
|
||||
_totalUnreadCountController.close();
|
||||
|
||||
final channels = this.channels.values.toList();
|
||||
final channels = [...this.channels.keys];
|
||||
for (final channel in channels) {
|
||||
channel.dispose();
|
||||
this.channels.remove(channel)?.dispose();
|
||||
}
|
||||
_channelsController.close();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
- Updated dependencies to resolvable versions.
|
||||
|
||||
@@ -387,12 +387,20 @@ class StreamChannelState extends State<StreamChannel> {
|
||||
(it) => it.user.id == channel.client.state.currentUser?.id,
|
||||
);
|
||||
|
||||
if (read != null &&
|
||||
!(channel.state!.messages
|
||||
.any((it) => it.createdAt.compareTo(read.lastRead) > 0) &&
|
||||
channel.state!.messages
|
||||
.any((it) => it.createdAt.compareTo(read.lastRead) <= 0))) {
|
||||
_futures.add(_loadChannelAtTimestamp(read.lastRead));
|
||||
if (read == null) return;
|
||||
|
||||
final messages = channel.state!.messages;
|
||||
final lastRead = 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;
|
||||
}
|
||||
}
|
||||
|
||||
extension on DateTime {
|
||||
bool isBeforeOrEqualTo(DateTime other) {
|
||||
return isBefore(other) || isAtSameMomentAs(other);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,14 +101,19 @@ class StreamChannelListEventHandler {
|
||||
/// we are currently watching.
|
||||
///
|
||||
/// 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;
|
||||
if (channelCid == null) return;
|
||||
|
||||
final channels = [...controller.currentItems];
|
||||
|
||||
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);
|
||||
channels.insert(0, channel);
|
||||
|
||||
Reference in New Issue
Block a user