Merge pull request #1622 from GetStream/fix/mute-expire

This commit is contained in:
Sahil Kumar
2023-06-19 14:25:15 +05:30
committed by GitHub
3 changed files with 45 additions and 0 deletions
+2
View File
@@ -4,6 +4,8 @@
- [[#1293]](https://github.com/GetStream/stream-chat-flutter/issues/1293) Fixed wrong message order when sending - [[#1293]](https://github.com/GetStream/stream-chat-flutter/issues/1293) Fixed wrong message order when sending
messages quickly. messages quickly.
- [[#1612]](https://github.com/GetStream/stream-chat-flutter/issues/1612) Fixed `Channel.isMutedStream` does not emit
when channel mute expires.
## 6.3.0 ## 6.3.0
@@ -1447,15 +1447,32 @@ class Channel {
); );
} }
// Timer to keep track of mute expiration. This is used to update the channel
// state when the mute expires.
Timer? _muteExpirationTimer;
/// Mutes the channel. /// Mutes the channel.
Future<EmptyResponse> mute({Duration? expiration}) { Future<EmptyResponse> mute({Duration? expiration}) {
_checkInitialized(); _checkInitialized();
// If there is a expiration set, we will set a timer to automatically unmute
// the channel when the mute expires.
if (expiration != null) {
_muteExpirationTimer?.cancel();
_muteExpirationTimer = Timer(expiration, unmute);
}
return _client.muteChannel(cid!, expiration: expiration); return _client.muteChannel(cid!, expiration: expiration);
} }
/// Unmute the channel. /// Unmute the channel.
Future<EmptyResponse> unmute() { Future<EmptyResponse> unmute() {
_checkInitialized(); _checkInitialized();
// Cancel the mute expiration timer if it is set.
_muteExpirationTimer?.cancel();
_muteExpirationTimer = null;
return _client.unmuteChannel(cid!); return _client.unmuteChannel(cid!);
} }
@@ -1585,6 +1602,7 @@ class Channel {
void dispose() { void dispose() {
client.state.removeChannel('$cid'); client.state.removeChannel('$cid');
state?.dispose(); state?.dispose();
_muteExpirationTimer?.cancel();
_keyStrokeHandler.cancel(); _keyStrokeHandler.cancel();
} }
@@ -2481,6 +2481,31 @@ void main() {
)).called(1); )).called(1);
}); });
test('`.mute with expiration`', () async {
const expiration = Duration(seconds: 3);
when(() => client.muteChannel(
channelCid,
expiration: expiration,
)).thenAnswer((_) async => EmptyResponse());
when(() => client.unmuteChannel(channelCid))
.thenAnswer((_) async => EmptyResponse());
final res = await channel.mute(expiration: expiration);
expect(res, isNotNull);
verify(() => client.muteChannel(
channelCid,
expiration: expiration,
)).called(1);
// wait for expiration
await Future.delayed(expiration);
verify(() => client.unmuteChannel(channelCid)).called(1);
});
test('`.unmute`', () async { test('`.unmute`', () async {
when( when(
() => client.unmuteChannel(channelCid), () => client.unmuteChannel(channelCid),