summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authormatt <34400929+call-me-matt@users.noreply.github.com>2023-07-27 12:23:07 +0200
committerGitHub <noreply@github.com>2023-07-27 12:23:07 +0200
commit18819a5baa084110b603c0fd550e9d9e19abe4f8 (patch)
treec68b07a03b8fadfe2374d438ed46eeb9b92f5841 /lib
parentc73c7cf068b1df7f87ee62d5342e9c165695f485 (diff)
parent115b1b47335c79ee5b8f11c8e2c8f1f45da7e357 (diff)
Merge pull request #3504 from nextcloud/fix/social-mastodon
change Mastodon tree for social avatar
Diffstat (limited to 'lib')
-rw-r--r--lib/Service/Social/MastodonProvider.php28
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/Service/Social/MastodonProvider.php b/lib/Service/Social/MastodonProvider.php
index 37f20862..fb7f5cf2 100644
--- a/lib/Service/Social/MastodonProvider.php
+++ b/lib/Service/Social/MastodonProvider.php
@@ -79,9 +79,9 @@ class MastodonProvider implements ISocialProvider {
*/
public function getImageUrl(string $profileUrl):?string {
try {
- $result = $this->httpClient->get($profileUrl);
- $jsonResult = json_decode($result->getBody());
- return $jsonResult->avatar;
+ $result = $this->httpClient->get($profileUrl, ['headers' => ['Accept' => 'application/json']]);
+ $jsonResult = json_decode($result->getBody(), true);
+ return $jsonResult["icon"]["url"] ?? null;
} catch (\Exception $e) {
return null;
}
@@ -104,14 +104,18 @@ class MastodonProvider implements ISocialProvider {
if (isset($masto_user_server)) {
try {
[$masto_user, $masto_server] = $masto_user_server;
- # search for user on Mastodon
- $search = $masto_server . '/api/v2/search?q=' . $masto_user . '@' . parse_url($masto_server)["host"];
- $result = $this->httpClient->get($search);
- $jsonResult = json_decode($result->getBody());
- # take first search result
- $masto_id = $jsonResult->accounts[0]->id;
- $profileId = $masto_server . "/api/v1/accounts/" . $masto_id;
- $profileIds[] = $profileId;
+ # search for user webfinger
+ $webfinger = $masto_server . '/.well-known/webfinger?resource=acct:' . $masto_user . '@' . parse_url($masto_server)["host"];
+ $result = $this->httpClient->get($webfinger);
+ $jsonResult = json_decode($result->getBody(), null, 512, JSON_THROW_ON_ERROR);
+ # find account link
+ foreach ($jsonResult->links as $link) {
+ if (($link->rel == "self") and ($link->type == "application/activity+json")) {
+ $profileId = $link->href;
+ $profileIds[] = $profileId;
+ break;
+ }
+ }
} catch (\Exception $e) {
continue;
}
@@ -143,6 +147,8 @@ class MastodonProvider implements ISocialProvider {
if ((empty($masto_server)) || (empty($masto_user))) {
return null;
}
+ $masto_user = trim($masto_user, '/');
+ $masto_server = trim($masto_server, '/');
return array($masto_user, $masto_server);
} catch (\Exception $e) {
return null;