public function Channel::getChannelProxy in Rocket.Chat 8.2
Retrieve the Proxy, create the Channel / Group if needed.
Parameters
\Drupal\rocket_chat_api\RocketChat\ApiClient $apiClient:
Return value
array|null
Throws
\Exception
2 calls to Channel::getChannelProxy()
- Channel::changeChannelName in modules/
rocket_chat_api/ src/ RocketChat/ Element/ Channel.php - Channel::getAllChannelMembersBatched in modules/
rocket_chat_api/ src/ RocketChat/ Element/ Channel.php - Retrieve Chat Private Groups list. (in batch size)
File
- modules/
rocket_chat_api/ src/ RocketChat/ Element/ Channel.php, line 350
Class
Namespace
Drupal\rocket_chat_api\RocketChat\ElementCode
public function getChannelProxy(ApiClient $apiClient) {
if (!$this
->isEmpty()) {
$Channels = [];
$readChannel = $this
->hasType(Channel::READ);
$writeChannel = $this
->hasType(Channel::WRITE);
$broadcastChannel = $this
->hasType(Channel::BROADCAST);
if (!$readChannel) {
//Nothing to do when we can't read a channel.
//TODO need own error to throw.
throw new ImplementationError("Trying to do something with an unreadable channel??");
}
if ($broadcastChannel) {
throw new ImplementationError("Broadcast is not implemented yet, why use it??");
}
$methodBase = $this
->getChannelTypeName();
$state = Drupal::service('state');
$drupal8State = new Drupal8State($state);
switch ($methodBase) {
case "channels":
$ChannelList = new Channels($drupal8State, $apiClient);
//TODO needs to replaced by state cached version.
$Channels = $ChannelList
->getCache();
break;
case "groups":
$GroupList = new Groups($drupal8State, $apiClient);
$Channels = $GroupList
->getCache();
if (is_null($Channels) || empty($Channels)) {
$Channels = [];
$ChannelsB = Channel::getAllGroupsBatched($apiClient, $Channels);
}
break;
default:
//TODO report error!
break;
}
///TODO check if group exists?
$members = [];
$ret = $this
->fetchChannel($Channels, $apiClient, $writeChannel, $methodBase);
if (is_null($ret)) {
$this->Logger
->error("No Channel/Group found and creation failed.");
return NULL;
}
if (!isset($ret['body'][rtrim($methodBase, "s")]) || empty($ret['body'][rtrim($methodBase, "s")])) {
$this->Logger
->error("Error Retrieving Details |" . json_encode($ret));
return NULL;
}
$this->Channel = $ret['body'][rtrim($methodBase, "s")];
$members = [];
$this
->getAllChannelMembersBatched($apiClient, $members);
return $this->Channel;
}
else {
return null;
}
}