@@ -21,13 +21,14 @@ class Channel {
21
21
const WRITE = 0b01000 ;
22
22
const BROADCAST = 0b10000 ;
23
23
24
+ //Encodes like this: [Broadcast, Writeable Readable, public Channel, privateGroup]
24
25
// BWRCG
25
26
const DEFAULT_CHANNEL_TYPE = 0b01110 ;
26
27
27
28
/**
28
29
* @var int Masked value indicating what type of Channel this uses;
29
30
*/
30
- protected $ ChannelType = NULL ;//0b0111;//self::READ & self::WRITE & self::PUBLIC_CHANNEL;
31
+ protected $ ChannelType = NULL ;
31
32
protected $ ChannelName = NULL ;
32
33
33
34
private $ ChannelMembers = [];
@@ -174,9 +175,6 @@ public function __get($name) {
174
175
* @return bool|int
175
176
*/
176
177
public function hasType ($ test ){
177
- // if($test === self::PRIVATE_CHANNEL){
178
- // return (!$this->hasType(self::PUBLIC_CHANNEL));//Test if NOT public
179
- // }
180
178
return ($ this ->getChannelType () & $ test ) > 0 ;
181
179
}
182
180
@@ -372,10 +370,8 @@ public function getChannelProxy(ApiClient $apiClient){
372
370
$ ChannelList = new Channels ($ drupal8State , $ apiClient );
373
371
//TODO needs to replaced by state cached version.
374
372
$ Channels = $ ChannelList ->getCache ();
375
- // Channel::getAllChannelsBatched($apiClient, $Channels);
376
373
break ;
377
374
case "groups " :
378
- //TODO Replace with
379
375
$ GroupList = new Groups ($ drupal8State ,$ apiClient );
380
376
$ Channels = $ GroupList ->getCache ();
381
377
if (is_null ($ Channels ) || empty ($ Channels )){
@@ -410,6 +406,8 @@ public function getChannelProxy(ApiClient $apiClient){
410
406
/**
411
407
* Get Channel Type (channels|groups) or (public | private type.
412
408
* @return string
409
+ * @throws \Exception
410
+ * @throws \Exception
413
411
*/
414
412
public function getChannelTypeName (){
415
413
if ($ this ->hasType (Channel::PUBLIC_CHANNEL )) {
@@ -421,9 +419,8 @@ public function getChannelTypeName(){
421
419
//Private Group
422
420
}
423
421
else {
424
- //TODO report this fail state!
422
+ //TODO report this fial state better !
425
423
throw new Exception ("ERROR! " );
426
- // return NULL;
427
424
}
428
425
return $ methodBase ;
429
426
}
@@ -463,7 +460,7 @@ private function fetchChannel(array &$Channels,ApiClient &$apiClient,bool $write
463
460
$ members [] = $ myProxy ['body ' ]['username ' ];
464
461
}
465
462
}
466
- $ options ['json ' ]['members ' ] = $ members ;//Member names to add...
463
+ $ options ['json ' ]['members ' ] = $ members ; //Member names to add...
467
464
468
465
$ ret = $ apiClient ->postToRocketChat ("$ methodBase.create " , $ options );
469
466
//todo implement error check
@@ -485,7 +482,7 @@ private function fetchChannel(array &$Channels,ApiClient &$apiClient,bool $write
485
482
$ ownerJson ['json ' ]["userId " ] = $ myId ; //Current User
486
483
$ remOwn = $ apiClient ->postToRocketChat ("$ methodBase.removeOwner " , $ ownerJson );
487
484
488
- //todo implement error check
485
+ //todo implement better error check
489
486
}
490
487
} else {
491
488
$ logger = drupal::logger ("Rocket Chat API " );
@@ -494,10 +491,8 @@ private function fetchChannel(array &$Channels,ApiClient &$apiClient,bool $write
494
491
}
495
492
}
496
493
else {
497
- //TODO REplace with
498
494
$ ret = [];
499
495
$ ret ['body ' ] = [];
500
- // $ret['body'][rtrim($methodBase,"s")] = [];
501
496
$ ret ['body ' ][rtrim ($ methodBase ,"s " )] = $ this ->getFromList ($ Channels );
502
497
$ ret2 = $ apiClient ->getFromRocketChat ("$ methodBase.info " , ["query " => ["roomName " => $ this ->getSafeChannelName ()]]);
503
498
$ ret3 = $ ret ;
@@ -507,8 +502,10 @@ private function fetchChannel(array &$Channels,ApiClient &$apiClient,bool $write
507
502
508
503
/**
509
504
* @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
511
506
*
507
+ * @return array
508
+ * @return array
512
509
* @throws \Exception
513
510
*/
514
511
public function addMembers (ApiClient $ apiClient , $ users ) {
@@ -523,6 +520,8 @@ public function addMembers(ApiClient $apiClient, $users) {
523
520
* @param \Drupal\rocket_chat_api\RocketChat\ApiClient $apiClient
524
521
* @param \Drupal\rocket_chat_api\RocketChat\Element\User $user
525
522
*
523
+ * @return bool|mixed
524
+ * @return bool|mixed
526
525
* @throws \Exception
527
526
*/
528
527
public function addMember (ApiClient $ apiClient , User $ user ){
@@ -541,7 +540,7 @@ public function addMember(ApiClient $apiClient, User $user){
541
540
}
542
541
if (!$ found ){
543
542
$ user ->getUserProxy ($ apiClient );
544
- $ method = $ methodBase = $ this ->getChannelTypeName ();//$user->getUserProxy($apiClient);
543
+ $ method = $ methodBase = $ this ->getChannelTypeName ();
545
544
$ membersJson = [];
546
545
$ membersJson ["json " ] = [];
547
546
$ membersJson ["json " ]['roomId ' ] = $ this ->Channel ['_id ' ];
@@ -550,7 +549,6 @@ public function addMember(ApiClient $apiClient, User $user){
550
549
$ this ->getAllChannelMembersBatched ($ apiClient ,$ members );
551
550
552
551
return $ ret ['body ' ]['status ' ];
553
- // return $ret['body']['success'];
554
552
}
555
553
return false ;
556
554
}
@@ -571,7 +569,7 @@ public function removeMember(ApiClient $apiClient, User $user){
571
569
}
572
570
if ($ found ){
573
571
$ user ->getUserProxy ($ apiClient );
574
- $ method = $ methodBase = $ this ->getChannelTypeName ();//$user->getUserProxy($apiClient);
572
+ $ method = $ methodBase = $ this ->getChannelTypeName ();
575
573
$ membersJson = [];
576
574
$ membersJson ["json " ] = [];
577
575
$ membersJson ["json " ]['roomId ' ] = $ this ->Channel ['_id ' ];
@@ -580,7 +578,6 @@ public function removeMember(ApiClient $apiClient, User $user){
580
578
$ this ->getAllChannelMembersBatched ($ apiClient ,$ members );
581
579
582
580
return $ ret ['body ' ]['status ' ];
583
- // return $ret['body']['success'];
584
581
}
585
582
return false ;
586
583
}
@@ -617,12 +614,6 @@ public function getChannelURI(){
617
614
}
618
615
619
616
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
- //
626
617
$ channelProxy = $ this ->getChannelProxy ($ apiClient );
627
618
if (strcmp ($ this ->getSafeChannelName (), self ::toSafeChannelName ($ newName ) !== 0 )){
628
619
$ methodBase = $ this ->getChannelTypeName ();
@@ -631,7 +622,7 @@ public function changeChannelName(ApiClient $apiClient, string $newName){
631
622
$ rename ['json ' ]['roomId ' ] = $ this ->Channel ['_id ' ];
632
623
$ rename ['json ' ]['name ' ] = self ::toSafeChannelName ($ newName );
633
624
$ ret = $ apiClient ->postToRocketChat ($ methodBase . ".rename " ,$ rename );
634
- //needs Check.
625
+ //TODO implement better Check.
635
626
$ this ->Channel = $ ret ['body ' ][rtrim ($ methodBase , "s " )];
636
627
$ state = Drupal::service ('state ' );
637
628
$ ChannelList = new Channels (new Drupal8State ($ state ), $ apiClient );
0 commit comments