Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/channels/channel_management/deleting.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ $channel->delete();
> If you recreate this channel, it will show up empty. Recovering old messages is not supported. Use the disable method if you want a reversible change.


### Keeping the messages

Pass `["skip_truncate" => true]` to keep the messages of a soft deleted channel, so recreating the channel with the same ID restores its history. It cannot be combined with a hard delete, and only distinct channels are eligible.

```php
$channel->delete(["skip_truncate" => true]);

// same option on the batch endpoint
$response = $client->deleteChannels([cid1, cid2], ["skip_truncate" => true]);
```

## Deleting Many Channels

You can delete up to 100 channels and optionally all of their messages using this method. This can be a large amount of data to delete, so this endpoint processes asynchronously, meaning responses contain a `task ID` which can be polled using the [getTask endpoint](/chat/docs/php#tasks-gettask) to check status of the deletions. Channels will be soft-deleted immediately so that channels no longer return from queries, but permanently deleting the channel and deleting messages takes longer to process.
Expand Down
5 changes: 3 additions & 2 deletions lib/GetStream/StreamChat/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,13 @@ public function updatePartial(?array $set = null, ?array $unset = null): StreamR
}

/** Deletes a channel.
* Pass ["skip_truncate" => true] to keep the messages of a soft deleted channel.
* @link https://getstream.io/chat/docs/php/channel_delete/?language=php
* @throws StreamException
*/
public function delete(): StreamResponse
public function delete(?array $options = null): StreamResponse
{
return $this->client->delete($this->getUrl());
return $this->client->delete($this->getUrl(), $options ?? []);
}

/** Removes all messages from the channel.
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/ChannelDeleteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=0);

namespace GetStream\Unit;

use GetStream\StreamChat\Channel;
use GetStream\StreamChat\Client;
use GetStream\StreamChat\StreamResponse;
use PHPUnit\Framework\TestCase;

class ChannelDeleteTest extends TestCase
{
private function channel(Client $client): Channel
{
return new Channel($client, "messaging", "chan");
}

public function testDeleteWithoutOptions()
{
$client = $this->createMock(Client::class);
$client->expects($this->once())
->method('delete')
->with("channels/messaging/chan", [])
->willReturn($this->createMock(StreamResponse::class));

$this->channel($client)->delete();
}

public function testDeleteWithSkipTruncate()
{
$client = $this->createMock(Client::class);
$client->expects($this->once())
->method('delete')
->with("channels/messaging/chan", ["skip_truncate" => true])
->willReturn($this->createMock(StreamResponse::class));

$this->channel($client)->delete(["skip_truncate" => true]);
}
}
Loading