You are here

public function Channel::changeChannelName in Rocket.Chat 8.2

File

modules/rocket_chat_api/src/RocketChat/Element/Channel.php, line 616

Class

Channel

Namespace

Drupal\rocket_chat_api\RocketChat\Element

Code

public function changeChannelName(ApiClient $apiClient, string $newName) {
  $channelProxy = $this
    ->getChannelProxy($apiClient);
  if (strcmp($this
    ->getSafeChannelName(), self::toSafeChannelName($newName) !== 0)) {
    $methodBase = $this
      ->getChannelTypeName();
    $rename = [];
    $rename['json'] = [];
    $rename['json']['roomId'] = $this->Channel['_id'];
    $rename['json']['name'] = self::toSafeChannelName($newName);
    $ret = $apiClient
      ->postToRocketChat($methodBase . ".rename", $rename);

    //TODO implement better Check.
    $this->Channel = $ret['body'][rtrim($methodBase, "s")];
    $state = Drupal::service('state');
    $ChannelList = new Channels(new Drupal8State($state), $apiClient);
    $ChannelList
      ->refreshCache(TRUE);
  }
}