You are here

public function Channel::getAllChannelMembersBatched in Rocket.Chat 8.2

Retrieve Chat Private Groups list. (in batch size)

@todo needs better Error checking / missing detection.

Parameters

\Drupal\rocket_chat_api\RocketChat\ApiClient $api:

array $members:

int $offset:

int $size:

int $level: for entry level. anything else is unsuported.

Return value

int Total number of Groups found.

Throws

\Exception

3 calls to Channel::getAllChannelMembersBatched()
Channel::addMember in modules/rocket_chat_api/src/RocketChat/Element/Channel.php
Channel::getChannelProxy in modules/rocket_chat_api/src/RocketChat/Element/Channel.php
Retrieve the Proxy, create the Channel / Group if needed.
Channel::removeMember in modules/rocket_chat_api/src/RocketChat/Element/Channel.php

File

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

Class

Channel

Namespace

Drupal\rocket_chat_api\RocketChat\Element

Code

public function getAllChannelMembersBatched(ApiClient &$api, array &$members, $offset = 0, $size = 500, $level = 0) {
  if (empty($this->Channel)) {
    $this
      ->getChannelProxy($api);
  }
  $method = $this
    ->getChannelTypeName();
  $retOptions = [
    "query" => [
      "offset" => $offset,
      "count" => $size,
      "roomId" => $this->Channel['_id'],
    ],
  ];
  $ret = $api
    ->getFromRocketChat("{$method}" . ".members", $retOptions);
  foreach ($ret['body']['members'] as $index => $member) {
    $members[] = $member;
  }
  $total = $ret['body']['total'];
  $count = $ret['body']['count'];
  $retOffset = $ret['body']['offset'];
  $subTotal = $count * (1 + $retOffset);
  $roomsLeft = $total - $subTotal;
  if ($roomsLeft > 0) {
    self::getAllChannelMembersBatched($api, $members, ++$offset, $size, ++$level);
  }
  if ($level === 0) {
    $this->ChannelMembers = $members;
  }
  return $total;
}