Skip to content

Commit ea74a87

Browse files
feat: added assignRole endpoint (#111)
1 parent 4917191 commit ea74a87

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/GetStream/StreamChat/Channel.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,27 @@ public function truncate(array $options = null): StreamResponse
268268
return $this->client->post($this->getUrl() . "/truncate", $options);
269269
}
270270

271+
/** assignRoles - sets member roles in a channel
272+
* @link https://getstream.io/chat/docs/php/channel_members/?language=php
273+
* @throws StreamException
274+
* @param array $roles
275+
* @param array|null $message
276+
* @param array|null $options
277+
* @return StreamResponse
278+
*/
279+
public function assignRoles(array $roles, array $message = null, array $options = null): StreamResponse
280+
{
281+
$opts = [
282+
"assign_roles" => $roles
283+
];
284+
285+
if ($options !== null) {
286+
$opts = array_merge($opts, $options);
287+
}
288+
289+
return $this->update(null, $message, $opts);
290+
}
291+
271292
/** Adds members to the channel.
272293
* @link https://getstream.io/chat/docs/php/channel_members/?language=php
273294
* @throws StreamException

tests/integration/IntegrationTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,35 @@ public function testChannelAddMembers()
885885
}
886886
}
887887

888+
public function testChannelAssignRoles()
889+
{
890+
// Add user to the channel with role set
891+
$this->client->upsertUsers([
892+
['id' => 'james_bond', 'role' => 'user'],
893+
]);
894+
895+
$this->channel->addMembers([
896+
['user_id' => 'james_bond', 'channel_role' => 'channel_member'],
897+
]);
898+
899+
$result = $this->channel->assignRoles([
900+
['user_id' => 'james_bond', 'channel_role' => 'channel_moderator'],
901+
]);
902+
903+
if (array_key_exists("channel_role", $result["members"][0])) {
904+
$this->assertEquals('channel_moderator', $result["members"][0]["channel_role"]);
905+
}
906+
907+
$result = $this->channel->assignRoles([
908+
['user_id' => 'james_bond', 'channel_role' => 'channel_member'],
909+
]);
910+
911+
if (array_key_exists("channel_role", $result["members"][0])) {
912+
$this->assertEquals('channel_member', $result["members"][0]["channel_role"]);
913+
}
914+
}
915+
916+
888917
public function testChannelAddModerators()
889918
{
890919
$response = $this->channel->addModerators([$this->user1["id"]]);

0 commit comments

Comments
 (0)