Skip to content

Commit 046c1f3

Browse files
author
Lawri van Buël
committed
Clean up of code pre realease commit
1 parent 5eb5c5e commit 046c1f3

File tree

18 files changed

+83
-203
lines changed

18 files changed

+83
-203
lines changed

modules/livechat/src/LivechatWidgetHandler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ private function setJavascriptParams($key) {
200200
* Key to set the value in.
201201
* @param mixed $value
202202
* Value to set in the key register.
203+
* @return mixed
204+
* @return mixed
203205
*/
204206
private function buildJavaScriptArray($key, $value) {
205207
$ds = $this->form['#attached']['drupalSettings'][$this->getWidgetLibraryName()][$this->getWidgetLibraryRoute()][$key] = $value;

modules/rocket_chat_api/src/RocketChat/ApiClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private function createClient($login = FALSE) {
118118
$userId = $this->config->getElement("rocket_chat_uid");
119119
$userToken = $this->config->getElement("rocket_chat_uit");
120120
$guzzleConfig = [
121-
'base_uri' => $this->config->getElement('rocket_chat_url', "http://localhost:3000") . '/api/',//v1/ removed for info.
121+
'base_uri' => $this->config->getElement('rocket_chat_url', "http://localhost:3000") . '/api/', // NOTE: v1/ removed for info. as its Deprecated in 1.0.0
122122
'allow_redirects' => FALSE,
123123
'timeout' => 60,
124124
'debug' => $this->config->isDebug(),

modules/rocket_chat_api/src/RocketChat/Collection/Channels.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Drupal\rocket_chat_api\RocketChat\Collection;
33

4+
use Drupal;
45
use Drupal\rocket_chat_api\RocketChat\RocketChatStateinterface as StateInterface;
56
use Drupal\rocket_chat_api\RocketChat\ApiClient;
67
use Drupal\rocket_chat_api\RocketChat\Element\Channel;
@@ -33,7 +34,7 @@ class Channels implements CollectionInterface {
3334
public function __construct(StateInterface $state,ApiClient $apiClient) {
3435
$this->state = $state;
3536
$this->apiClient = $apiClient;
36-
$this->Logger = \Drupal::logger("Rocket Chat API: Channels");
37+
$this->Logger = Drupal::logger("Rocket Chat API: Channels");
3738

3839
}
3940

@@ -68,8 +69,6 @@ public function refreshCache($forceReload = FALSE){
6869
$found = Channel::getAllChannelsBatched($this->apiClient, $channels);
6970
$channelIds = [];
7071
foreach ($channels as $channel){
71-
// $channelJson = json_encode($channel);
72-
$channelIds[] = $channel['_id'];
7372
$this->state->set(self::CHANNEL . $channel['_id'], $channel);
7473
}
7574
$this->state->set(self::LIST,$channelIds);

modules/rocket_chat_api/src/RocketChat/Collection/Groups.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
namespace Drupal\rocket_chat_api\RocketChat\Collection;
3+
use Drupal;
34
use Drupal\rocket_chat_api\RocketChat\RocketChatStateinterface as StateInterface;
45
use Drupal\rocket_chat_api\RocketChat\ApiClient;
56
use Drupal\rocket_chat_api\RocketChat\Element\Channel;
@@ -32,7 +33,7 @@ class Groups implements CollectionInterface {
3233
public function __construct(StateInterface $state,ApiClient $apiClient) {
3334
$this->state = $state;
3435
$this->apiClient = $apiClient;
35-
$this->Logger = \Drupal::logger("Rocket Chat API: Groups");
36+
$this->Logger = Drupal::logger("Rocket Chat API: Groups");
3637
}
3738

3839
public function getCache($forceReload = FALSE){

modules/rocket_chat_api/src/RocketChat/Collection/Users.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Drupal\rocket_chat_api\RocketChat\Collection;
33

4+
use Drupal;
45
use Drupal\rocket_chat_api\RocketChat\RocketChatStateinterface as StateInterface;
56
use Drupal\rocket_chat_api\RocketChat\ApiClient;
67
use Drupal\rocket_chat_api\RocketChat\Element\Channel;
@@ -35,11 +36,11 @@ class Users implements CollectionInterface {
3536
public function __construct(StateInterface $state,ApiClient $apiClient) {
3637
$this->state = $state;
3738
$this->apiClient = $apiClient;
38-
$this->Logger = \Drupal::logger("Rocket Chat API: Users");
39+
$this->Logger = Drupal::logger("Rocket Chat API: Users");
40+
//Todo Decouple this
3941

4042
}
4143

42-
4344
/**
4445
* @param bool $forceReload
4546
* @return array
@@ -57,7 +58,6 @@ public function getCache($forceReload = FALSE){
5758
return $users;
5859
}
5960

60-
6161
public function refreshCache($forceReload = FALSE){
6262
$lastUpdate = $this->state->get(self::UPDATE,0);
6363
$now = time();
@@ -85,6 +85,8 @@ public function refreshCache($forceReload = FALSE){
8585
* @param array $users
8686
* @param int $offset
8787
* @param int $size
88+
* @return float|int
89+
* @return float|int
8890
* @todo needs better Error checking / missing detection.
8991
*/
9092
public static function getAllUsersBatched(ApiClient &$api, array &$users, $offset=0, $size=500){

modules/rocket_chat_api/src/RocketChat/Drupal8Config.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Time: 16:38
1010
*/
1111

12+
use Drupal;
1213
use Drupal\Core\Config\ConfigFactoryInterface;
1314
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
1415
use Drupal\Core\Extension\ModuleHandlerInterface;
@@ -66,13 +67,14 @@ class Drupal8Config implements RocketChatConfigInterface, ContainerInjectionInte
6667
* The ModuleHandler to interact with loaded modules.
6768
* @param \Drupal\Core\State\StateInterface $state
6869
* The state interface to manipulate the States.
70+
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
6971
*/
7072
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $moduleHandler, StateInterface $state, MessengerInterface $messenger) {
7173
$this->config = $config_factory->get('rocket_chat.settings');
7274
$this->moduleHandler = $moduleHandler;
7375
$this->state = $state;
7476
$this->messenger = $messenger;
75-
$this->Logger = \Drupal::logger("Rocket Chat API: Config");
77+
$this->Logger = Drupal::logger("Rocket Chat API: Config");
7678
}
7779

7880
/**

modules/rocket_chat_api/src/RocketChat/Element/Channel.php

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ class Channel {
2121
const WRITE = 0b01000;
2222
const BROADCAST = 0b10000;
2323

24+
//Encodes like this: [Broadcast, Writeable Readable, public Channel, privateGroup]
2425
// BWRCG
2526
const DEFAULT_CHANNEL_TYPE = 0b01110;
2627

2728
/**
2829
* @var int Masked value indicating what type of Channel this uses;
2930
*/
30-
protected $ChannelType = NULL;//0b0111;//self::READ & self::WRITE & self::PUBLIC_CHANNEL;
31+
protected $ChannelType = NULL;
3132
protected $ChannelName = NULL;
3233

3334
private $ChannelMembers = [];
@@ -174,9 +175,6 @@ public function __get($name) {
174175
* @return bool|int
175176
*/
176177
public function hasType($test){
177-
// if($test === self::PRIVATE_CHANNEL){
178-
// return (!$this->hasType(self::PUBLIC_CHANNEL));//Test if NOT public
179-
// }
180178
return ($this->getChannelType() & $test) > 0;
181179
}
182180

@@ -372,10 +370,8 @@ public function getChannelProxy(ApiClient $apiClient){
372370
$ChannelList = new Channels($drupal8State, $apiClient);
373371
//TODO needs to replaced by state cached version.
374372
$Channels = $ChannelList->getCache();
375-
// Channel::getAllChannelsBatched($apiClient, $Channels);
376373
break;
377374
case "groups":
378-
//TODO Replace with
379375
$GroupList = new Groups($drupal8State,$apiClient);
380376
$Channels = $GroupList->getCache();
381377
if(is_null($Channels) || empty($Channels)){
@@ -410,6 +406,8 @@ public function getChannelProxy(ApiClient $apiClient){
410406
/**
411407
* Get Channel Type (channels|groups) or (public | private type.
412408
* @return string
409+
* @throws \Exception
410+
* @throws \Exception
413411
*/
414412
public function getChannelTypeName(){
415413
if ($this->hasType(Channel::PUBLIC_CHANNEL)) {
@@ -421,9 +419,8 @@ public function getChannelTypeName(){
421419
//Private Group
422420
}
423421
else {
424-
//TODO report this fail state!
422+
//TODO report this fial state better!
425423
throw new Exception("ERROR!");
426-
// return NULL;
427424
}
428425
return $methodBase;
429426
}
@@ -463,7 +460,7 @@ private function fetchChannel(array &$Channels,ApiClient &$apiClient,bool $write
463460
$members[] = $myProxy['body']['username'];
464461
}
465462
}
466-
$options['json']['members'] = $members;//Member names to add...
463+
$options['json']['members'] = $members; //Member names to add...
467464

468465
$ret = $apiClient->postToRocketChat("$methodBase.create", $options);
469466
//todo implement error check
@@ -485,7 +482,7 @@ private function fetchChannel(array &$Channels,ApiClient &$apiClient,bool $write
485482
$ownerJson['json']["userId"] = $myId; //Current User
486483
$remOwn = $apiClient->postToRocketChat("$methodBase.removeOwner", $ownerJson);
487484

488-
//todo implement error check
485+
//todo implement better error check
489486
}
490487
} else {
491488
$logger = drupal::logger("Rocket Chat API");
@@ -494,10 +491,8 @@ private function fetchChannel(array &$Channels,ApiClient &$apiClient,bool $write
494491
}
495492
}
496493
else {
497-
//TODO REplace with
498494
$ret = [];
499495
$ret['body'] = [];
500-
// $ret['body'][rtrim($methodBase,"s")] = [];
501496
$ret['body'][rtrim($methodBase,"s")] = $this->getFromList($Channels);
502497
$ret2 = $apiClient->getFromRocketChat("$methodBase.info", ["query" => ["roomName" => $this->getSafeChannelName()]]);
503498
$ret3 = $ret;
@@ -507,8 +502,10 @@ private function fetchChannel(array &$Channels,ApiClient &$apiClient,bool $write
507502

508503
/**
509504
* @param \Drupal\rocket_chat_api\RocketChat\ApiClient $apiClient
510-
* @param \Drupal\rocket_chat_api\RocketChat\Element\User[] $user
505+
* @param \Drupal\rocket_chat_api\RocketChat\Element\User[] $users
511506
*
507+
* @return array
508+
* @return array
512509
* @throws \Exception
513510
*/
514511
public function addMembers(ApiClient $apiClient, $users) {
@@ -523,6 +520,8 @@ public function addMembers(ApiClient $apiClient, $users) {
523520
* @param \Drupal\rocket_chat_api\RocketChat\ApiClient $apiClient
524521
* @param \Drupal\rocket_chat_api\RocketChat\Element\User $user
525522
*
523+
* @return bool|mixed
524+
* @return bool|mixed
526525
* @throws \Exception
527526
*/
528527
public function addMember(ApiClient $apiClient, User $user){
@@ -541,7 +540,7 @@ public function addMember(ApiClient $apiClient, User $user){
541540
}
542541
if(!$found){
543542
$user->getUserProxy($apiClient);
544-
$method = $methodBase = $this->getChannelTypeName();//$user->getUserProxy($apiClient);
543+
$method = $methodBase = $this->getChannelTypeName();
545544
$membersJson = [];
546545
$membersJson["json"] = [];
547546
$membersJson["json"]['roomId'] = $this->Channel['_id'];
@@ -550,7 +549,6 @@ public function addMember(ApiClient $apiClient, User $user){
550549
$this->getAllChannelMembersBatched($apiClient,$members);
551550

552551
return $ret['body']['status'];
553-
// return $ret['body']['success'];
554552
}
555553
return false;
556554
}
@@ -571,7 +569,7 @@ public function removeMember(ApiClient $apiClient, User $user){
571569
}
572570
if($found){
573571
$user->getUserProxy($apiClient);
574-
$method = $methodBase = $this->getChannelTypeName();//$user->getUserProxy($apiClient);
572+
$method = $methodBase = $this->getChannelTypeName();
575573
$membersJson = [];
576574
$membersJson["json"] = [];
577575
$membersJson["json"]['roomId'] = $this->Channel['_id'];
@@ -580,7 +578,6 @@ public function removeMember(ApiClient $apiClient, User $user){
580578
$this->getAllChannelMembersBatched($apiClient,$members);
581579

582580
return $ret['body']['status'];
583-
// return $ret['body']['success'];
584581
}
585582
return false;
586583
}
@@ -617,12 +614,6 @@ public function getChannelURI(){
617614
}
618615

619616
public function changeChannelName(ApiClient $apiClient, string $newName){
620-
// $this->getChannelProxy($apiClient);
621-
// $state = \Drupal::service('state');
622-
// $ChannelList = new Channels(new Drupal8State($state), $apiClient);
623-
// $Channels = $ChannelList->getCachedChannels();
624-
// $ret = $this->fetchChannel($Channels, $apiClient, $this->hasType(Channel::WRITE), $this->getChannelTypeName());
625-
//
626617
$channelProxy = $this->getChannelProxy($apiClient);
627618
if(strcmp($this->getSafeChannelName(), self::toSafeChannelName($newName) !== 0)){
628619
$methodBase = $this->getChannelTypeName();
@@ -631,7 +622,7 @@ public function changeChannelName(ApiClient $apiClient, string $newName){
631622
$rename['json']['roomId'] = $this->Channel['_id'];
632623
$rename['json']['name'] = self::toSafeChannelName($newName);
633624
$ret = $apiClient->postToRocketChat($methodBase . ".rename",$rename);
634-
//needs Check.
625+
//TODO implement better Check.
635626
$this->Channel = $ret['body'][rtrim($methodBase, "s")];
636627
$state = Drupal::service('state');
637628
$ChannelList = new Channels(new Drupal8State($state), $apiClient);

modules/rocket_chat_api/src/RocketChat/Element/User.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\rocket_chat_api\RocketChat\Element;
44

55

6+
use Drupal;
67
use Drupal\rocket_chat_api\RocketChat\ApiClient;
78
use Drupal\rocket_chat_api\RocketChat\Collection\Users;
89
use Drupal\rocket_chat_api\RocketChat\RocketChatStateinterface;
@@ -94,7 +95,7 @@ public function __construct(RocketChatStateinterface $state, $username = NULL,$e
9495
$this->username = $username;
9596
$this->email = $email;
9697
$this->name = $name;
97-
$this->Logger = \Drupal::logger("Rocket Chat API: User");
98+
$this->Logger = Drupal::logger("Rocket Chat API: User");
9899
}
99100

100101
/**
@@ -132,13 +133,14 @@ private function getFromList($list){
132133
}
133134
return NULL;
134135
}
136+
135137
/**
136138
* Retrieve the Proxy, create the User if needed.
137139
*
138140
* @param \Drupal\rocket_chat_api\RocketChat\ApiClient $apiClient
139141
*
140142
* @return array|null
141-
* @throws \Exception
143+
* @throws Exception
142144
*/
143145
public function getUserProxy(ApiClient $apiClient){
144146
if(empty($this->User)) {
@@ -150,9 +152,6 @@ public function getUserProxy(ApiClient $apiClient){
150152
}
151153
$usersState = new Users($this->state, $apiClient);
152154
$users = $usersState->getCache();
153-
154-
// $users = new Users($this->state, $apiClient);
155-
// self::getAllUsersBatched($apiClient, $users);
156155
if (!$this->isInList($users)) {
157156
$options = [];
158157
$options['json'] = [];

modules/rocket_chat_group/rocket_chat_group.module

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function rocket_chat_group_group_content_insert(Drupal\group\Entity\GroupContent
3131
//Update
3232
/**
3333
* Implements hook_ENTITY_TYPE_update().
34+
* @param \Drupal\group\Entity\GroupContent $entity
3435
*/
3536
function rocket_chat_group_group_content_update(Drupal\group\Entity\GroupContent $entity) {
3637
try {
@@ -47,6 +48,7 @@ function rocket_chat_group_group_content_update(Drupal\group\Entity\GroupContent
4748
//Delete
4849
/**
4950
* Implements hook_ENTITY_TYPE_delete().
51+
* @param \Drupal\group\Entity\GroupContent $entity
5052
*/
5153
function rocket_chat_group_group_content_delete(Drupal\group\Entity\GroupContent $entity) {
5254
try {
@@ -62,6 +64,11 @@ function rocket_chat_group_group_content_delete(Drupal\group\Entity\GroupContent
6264

6365
/**
6466
* Implements hook_theme().
67+
* @param $existing
68+
* @param $type
69+
* @param $theme
70+
* @param $path
71+
* @return \array[][]
6572
*/
6673
function rocket_chat_group_theme($existing, $type, $theme, $path) {
6774
return moduleHelper::themeRocketChannelBLock($existing, $type, $theme, $path);

0 commit comments

Comments
 (0)