diff --git a/packages/stream_chat/lib/src/client/channel.dart b/packages/stream_chat/lib/src/client/channel.dart index 7575b29d..abe8cf48 100644 --- a/packages/stream_chat/lib/src/client/channel.dart +++ b/packages/stream_chat/lib/src/client/channel.dart @@ -1033,10 +1033,23 @@ class Channel { return _client.deleteChannel(id!, type); } - /// Removes all messages from the channel. - Future truncate() async { + /// Removes all messages from the channel up to [truncatedAt] or now if + /// [truncatedAt] is not provided. + /// If [skipPush] is true, no push notification will be sent. + /// [Message] is the system message that will be sent to the channel. + Future truncate({ + Message? message, + bool? skipPush, + DateTime? truncatedAt, + }) async { _checkInitialized(); - return _client.truncateChannel(id!, type); + return _client.truncateChannel( + id!, + type, + message: message, + skipPush: skipPush, + truncatedAt: truncatedAt, + ); } /// Accept invitation to the channel. diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index c3605ac5..3bec2dff 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -938,14 +938,23 @@ class StreamChatClient { channelType, ); - /// Removes all messages from the channel + /// Removes all messages from the channel up to [truncatedAt] or now if + /// [truncatedAt] is not provided. + /// If [skipPush] is true, no push notification will be sent. + /// [Message] is the system message that will be sent to the channel. Future truncateChannel( String channelId, - String channelType, - ) => + String channelType, { + Message? message, + bool? skipPush, + DateTime? truncatedAt, + }) => _chatApi.channel.truncateChannel( channelId, channelType, + message: message, + skipPush: skipPush, + truncatedAt: truncatedAt, ); /// Mutes the channel diff --git a/packages/stream_chat/lib/src/core/api/channel_api.dart b/packages/stream_chat/lib/src/core/api/channel_api.dart index 8744661a..93d17870 100644 --- a/packages/stream_chat/lib/src/core/api/channel_api.dart +++ b/packages/stream_chat/lib/src/core/api/channel_api.dart @@ -265,10 +265,18 @@ class ChannelApi { /// Removes all messages from the channel Future truncateChannel( String channelId, - String channelType, - ) async { + String channelType, { + Message? message, + bool? skipPush, + DateTime? truncatedAt, + }) async { final response = await _client.post( '${_getChannelUrl(channelId, channelType)}/truncate', + data: { + if (message != null) 'message': message, + if (skipPush != null) 'skip_push': skipPush, + if (truncatedAt != null) 'truncated_at': truncatedAt, + }, ); return EmptyResponse.fromJson(response.data); } diff --git a/packages/stream_chat/test/src/core/api/channel_api_test.dart b/packages/stream_chat/test/src/core/api/channel_api_test.dart index e631fdb2..a7856c92 100644 --- a/packages/stream_chat/test/src/core/api/channel_api_test.dart +++ b/packages/stream_chat/test/src/core/api/channel_api_test.dart @@ -481,14 +481,21 @@ void main() { final path = '${_getChannelUrl(channelId, channelType)}/truncate'; - when(() => client.post(path)).thenAnswer( - (_) async => successResponse(path, data: {})); + when(() => client.post( + path, + data: {}, + )) + .thenAnswer( + (_) async => successResponse(path, data: {})); final res = await channelApi.truncateChannel(channelId, channelType); expect(res, isNotNull); - verify(() => client.post(path)).called(1); + verify(() => client.post( + path, + data: {}, + )).called(1); verifyNoMoreInteractions(client); });