File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 " ]]);
You can’t perform that action at this time.
0 commit comments