diff --git a/lib/Widget/MastodonProvider.php b/lib/Widget/MastodonProvider.php index 2e4d96a448..c337d6c9d6 100644 --- a/lib/Widget/MastodonProvider.php +++ b/lib/Widget/MastodonProvider.php @@ -46,7 +46,7 @@ public function fetchData(DataProviderInterface $dataProvider): WidgetProviderIn try { $httpOptions = [ - 'timeout' => 20, // wait no more than 20 seconds + // 'timeout' => 20, // wait no more than 20 seconds 'query' => [ 'limit' => $dataProvider->getProperty('numItems', 15) ] @@ -73,10 +73,9 @@ public function fetchData(DataProviderInterface $dataProvider): WidgetProviderIn // when username is provided do not search in public timeline if (!empty($dataProvider->getProperty('userName', ''))) { // username search: get account ID, always returns one record - $accountId = $this->getAccountId($uri, $dataProvider); + $accountId = $this->getAccountId($uri, $dataProvider->getProperty('userName'), $dataProvider); $httpOptions['query']['tagged'] = trim($hashtag, '#'); - ; - $result = $this->getResult($uri, $accountId, $httpOptions); + $uri = rtrim($uri, '/') . '/api/v1/accounts/' . $accountId . '/statuses?'; } else { // Hashtag: When empty we should do a public search, when filled we should do a hashtag search if (!empty($hashtag)) { @@ -84,13 +83,13 @@ public function fetchData(DataProviderInterface $dataProvider): WidgetProviderIn } else { $uri = rtrim($uri, '/') . '/api/v1/timelines/public'; } + } - $response = $dataProvider - ->getGuzzleClient($httpOptions) - ->get($uri); + $response = $dataProvider + ->getGuzzleClient($httpOptions) + ->get($uri); - $result = json_decode($response->getBody()->getContents(), true); - } + $result = json_decode($response->getBody()->getContents(), true); $this->getLog()->debug('Mastodon: uri: ' . $uri . ' httpOptions: ' . json_encode($httpOptions)); @@ -175,14 +174,14 @@ public function getDataModifiedDt(DataProviderInterface $dataProvider): ?Carbon * Get Mastodon Account Id from username * @throws GuzzleException */ - private function getAccountId(mixed $uri, DataProviderInterface $dataProvider) + private function getAccountId(string $uri, string $username, DataProviderInterface $dataProvider) { $uri = rtrim($uri, '/').'/api/v1/accounts/lookup?'; $httpOptions = [ 'timeout' => 20, // wait no more than 20 seconds 'query' => [ - 'acct' => $dataProvider->getProperty('userName') + 'acct' => $username ], ]; $response = $dataProvider @@ -195,20 +194,4 @@ private function getAccountId(mixed $uri, DataProviderInterface $dataProvider) return $result['id']; } - - /** - * Get Mastodon account public status - * @throws GuzzleException - */ - private function getResult(mixed $uri, $accountId, $httpOptions) - { - $uri = rtrim($uri, '/') . '/api/v1/accounts/' . $accountId . '/statuses?'; - - $client = new Client(); - $response = $client->request('GET', $uri, $httpOptions); - $result = json_decode($response->getBody()->getContents(), true); - - $this->getLog()->debug('Mastodon: username search result count ' . count($result)); - return $result; - } }