public function Channel::addMember in Rocket.Chat 8.2
Parameters
\Drupal\rocket_chat_api\RocketChat\ApiClient $apiClient:
\Drupal\rocket_chat_api\RocketChat\Element\User $user:
Return value
bool|mixed
bool|mixed
Throws
\Exception
1 call to Channel::addMember()
- Channel::addMembers in modules/
rocket_chat_api/ src/ RocketChat/ Element/ Channel.php
File
- modules/
rocket_chat_api/ src/ RocketChat/ Element/ Channel.php, line 527
Class
Namespace
Drupal\rocket_chat_api\RocketChat\ElementCode
public function addMember(ApiClient $apiClient, User $user) {
$members = [];
if (empty($this->ChannelMembers)) {
$this
->getAllChannelMembersBatched($apiClient, $members);
}
$found = FALSE;
foreach ($this->ChannelMembers as $member) {
if (strcmp($user
->getName(), $member['name']) === 0) {
if (strcmp($user
->getUsername(), $member['username']) === 0) {
$found = TRUE;
break;
}
}
}
if (!$found) {
$user
->getUserProxy($apiClient);
$method = $methodBase = $this
->getChannelTypeName();
$membersJson = [];
$membersJson["json"] = [];
$membersJson["json"]['roomId'] = $this->Channel['_id'];
$membersJson["json"]['userId'] = $user
->getUser()['_id'];
$ret = $apiClient
->postToRocketChat($method . ".invite", $membersJson);
$this
->getAllChannelMembersBatched($apiClient, $members);
return $ret['body']['status'];
}
return false;
}