class Channels in Rocket.Chat 8.2
Hierarchy
- class \Drupal\rocket_chat_api\RocketChat\Collection\Channels implements CollectionInterface
Expanded class hierarchy of Channels
5 files declare their use of Channels
- Channel.php in modules/
rocket_chat_api/ src/ RocketChat/ Element/ Channel.php - GroupChannel.php in modules/
rocket_chat_group/ src/ Plugin/ Field/ FieldType/ GroupChannel.php - moduleHelper.php in modules/
rocket_chat_group/ src/ RocketChat/ moduleHelper.php - RocketChatGroupHelper.php in src/
Form/ RocketChatGroupHelper.php - RocketChatSettingsForm.php in src/
Form/ RocketChatSettingsForm.php - Contains \Drupal\rocket_chat\Form\RocketChatSettingsForm.
File
- modules/
rocket_chat_api/ src/ RocketChat/ Collection/ Channels.php, line 10
Namespace
Drupal\rocket_chat_api\RocketChat\CollectionView source
class Channels implements CollectionInterface {
/**
* @var \Psr\Log\LoggerInterface
*/
protected $Logger;
/**
* @var \Drupal\rocket_chat_api\RocketChat\RocketChatStateinterface
*/
private $state;
/**
* @var \Drupal\rocket_chat_api\RocketChat\ApiClient
*/
private $apiClient;
/**
* Cache Names (or stub name).
*/
public const LIST = "rocket.chat.channel.list";
public const UPDATE = "rocket.chat.channel.lastUpdate";
public const CHANNEL = "rocket.chat.channel.";
public function __construct(StateInterface $state, ApiClient $apiClient) {
$this->state = $state;
$this->apiClient = $apiClient;
$this->Logger = Drupal::logger("Rocket Chat API: Channels");
}
/**
* @param bool $forceReload
*
* @return array
*/
public function getCache($forceReload = FALSE) {
$this
->refreshCache(FALSE);
$idList = $this->state
->get(self::LIST, []);
foreach ($idList as $index => $id) {
$idList[$index] = self::CHANNEL . $id;
}
$channels = $this->state
->getMultiple($idList);
if (empty($channels)) {
$channels = [];
}
return $channels;
}
public function refreshCache($forceReload = FALSE) {
$lastUpdate = $this->state
->get(self::UPDATE, 0);
$now = time();
if ($now - $lastUpdate >= 3600 * 24 * 7) {
$this->Logger
->info("Refreshing Channels Cache due to stale Cache (timeout)");
$forceReload = TRUE;
}
if ($forceReload) {
$channels = [];
$found = Channel::getAllChannelsBatched($this->apiClient, $channels);
$channelIds = [];
foreach ($channels as $channel) {
$this->state
->set(self::CHANNEL . $channel['_id'], $channel);
}
$this->state
->set(self::LIST, $channelIds);
$this->state
->set(self::UPDATE, $now);
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Channels:: |
private | property | ||
Channels:: |
protected | property | ||
Channels:: |
private | property | ||
Channels:: |
public | constant | ||
Channels:: |
public | function |
Overrides CollectionInterface:: |
|
Channels:: |
public | constant | Cache Names (or stub name). | |
Channels:: |
public | function |
Overrides CollectionInterface:: |
|
Channels:: |
public | constant | ||
Channels:: |
public | function |