Skip to content

Commit 4ccf402

Browse files
authored
Add async delete channels (#63)
1 parent fb09ec0 commit 4ccf402

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

lib/GetStream/StreamChat/Client.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,21 @@ public function deleteUsers($userIds, $options=null)
393393
return $this->post("users/delete", $options);
394394
}
395395

396+
/**
397+
* @param array $cids
398+
* @param array $options
399+
* @return mixed
400+
* @throws StreamException
401+
*/
402+
public function deleteChannels($cids, $options=null)
403+
{
404+
if ($options === null) {
405+
$options = (object)[];
406+
}
407+
$options["cids"] = $cids;
408+
return $this->post("channels/delete", $options);
409+
}
410+
396411
/**
397412
* @param string $userId
398413
* @param array $options

tests/integration/IntegrationTest.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,37 @@ public function testDeleteUsers()
108108
$response = $this->client->deleteUsers([$user["id"]], ["user" => "hard"]);
109109
$this->assertTrue(array_key_exists("task_id", $response));
110110
$taskId = $response["task_id"];
111-
for ($i=0;$i<10;$i++) {
111+
for ($i=0;$i<30;$i++) {
112+
$response = $this->client->getTask($taskId);
113+
if ($response["status"] == "completed") {
114+
$this->assertSame($response["result"][$user["id"]]["status"], "ok");
115+
return;
116+
}
117+
usleep(300000);
118+
}
119+
$this->assertSame($response["status"], "completed");
120+
}
121+
122+
public function testDeleteChannels()
123+
{
124+
$user = ["id" => Uuid::uuid4()->toString()];
125+
$response = $this->client->updateUser($user);
126+
127+
$c1 = $this->getChannel();
128+
$c2 = $this->getChannel();
129+
130+
$response = $this->client->deleteChannels([$c1->getCID(), $c2->getCID()], ["hard_delete" => true]);
131+
$this->assertTrue(array_key_exists("task_id", $response));
132+
133+
$taskId = $response["task_id"];
134+
for ($i=0;$i<30;$i++) {
112135
$response = $this->client->getTask($taskId);
113136
if ($response["status"] == "completed") {
137+
$this->assertSame($response["result"][$c1->getCID()]["status"], "ok");
138+
$this->assertSame($response["result"][$c2->getCID()]["status"], "ok");
114139
return;
115140
}
116-
sleep(1);
141+
usleep(300000);
117142
}
118143
$this->assertSame($response["status"], "completed");
119144
}

0 commit comments

Comments
 (0)