Skip to content

Commit

Permalink
feat: add options to add members (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdeme committed Dec 13, 2021
1 parent d45ad02 commit 6bfba2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/GetStream/StreamChat/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,18 @@ public function truncate($options=null)

/**
* @param array $userIds
* @param array $options
* @return mixed
* @throws StreamException
*/
public function addMembers($userIds)
public function addMembers($userIds, $options=null)
{
$payload = [
"add_members" => $userIds
];
if ($options !== null) {
$payload = array_merge($payload, $options);
}
return $this->client->post($this->getUrl(), $payload);
}

Expand Down
12 changes: 8 additions & 4 deletions tests/integration/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,14 +653,18 @@ public function testChannelTruncateWithOptions()

public function testChannelAddMembers()
{
$user = $this->getUser();
$user1 = $this->getUser();
$user2 = $this->getUser();
$channel = $this->getChannel();
$response = $channel->removeMembers([$user["id"]]);
$response = $channel->removeMembers([$user1["id"]]);
$this->assertTrue(array_key_exists("members", $response));
$this->assertSame(count($response["members"]), 0);
$response = $channel->addMembers([$user["id"]]);

$response = $channel->addMembers([$user1["id"]]);
$response = $channel->addMembers([$user2["id"]], ["hide_history" => true]);

$this->assertTrue(array_key_exists("members", $response));
$this->assertSame(count($response["members"]), 1);
$this->assertSame(count($response["members"]), 2);
if (array_key_exists("is_moderator", $response["members"][0])) {
$this->assertFalse($response["members"][0]["is_moderator"]);
}
Expand Down

0 comments on commit 6bfba2c

Please sign in to comment.