diff --git a/docs/channels/channel_management/deleting.md b/docs/channels/channel_management/deleting.md index 5d2b4c9..0d8d0ba 100644 --- a/docs/channels/channel_management/deleting.md +++ b/docs/channels/channel_management/deleting.md @@ -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. diff --git a/lib/GetStream/StreamChat/Channel.php b/lib/GetStream/StreamChat/Channel.php index b116b2c..2d68594 100644 --- a/lib/GetStream/StreamChat/Channel.php +++ b/lib/GetStream/StreamChat/Channel.php @@ -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. diff --git a/tests/unit/ChannelDeleteTest.php b/tests/unit/ChannelDeleteTest.php new file mode 100644 index 0000000..749851b --- /dev/null +++ b/tests/unit/ChannelDeleteTest.php @@ -0,0 +1,40 @@ +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]); + } +}