// Removes all of the messages of the channel but doesn't affect the channel data or members
channelClient.truncate().enqueue { result ->
if (result.isSuccess) {
// Channel is truncated
} else {
// Handle result.error()
}
}
// Or with message parameter.
val message = Message(text = "Dear Everyone. The channel has been truncated.")
channelClient.truncate(systemMessage = message).enqueue { result ->
if (result.isSuccess) {
// Channel is truncated
} else {
// Handle result.error()
}
}
Truncate Channel
Messages from a channel can be truncated. This will remove all of the messages but not affect the channel data or channel members. If you want to delete both channel and message data then use the Delete Channel method instead.
Truncate channel can be performed client-side or server-side. To use client-side, the user must have the TruncateChannel permission.
On server-side calls, user_id
field can be used to identify channel truncator.
The default behaviour is to hide messages when channel is truncated. To permanently delete messages, set the hard_delete
option to true
. The following fields can be used to truncate a channel:
Type | Description | Optional | |
---|---|---|---|
truncated_at | Date | To truncate channel up to given time. | ✓ |
user_id | string | User who truncates the channel (server-side call only) | ✓ |
message | object | A system message to be added via truncation. | ✓ |
skip_push | bool | Don’t send a push notification for system message. | ✓ |
hard_delete | bool | True if truncation should delete messages instead of hiding | ✓ |
await channel.truncate();
// Or with parameters:
await channel.truncate({
'hard_delete': true,
'skip_push': false,
'message': {
'text': 'Dear Everyone. The channel has been truncated.'
'user_id': user['id']
}
});
// Setting user_id server side:
await channel.truncate({
'user_id': user['id']
});
channel.truncate();
# Or with parameters:
channel.truncate(
hard_delete=True,
skip_push=True,
message={
"text": "Dear Everyone. The channel has been truncated.",
"user_id": random_user["id"],
},
)
await channelClient.TruncateAsync(channel.Type, channel.Id);
// Or with parameters:
await channelClient.TruncateAsync(channel.Type, channel.Id, new TruncateOptions
{
SkipPush = true,
HardDelete = true,
Message = new MessageRequest
{
Text = "Dear Everyone. The channel has been truncated.",
User = new UserRequest { Id = user.Id },
},
});
channel.truncate
# Or with parameters:
text = "Dear Everyone. The channel has been truncated."
channel.truncate(skip_push: true, message: { text: text, user_id: @user[:id] })
$channel->truncate();
// Or with parameters:
$truncateOpts = [
"message" => ["text" => "Dear Everyone. The channel has been truncated.", "user_id" => $user["id"]],
"skip_push" => true,
];
$channel->truncate($truncateOpts);
err := ch.Truncate(context.Background())
// Or with parameters:
err := ch.Truncate(context.Background(),
TruncateWithSkipPush(true),
TruncateWithHardDelete(true),
TruncateWithMessage(&Message{Text: "Truncated channel.", User: &User{ID: user.ID}}),
)
let controller = client.channelController(for: .init(type: .messaging, id: "general"))
controller.truncateChannel()
await channel.TruncateAsync(systemMessage: "Clearing up the history!");
// Android SDK
// Removes all of the messages of the channel but doesn't affect the channel data or members
channelClient.truncate().enqueue(result -> {
if (result.isSuccess()) {
// Channel is truncated
} else {
// Handle result.error()
}
});
// Backend SDK
Channel.truncate(type, id).request();
Channel->Truncate();
// Or with parameters:
Channel->Truncate(
true, // bHardDelete
{}, // TruncatedAt
FMessage{TEXT("Dear Everyone. The channel has been truncated.")},
false, // bSkipPush
[]
{
// Channel is truncated
});