Skip to content

Commit

Permalink
Update Federation, use proper Content-Type headers for following/foll…
Browse files Browse the repository at this point in the history
…ower collections
  • Loading branch information
dansup committed Feb 16, 2024
1 parent 221fe43 commit fb0bb9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/FederationController.php
Expand Up @@ -253,7 +253,7 @@ public function userFollowing(Request $request, $username)
'type' => 'OrderedCollection',
'totalItems' => $account['following_count'] ?? 0,
];
return response()->json($obj);
return response()->json($obj)->header('Content-Type', 'application/activity+json');
}

public function userFollowers(Request $request, $username)
Expand All @@ -269,6 +269,6 @@ public function userFollowers(Request $request, $username)
'type' => 'OrderedCollection',
'totalItems' => $account['followers_count'] ?? 0,
];
return response()->json($obj);
return response()->json($obj)->header('Content-Type', 'application/activity+json');
}
}
18 changes: 18 additions & 0 deletions app/Util/ActivityPub/Helpers.php
Expand Up @@ -372,6 +372,10 @@ public static function statusFirstOrFetch($url, $replyTo = false)
$idDomain = parse_url($id, PHP_URL_HOST);
$urlDomain = parse_url($url, PHP_URL_HOST);

if($idDomain && $urlDomain && strtolower($idDomain) !== strtolower($urlDomain)) {
return;
}

if(!self::validateUrl($id)) {
return;
}
Expand Down Expand Up @@ -455,14 +459,21 @@ public static function statusFirstOrFetch($url, $replyTo = false)

public static function storeStatus($url, $profile, $activity)
{
$originalUrl = $url;
$id = isset($activity['id']) ? self::pluckval($activity['id']) : self::pluckval($activity['url']);
$url = isset($activity['url']) && is_string($activity['url']) ? self::pluckval($activity['url']) : self::pluckval($id);
$idDomain = parse_url($id, PHP_URL_HOST);
$urlDomain = parse_url($url, PHP_URL_HOST);
$originalUrlDomain = parse_url($originalUrl, PHP_URL_HOST);
if(!self::validateUrl($id) || !self::validateUrl($url)) {
return;
}

if( strtolower($originalUrlDomain) !== strtolower($idDomain) ||
strtolower($originalUrlDomain) !== strtolower($urlDomain) ) {
return;
}

$reply_to = self::getReplyTo($activity);

$ts = self::pluckval($activity['published']);
Expand Down Expand Up @@ -763,7 +774,11 @@ public static function profileUpdateOrCreate($url)
if(!$res || isset($res['id']) == false) {
return;
}
$urlDomain = parse_url($url, PHP_URL_HOST);
$domain = parse_url($res['id'], PHP_URL_HOST);
if(strtolower($urlDomain) !== strtolower($domain)) {
return;
}
if(!isset($res['preferredUsername']) && !isset($res['nickname'])) {
return;
}
Expand Down Expand Up @@ -831,6 +846,9 @@ public static function profileFetch($url)

public static function sendSignedObject($profile, $url, $body)
{
if(app()->environment() !== 'production') {
return;
}
ActivityPubDeliveryService::queue()
->from($profile)
->to($url)
Expand Down

0 comments on commit fb0bb9a

Please sign in to comment.