feat(llc): add additional parameters to channel.truncate

This commit is contained in:
Salvatore Giordano
2022-04-12 11:29:40 +02:00
parent 432579e04b
commit 58536e56c0
4 changed files with 48 additions and 11 deletions
@@ -1033,10 +1033,23 @@ class Channel {
return _client.deleteChannel(id!, type);
}
/// Removes all messages from the channel.
Future<EmptyResponse> 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<EmptyResponse> 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.
@@ -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<EmptyResponse> 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
@@ -265,10 +265,18 @@ class ChannelApi {
/// Removes all messages from the channel
Future<EmptyResponse> 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);
}
@@ -481,14 +481,21 @@ void main() {
final path = '${_getChannelUrl(channelId, channelType)}/truncate';
when(() => client.post(path)).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
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);
});