Added channel type filtering

This commit is contained in:
aymm 2021-04-18 13:10:05 +02:00
parent 18eb80cb6f
commit 51a798ea3e
Signed by: phlaym
GPG Key ID: A06651BAB6777237

View File

@ -210,13 +210,17 @@ class APnutI
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
} }
if ($method === 'GET' && isset($parameters['access_token'])) { if ($method === 'GET' && isset($parameters['access_token'])) {
$this->logger->info("Using provided token for auth");
$headers[] = 'Authorization: Bearer '.$params['access_token']; $headers[] = 'Authorization: Bearer '.$params['access_token'];
} elseif (!empty($this->access_token)) { } elseif (!empty($this->access_token)) {
$this->logger->info("Using access token for auth");
$headers[] = 'Authorization: Bearer '.$this->access_token; $headers[] = 'Authorization: Bearer '.$this->access_token;
} elseif (!empty($this->server_token)) { } elseif (!empty($this->server_token)) {
$use_server_token = true; $use_server_token = true;
$this->logger->info("Using server token for auth"); $this->logger->info("Using server token for auth");
$headers[] = 'Authorization: Bearer '.$this->server_token; $headers[] = 'Authorization: Bearer '.$this->server_token;
} else {
$this->logger->info("Using no auth");
} }
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
@ -698,11 +702,20 @@ class APnutI
return new Channel($this->get('/channels/'.$channel_id, $parameters), $this); return new Channel($this->get('/channels/'.$channel_id, $parameters), $this);
} }
public function getSubscribedChannel(): array public function getSubscribedChannels(bool $include_pms = true, bool $include_channels = true): array
{ {
# Always include channel raw, it contains the channel name # Always include channel raw, it contains the channel name
$channel_types = [];
if ($include_pms) {
$channel_types[] = 'io.pnut.core.pm';
}
if ($include_channels) {
$channel_types[] = 'io.pnut.core.chat';
}
$parameters = [ $parameters = [
'include_channel_raw' => true 'include_channel_raw' => true,
'channel_types' => implode(',', $channel_types)
]; ];
$channels = []; $channels = [];
$resp = $this->get('/users/me/channels/subscribed', $parameters); $resp = $this->get('/users/me/channels/subscribed', $parameters);
@ -765,4 +778,9 @@ class APnutI
throw new PnutException("Error retrieving app access token: ".json_encode($resp)); throw new PnutException("Error retrieving app access token: ".json_encode($resp));
} }
} }
public function getAccessToken(): string
{
return $this->access_token;
}
} }