Update activitpub setting, use config_cache()

This commit is contained in:
Daniel Supernault 2024-03-12 02:20:37 -06:00
parent 40478f258a
commit 5071aaf408
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1
10 changed files with 833 additions and 839 deletions

View file

@ -2,41 +2,25 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Jobs\InboxPipeline\{ use App\Jobs\InboxPipeline\DeleteWorker;
DeleteWorker, use App\Jobs\InboxPipeline\InboxValidator;
InboxWorker, use App\Jobs\InboxPipeline\InboxWorker;
InboxValidator use App\Profile;
};
use App\Jobs\RemoteFollowPipeline\RemoteFollowPipeline;
use App\{
AccountLog,
Like,
Profile,
Status,
User
};
use App\Util\Lexer\Nickname;
use App\Util\Webfinger\Webfinger;
use Auth;
use Cache;
use Carbon\Carbon;
use Illuminate\Http\Request;
use League\Fractal;
use App\Util\Site\Nodeinfo;
use App\Util\ActivityPub\{
Helpers,
HttpSignature,
Outbox
};
use Zttp\Zttp;
use App\Services\InstanceService;
use App\Services\AccountService; use App\Services\AccountService;
use App\Services\InstanceService;
use App\Status;
use App\Util\Lexer\Nickname;
use App\Util\Site\Nodeinfo;
use App\Util\Webfinger\Webfinger;
use Cache;
use Illuminate\Http\Request;
class FederationController extends Controller class FederationController extends Controller
{ {
public function nodeinfoWellKnown() public function nodeinfoWellKnown()
{ {
abort_if(! config('federation.nodeinfo.enabled'), 404); abort_if(! config('federation.nodeinfo.enabled'), 404);
return response()->json(Nodeinfo::wellKnown(), 200, [], JSON_UNESCAPED_SLASHES) return response()->json(Nodeinfo::wellKnown(), 200, [], JSON_UNESCAPED_SLASHES)
->header('Access-Control-Allow-Origin', '*'); ->header('Access-Control-Allow-Origin', '*');
} }
@ -44,6 +28,7 @@ class FederationController extends Controller
public function nodeinfo() public function nodeinfo()
{ {
abort_if(! config('federation.nodeinfo.enabled'), 404); abort_if(! config('federation.nodeinfo.enabled'), 404);
return response()->json(Nodeinfo::get(), 200, [], JSON_UNESCAPED_SLASHES) return response()->json(Nodeinfo::get(), 200, [], JSON_UNESCAPED_SLASHES)
->header('Access-Control-Allow-Origin', '*'); ->header('Access-Control-Allow-Origin', '*');
} }
@ -65,21 +50,22 @@ class FederationController extends Controller
$res = [ $res = [
'subject' => 'acct:'.$domain.'@'.$domain, 'subject' => 'acct:'.$domain.'@'.$domain,
'aliases' => [ 'aliases' => [
'https://' . $domain . '/i/actor' 'https://'.$domain.'/i/actor',
], ],
'links' => [ 'links' => [
[ [
'rel' => 'http://webfinger.net/rel/profile-page', 'rel' => 'http://webfinger.net/rel/profile-page',
'type' => 'text/html', 'type' => 'text/html',
'href' => 'https://' . $domain . '/site/kb/instance-actor' 'href' => 'https://'.$domain.'/site/kb/instance-actor',
], ],
[ [
'rel' => 'self', 'rel' => 'self',
'type' => 'application/activity+json', 'type' => 'application/activity+json',
'href' => 'https://' . $domain . '/i/actor' 'href' => 'https://'.$domain.'/i/actor',
] ],
] ],
]; ];
return response()->json($res, 200, [], JSON_UNESCAPED_SLASHES); return response()->json($res, 200, [], JSON_UNESCAPED_SLASHES);
} }
$hash = hash('sha256', $resource); $hash = hash('sha256', $resource);
@ -118,7 +104,7 @@ class FederationController extends Controller
public function userOutbox(Request $request, $username) public function userOutbox(Request $request, $username)
{ {
abort_if(!config_cache('federation.activitypub.enabled'), 404); abort_if(! (bool) config_cache('federation.activitypub.enabled'), 404);
if (! $request->wantsJson()) { if (! $request->wantsJson()) {
return redirect('/'.$username); return redirect('/'.$username);
@ -140,7 +126,7 @@ class FederationController extends Controller
public function userInbox(Request $request, $username) public function userInbox(Request $request, $username)
{ {
abort_if(!config_cache('federation.activitypub.enabled'), 404); abort_if(! (bool) config_cache('federation.activitypub.enabled'), 404);
abort_if(! config('federation.activitypub.inbox'), 404); abort_if(! config('federation.activitypub.inbox'), 404);
$headers = $request->headers->all(); $headers = $request->headers->all();
@ -162,6 +148,7 @@ class FederationController extends Controller
if ($obj['object']['type'] === 'Person') { if ($obj['object']['type'] === 'Person') {
if (Profile::whereRemoteUrl($obj['object']['id'])->exists()) { if (Profile::whereRemoteUrl($obj['object']['id'])->exists()) {
dispatch(new DeleteWorker($headers, $payload))->onQueue('inbox'); dispatch(new DeleteWorker($headers, $payload))->onQueue('inbox');
return; return;
} }
} }
@ -169,27 +156,30 @@ class FederationController extends Controller
if ($obj['object']['type'] === 'Tombstone') { if ($obj['object']['type'] === 'Tombstone') {
if (Status::whereObjectUrl($obj['object']['id'])->exists()) { if (Status::whereObjectUrl($obj['object']['id'])->exists()) {
dispatch(new DeleteWorker($headers, $payload))->onQueue('delete'); dispatch(new DeleteWorker($headers, $payload))->onQueue('delete');
return; return;
} }
} }
if ($obj['object']['type'] === 'Story') { if ($obj['object']['type'] === 'Story') {
dispatch(new DeleteWorker($headers, $payload))->onQueue('story'); dispatch(new DeleteWorker($headers, $payload))->onQueue('story');
return; return;
} }
} }
return; return;
} elseif (isset($obj['type']) && in_array($obj['type'], ['Follow', 'Accept'])) { } elseif (isset($obj['type']) && in_array($obj['type'], ['Follow', 'Accept'])) {
dispatch(new InboxValidator($username, $headers, $payload))->onQueue('follow'); dispatch(new InboxValidator($username, $headers, $payload))->onQueue('follow');
} else { } else {
dispatch(new InboxValidator($username, $headers, $payload))->onQueue('high'); dispatch(new InboxValidator($username, $headers, $payload))->onQueue('high');
} }
return;
} }
public function sharedInbox(Request $request) public function sharedInbox(Request $request)
{ {
abort_if(!config_cache('federation.activitypub.enabled'), 404); abort_if(! (bool) config_cache('federation.activitypub.enabled'), 404);
abort_if(! config('federation.activitypub.sharedInbox'), 404); abort_if(! config('federation.activitypub.sharedInbox'), 404);
$headers = $request->headers->all(); $headers = $request->headers->all();
@ -214,6 +204,7 @@ class FederationController extends Controller
if ($obj['object']['type'] === 'Person') { if ($obj['object']['type'] === 'Person') {
if (Profile::whereRemoteUrl($obj['object']['id'])->exists()) { if (Profile::whereRemoteUrl($obj['object']['id'])->exists()) {
dispatch(new DeleteWorker($headers, $payload))->onQueue('inbox'); dispatch(new DeleteWorker($headers, $payload))->onQueue('inbox');
return; return;
} }
} }
@ -221,27 +212,30 @@ class FederationController extends Controller
if ($obj['object']['type'] === 'Tombstone') { if ($obj['object']['type'] === 'Tombstone') {
if (Status::whereObjectUrl($obj['object']['id'])->exists()) { if (Status::whereObjectUrl($obj['object']['id'])->exists()) {
dispatch(new DeleteWorker($headers, $payload))->onQueue('delete'); dispatch(new DeleteWorker($headers, $payload))->onQueue('delete');
return; return;
} }
} }
if ($obj['object']['type'] === 'Story') { if ($obj['object']['type'] === 'Story') {
dispatch(new DeleteWorker($headers, $payload))->onQueue('story'); dispatch(new DeleteWorker($headers, $payload))->onQueue('story');
return; return;
} }
} }
return; return;
} elseif (isset($obj['type']) && in_array($obj['type'], ['Follow', 'Accept'])) { } elseif (isset($obj['type']) && in_array($obj['type'], ['Follow', 'Accept'])) {
dispatch(new InboxWorker($headers, $payload))->onQueue('follow'); dispatch(new InboxWorker($headers, $payload))->onQueue('follow');
} else { } else {
dispatch(new InboxWorker($headers, $payload))->onQueue('shared'); dispatch(new InboxWorker($headers, $payload))->onQueue('shared');
} }
return;
} }
public function userFollowing(Request $request, $username) public function userFollowing(Request $request, $username)
{ {
abort_if(!config_cache('federation.activitypub.enabled'), 404); abort_if(! (bool) config_cache('federation.activitypub.enabled'), 404);
$id = AccountService::usernameToId($username); $id = AccountService::usernameToId($username);
abort_if(! $id, 404); abort_if(! $id, 404);
@ -253,12 +247,13 @@ class FederationController extends Controller
'type' => 'OrderedCollection', 'type' => 'OrderedCollection',
'totalItems' => $account['following_count'] ?? 0, 'totalItems' => $account['following_count'] ?? 0,
]; ];
return response()->json($obj)->header('Content-Type', 'application/activity+json'); return response()->json($obj)->header('Content-Type', 'application/activity+json');
} }
public function userFollowers(Request $request, $username) public function userFollowers(Request $request, $username)
{ {
abort_if(!config_cache('federation.activitypub.enabled'), 404); abort_if(! (bool) config_cache('federation.activitypub.enabled'), 404);
$id = AccountService::usernameToId($username); $id = AccountService::usernameToId($username);
abort_if(! $id, 404); abort_if(! $id, 404);
$account = AccountService::get($id); $account = AccountService::get($id);
@ -269,6 +264,7 @@ class FederationController extends Controller
'type' => 'OrderedCollection', 'type' => 'OrderedCollection',
'totalItems' => $account['followers_count'] ?? 0, 'totalItems' => $account['followers_count'] ?? 0,
]; ];
return response()->json($obj)->header('Content-Type', 'application/activity+json'); return response()->json($obj)->header('Content-Type', 'application/activity+json');
} }
} }

View file

@ -2,27 +2,25 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Auth;
use App\Hashtag; use App\Hashtag;
use App\Place; use App\Place;
use App\Profile; use App\Profile;
use App\Services\WebfingerService;
use App\Status; use App\Status;
use Illuminate\Http\Request;
use App\Util\ActivityPub\Helpers; use App\Util\ActivityPub\Helpers;
use Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Transformer\Api\{
AccountTransformer,
HashtagTransformer,
StatusTransformer,
};
use App\Services\WebfingerService;
class SearchController extends Controller class SearchController extends Controller
{ {
public $tokens = []; public $tokens = [];
public $term = ''; public $term = '';
public $hash = ''; public $hash = '';
public $cacheKey = 'api:search:tag:'; public $cacheKey = 'api:search:tag:';
public function __construct() public function __construct()
@ -36,7 +34,7 @@ class SearchController extends Controller
'q' => 'required|string|min:3|max:120', 'q' => 'required|string|min:3|max:120',
'src' => 'required|string|in:metro', 'src' => 'required|string|in:metro',
'v' => 'required|integer|in:2', 'v' => 'required|integer|in:2',
'scope' => 'required|in:all,hashtag,profile,remote,webfinger' 'scope' => 'required|in:all,hashtag,profile,remote,webfinger',
]); ]);
$scope = $request->input('scope') ?? 'all'; $scope = $request->input('scope') ?? 'all';
@ -84,12 +82,13 @@ class SearchController extends Controller
$hash = hash('sha256', $tag); $hash = hash('sha256', $tag);
if (Helpers::validateUrl($tag) != false && if (Helpers::validateUrl($tag) != false &&
Helpers::validateLocalUrl($tag) != true && Helpers::validateLocalUrl($tag) != true &&
config_cache('federation.activitypub.enabled') == true && (bool) config_cache('federation.activitypub.enabled') == true &&
config('federation.activitypub.remoteFollow') == true config('federation.activitypub.remoteFollow') == true
) { ) {
$remote = Helpers::fetchFromUrl($tag); $remote = Helpers::fetchFromUrl($tag);
if (isset($remote['type']) && if (isset($remote['type']) &&
$remote['type'] == 'Note') { in_array($remote['type'], ['Note', 'Question'])
) {
$item = Helpers::statusFetch($tag); $item = Helpers::statusFetch($tag);
$this->tokens['posts'] = [[ $this->tokens['posts'] = [[
'count' => 0, 'count' => 0,
@ -122,7 +121,7 @@ class SearchController extends Controller
'tokens' => [$item->caption], 'tokens' => [$item->caption],
'name' => $item->caption, 'name' => $item->caption,
'thumb' => $item->thumb(), 'thumb' => $item->thumb(),
'filter' => $item->firstMedia()->filter_class 'filter' => $item->firstMedia()->filter_class,
]; ];
}); });
$this->tokens['posts'] = $posts; $this->tokens['posts'] = $posts;
@ -153,6 +152,7 @@ class SearchController extends Controller
'name' => null, 'name' => null,
]; ];
}); });
return $tags; return $tags;
} }
}); });
@ -180,7 +180,7 @@ class SearchController extends Controller
'tokens' => '', 'tokens' => '',
'name' => null, 'name' => null,
'city' => $item->name, 'city' => $item->name,
'country' => $item->country 'country' => $item->country,
]; ];
}); });
// return $tags; // return $tags;
@ -190,7 +190,7 @@ class SearchController extends Controller
$this->tokens['placesPagination'] = [ $this->tokens['placesPagination'] = [
'total' => $hashtags->total(), 'total' => $hashtags->total(),
'current_page' => $hashtags->currentPage(), 'current_page' => $hashtags->currentPage(),
'last_page' => $hashtags->lastPage() 'last_page' => $hashtags->lastPage(),
]; ];
} }
@ -203,7 +203,7 @@ class SearchController extends Controller
$ttl = now()->addHours(2); $ttl = now()->addHours(2);
if (Helpers::validateUrl($tag) != false && if (Helpers::validateUrl($tag) != false &&
Helpers::validateLocalUrl($tag) != true && Helpers::validateLocalUrl($tag) != true &&
config_cache('federation.activitypub.enabled') == true && (bool) config_cache('federation.activitypub.enabled') == true &&
config('federation.activitypub.remoteFollow') == true config('federation.activitypub.remoteFollow') == true
) { ) {
$remote = Helpers::fetchFromUrl($tag); $remote = Helpers::fetchFromUrl($tag);
@ -225,15 +225,14 @@ class SearchController extends Controller
'follow_request' => $item->hasFollowRequestById(Auth::user()->profile_id), 'follow_request' => $item->hasFollowRequestById(Auth::user()->profile_id),
'thumb' => $item->avatarUrl(), 'thumb' => $item->avatarUrl(),
'local' => (bool) ! $item->domain, 'local' => (bool) ! $item->domain,
'post_count' => $item->statuses()->count() 'post_count' => $item->statuses()->count(),
] ],
]]; ]];
return $tokens; return $tokens;
}); });
} }
} } else {
else {
$this->tokens['profiles'] = Cache::remember($key, $ttl, function () use ($tag) { $this->tokens['profiles'] = Cache::remember($key, $ttl, function () use ($tag) {
if (Str::startsWith($tag, '@')) { if (Str::startsWith($tag, '@')) {
$tag = substr($tag, 1); $tag = substr($tag, 1);
@ -262,8 +261,8 @@ class SearchController extends Controller
'follow_request' => $item->hasFollowRequestById(Auth::user()->profile_id), 'follow_request' => $item->hasFollowRequestById(Auth::user()->profile_id),
'thumb' => $item->avatarUrl(), 'thumb' => $item->avatarUrl(),
'local' => (bool) ! $item->domain, 'local' => (bool) ! $item->domain,
'post_count' => $item->statuses()->count() 'post_count' => $item->statuses()->count(),
] ],
]; ];
}); });
} }
@ -301,11 +300,11 @@ class SearchController extends Controller
'following' => null, 'following' => null,
'follow_request' => null, 'follow_request' => null,
'thumb' => $wfs['avatar'], 'thumb' => $wfs['avatar'],
'local' => (bool) $wfs['local'] 'local' => (bool) $wfs['local'],
] ],
] ],
]; ];
return;
} }
protected function remotePostLookup() protected function remotePostLookup()
@ -333,7 +332,7 @@ class SearchController extends Controller
'username' => $item->profile->username, 'username' => $item->profile->username,
'caption' => $item->rendered ?? $item->caption, 'caption' => $item->rendered ?? $item->caption,
'thumb' => $url, 'thumb' => $url,
'timestamp' => $item->created_at->diffForHumans() 'timestamp' => $item->created_at->diffForHumans(),
]]; ]];
} }
@ -353,7 +352,7 @@ class SearchController extends Controller
'username' => $item->profile->username, 'username' => $item->profile->username,
'caption' => $item->rendered ?? $item->caption, 'caption' => $item->rendered ?? $item->caption,
'thumb' => $url, 'thumb' => $url,
'timestamp' => $item->created_at->diffForHumans() 'timestamp' => $item->created_at->diffForHumans(),
]]; ]];
} }
} }

View file

@ -78,7 +78,7 @@ class StatusController extends Controller
]); ]);
} }
if ($request->wantsJson() && config_cache('federation.activitypub.enabled')) { if ($request->wantsJson() && (bool) config_cache('federation.activitypub.enabled')) {
return $this->showActivityPub($request, $status); return $this->showActivityPub($request, $status);
} }

View file

@ -2,9 +2,15 @@
namespace App\Jobs\SharePipeline; namespace App\Jobs\SharePipeline;
use Cache, Log; use App\Jobs\HomeFeedPipeline\FeedInsertPipeline;
use Illuminate\Support\Facades\Redis; use App\Notification;
use App\{Status, Notification}; use App\Services\ReblogService;
use App\Services\StatusService;
use App\Status;
use App\Transformer\ActivityPub\Verb\Announce;
use App\Util\ActivityPub\HttpSignature;
use GuzzleHttp\Client;
use GuzzleHttp\Pool;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
@ -12,12 +18,6 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use League\Fractal; use League\Fractal;
use League\Fractal\Serializer\ArraySerializer; use League\Fractal\Serializer\ArraySerializer;
use App\Transformer\ActivityPub\Verb\Announce;
use GuzzleHttp\{Pool, Client, Promise};
use App\Util\ActivityPub\HttpSignature;
use App\Services\ReblogService;
use App\Services\StatusService;
use App\Jobs\HomeFeedPipeline\FeedInsertPipeline;
class SharePipeline implements ShouldQueue class SharePipeline implements ShouldQueue
{ {
@ -64,6 +64,7 @@ class SharePipeline implements ShouldQueue
if ($target->id === $status->profile_id) { if ($target->id === $status->profile_id) {
$this->remoteAnnounceDeliver(); $this->remoteAnnounceDeliver();
return true; return true;
} }
@ -90,7 +91,7 @@ class SharePipeline implements ShouldQueue
public function remoteAnnounceDeliver() public function remoteAnnounceDeliver()
{ {
if(config('app.env') !== 'production' || config_cache('federation.activitypub.enabled') == false) { if (config('app.env') !== 'production' || (bool) config_cache('federation.activitypub.enabled') == false) {
return true; return true;
} }
$status = $this->status; $status = $this->status;
@ -111,7 +112,7 @@ class SharePipeline implements ShouldQueue
$payload = json_encode($activity); $payload = json_encode($activity);
$client = new Client([ $client = new Client([
'timeout' => config('federation.activitypub.delivery.timeout') 'timeout' => config('federation.activitypub.delivery.timeout'),
]); ]);
$version = config('pixelfed.version'); $version = config('pixelfed.version');
@ -129,8 +130,8 @@ class SharePipeline implements ShouldQueue
'curl' => [ 'curl' => [
CURLOPT_HTTPHEADER => $headers, CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $payload, CURLOPT_POSTFIELDS => $payload,
CURLOPT_HEADER => true CURLOPT_HEADER => true,
] ],
]); ]);
}; };
} }
@ -141,7 +142,7 @@ class SharePipeline implements ShouldQueue
'fulfilled' => function ($response, $index) { 'fulfilled' => function ($response, $index) {
}, },
'rejected' => function ($reason, $index) { 'rejected' => function ($reason, $index) {
} },
]); ]);
$promise = $pool->promise(); $promise = $pool->promise();

View file

@ -2,9 +2,15 @@
namespace App\Jobs\SharePipeline; namespace App\Jobs\SharePipeline;
use Cache, Log; use App\Jobs\HomeFeedPipeline\FeedRemovePipeline;
use Illuminate\Support\Facades\Redis; use App\Notification;
use App\{Status, Notification}; use App\Services\ReblogService;
use App\Services\StatusService;
use App\Status;
use App\Transformer\ActivityPub\Verb\UndoAnnounce;
use App\Util\ActivityPub\HttpSignature;
use GuzzleHttp\Client;
use GuzzleHttp\Pool;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
@ -12,17 +18,13 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use League\Fractal; use League\Fractal;
use League\Fractal\Serializer\ArraySerializer; use League\Fractal\Serializer\ArraySerializer;
use App\Transformer\ActivityPub\Verb\UndoAnnounce;
use GuzzleHttp\{Pool, Client, Promise};
use App\Util\ActivityPub\HttpSignature;
use App\Services\ReblogService;
use App\Services\StatusService;
use App\Jobs\HomeFeedPipeline\FeedRemovePipeline;
class UndoSharePipeline implements ShouldQueue class UndoSharePipeline implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $status; protected $status;
public $deleteWhenMissingModels = true; public $deleteWhenMissingModels = true;
public function __construct(Status $status) public function __construct(Status $status)
@ -64,7 +66,7 @@ class UndoSharePipeline implements ShouldQueue
return; return;
} }
if(config('app.env') !== 'production' || config_cache('federation.activitypub.enabled') == false) { if (config('app.env') !== 'production' || (bool) config_cache('federation.activitypub.enabled') == false) {
return $status->delete(); return $status->delete();
} else { } else {
return $this->remoteAnnounceDeliver(); return $this->remoteAnnounceDeliver();
@ -73,8 +75,9 @@ class UndoSharePipeline implements ShouldQueue
public function remoteAnnounceDeliver() public function remoteAnnounceDeliver()
{ {
if(config('app.env') !== 'production' || config_cache('federation.activitypub.enabled') == false) { if (config('app.env') !== 'production' || (bool) config_cache('federation.activitypub.enabled') == false) {
$status->delete(); $status->delete();
return 1; return 1;
} }
@ -95,7 +98,7 @@ class UndoSharePipeline implements ShouldQueue
$payload = json_encode($activity); $payload = json_encode($activity);
$client = new Client([ $client = new Client([
'timeout' => config('federation.activitypub.delivery.timeout') 'timeout' => config('federation.activitypub.delivery.timeout'),
]); ]);
$version = config('pixelfed.version'); $version = config('pixelfed.version');
@ -113,8 +116,8 @@ class UndoSharePipeline implements ShouldQueue
'curl' => [ 'curl' => [
CURLOPT_HTTPHEADER => $headers, CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $payload, CURLOPT_POSTFIELDS => $payload,
CURLOPT_HEADER => true CURLOPT_HEADER => true,
] ],
]); ]);
}; };
} }
@ -125,7 +128,7 @@ class UndoSharePipeline implements ShouldQueue
'fulfilled' => function ($response, $index) { 'fulfilled' => function ($response, $index) {
}, },
'rejected' => function ($reason, $index) { 'rejected' => function ($reason, $index) {
} },
]); ]);
$promise = $pool->promise(); $promise = $pool->promise();

View file

@ -2,41 +2,36 @@
namespace App\Jobs\StatusPipeline; namespace App\Jobs\StatusPipeline;
use DB, Cache, Storage; use App\AccountInterstitial;
use App\{ use App\Bookmark;
AccountInterstitial, use App\CollectionItem;
Bookmark, use App\DirectMessage;
CollectionItem, use App\Jobs\MediaPipeline\MediaDeletePipeline;
DirectMessage, use App\Like;
Like, use App\Media;
Media, use App\MediaTag;
MediaTag, use App\Mention;
Mention, use App\Notification;
Notification, use App\Report;
Report, use App\Services\CollectionService;
Status, use App\Services\NotificationService;
StatusArchived, use App\Services\StatusService;
StatusHashtag, use App\Status;
StatusView use App\StatusArchived;
}; use App\StatusHashtag;
use App\StatusView;
use App\Transformer\ActivityPub\Verb\DeleteNote;
use App\Util\ActivityPub\HttpSignature;
use Cache;
use GuzzleHttp\Client;
use GuzzleHttp\Pool;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use League\Fractal; use League\Fractal;
use Illuminate\Support\Str;
use League\Fractal\Serializer\ArraySerializer; use League\Fractal\Serializer\ArraySerializer;
use App\Transformer\ActivityPub\Verb\DeleteNote;
use App\Util\ActivityPub\Helpers;
use GuzzleHttp\Pool;
use GuzzleHttp\Client;
use GuzzleHttp\Promise;
use App\Util\ActivityPub\HttpSignature;
use App\Services\CollectionService;
use App\Services\StatusService;
use App\Services\NotificationService;
use App\Jobs\MediaPipeline\MediaDeletePipeline;
class StatusDelete implements ShouldQueue class StatusDelete implements ShouldQueue
{ {
@ -52,6 +47,7 @@ class StatusDelete implements ShouldQueue
public $deleteWhenMissingModels = true; public $deleteWhenMissingModels = true;
public $timeout = 900; public $timeout = 900;
public $tries = 2; public $tries = 2;
/** /**
@ -84,7 +80,7 @@ class StatusDelete implements ShouldQueue
Cache::forget('pf:atom:user-feed:by-id:'.$status->profile_id); Cache::forget('pf:atom:user-feed:by-id:'.$status->profile_id);
if(config_cache('federation.activitypub.enabled') == true) { if ((bool) config_cache('federation.activitypub.enabled') == true) {
return $this->fanoutDelete($status); return $this->fanoutDelete($status);
} else { } else {
return $this->unlinkRemoveMedia($status); return $this->unlinkRemoveMedia($status);
@ -101,7 +97,7 @@ class StatusDelete implements ShouldQueue
if ($status->in_reply_to_id) { if ($status->in_reply_to_id) {
$parent = Status::findOrFail($status->in_reply_to_id); $parent = Status::findOrFail($status->in_reply_to_id);
--$parent->reply_count; $parent->reply_count--;
$parent->save(); $parent->save();
StatusService::del($parent->id); StatusService::del($parent->id);
} }
@ -184,7 +180,7 @@ class StatusDelete implements ShouldQueue
$payload = json_encode($activity); $payload = json_encode($activity);
$client = new Client([ $client = new Client([
'timeout' => config('federation.activitypub.delivery.timeout') 'timeout' => config('federation.activitypub.delivery.timeout'),
]); ]);
$version = config('pixelfed.version'); $version = config('pixelfed.version');
@ -202,8 +198,8 @@ class StatusDelete implements ShouldQueue
'curl' => [ 'curl' => [
CURLOPT_HTTPHEADER => $headers, CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $payload, CURLOPT_POSTFIELDS => $payload,
CURLOPT_HEADER => true CURLOPT_HEADER => true,
] ],
]); ]);
}; };
} }
@ -214,7 +210,7 @@ class StatusDelete implements ShouldQueue
'fulfilled' => function ($response, $index) { 'fulfilled' => function ($response, $index) {
}, },
'rejected' => function ($reason, $index) { 'rejected' => function ($reason, $index) {
} },
]); ]);
$promise = $pool->promise(); $promise = $pool->promise();

View file

@ -3,12 +3,16 @@
namespace App\Jobs\StatusPipeline; namespace App\Jobs\StatusPipeline;
use App\Hashtag; use App\Hashtag;
use App\Jobs\HomeFeedPipeline\FeedInsertPipeline;
use App\Jobs\MentionPipeline\MentionPipeline; use App\Jobs\MentionPipeline\MentionPipeline;
use App\Mention; use App\Mention;
use App\Profile; use App\Profile;
use App\Services\AdminShadowFilterService;
use App\Services\PublicTimelineService;
use App\Services\StatusService;
use App\Services\UserFilterService;
use App\Status; use App\Status;
use App\StatusHashtag; use App\StatusHashtag;
use App\Services\PublicTimelineService;
use App\Util\Lexer\Autolink; use App\Util\Lexer\Autolink;
use App\Util\Lexer\Extractor; use App\Util\Lexer\Extractor;
use App\Util\Sentiment\Bouncer; use App\Util\Sentiment\Bouncer;
@ -19,18 +23,15 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use App\Services\StatusService;
use App\Services\UserFilterService;
use App\Services\AdminShadowFilterService;
use App\Jobs\HomeFeedPipeline\FeedInsertPipeline;
use App\Jobs\HomeFeedPipeline\HashtagInsertFanoutPipeline;
class StatusEntityLexer implements ShouldQueue class StatusEntityLexer implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $status; protected $status;
protected $entities; protected $entities;
protected $autolink; protected $autolink;
/** /**
@ -110,9 +111,9 @@ class StatusEntityLexer implements ShouldQueue
$slug = str_slug($tag, '-', false); $slug = str_slug($tag, '-', false);
$hashtag = Hashtag::firstOrCreate([ $hashtag = Hashtag::firstOrCreate([
'slug' => $slug 'slug' => $slug,
], [ ], [
'name' => $tag 'name' => $tag,
]); ]);
StatusHashtag::firstOrCreate( StatusHashtag::firstOrCreate(
@ -179,7 +180,7 @@ class StatusEntityLexer implements ShouldQueue
'photo:album', 'photo:album',
'video', 'video',
'video:album', 'video:album',
'photo:video:album' 'photo:video:album',
]; ];
if (config_cache('pixelfed.bouncer.enabled')) { if (config_cache('pixelfed.bouncer.enabled')) {
@ -200,7 +201,7 @@ class StatusEntityLexer implements ShouldQueue
} }
} }
if(config_cache('federation.activitypub.enabled') == true && config('app.env') == 'production') { if ((bool) config_cache('federation.activitypub.enabled') == true && config('app.env') == 'production') {
StatusActivityPubDeliver::dispatch($status); StatusActivityPubDeliver::dispatch($status);
} }
} }

View file

@ -85,7 +85,7 @@ class LandingService
'media_types' => config_cache('pixelfed.media_types'), 'media_types' => config_cache('pixelfed.media_types'),
], ],
'features' => [ 'features' => [
'federation' => config_cache('federation.activitypub.enabled'), 'federation' => (bool) config_cache('federation.activitypub.enabled'),
'timelines' => [ 'timelines' => [
'local' => true, 'local' => true,
'network' => (bool) config_cache('federation.network_timeline'), 'network' => (bool) config_cache('federation.network_timeline'),

View file

@ -2,18 +2,16 @@
namespace App\Util\ActivityPub; namespace App\Util\ActivityPub;
use App\Profile;
use App\Status;
use League\Fractal;
use App\Http\Controllers\ProfileController; use App\Http\Controllers\ProfileController;
use App\Transformer\ActivityPub\ProfileOutbox; use App\Status;
use App\Transformer\ActivityPub\Verb\CreateNote; use App\Transformer\ActivityPub\Verb\CreateNote;
use League\Fractal;
class Outbox { class Outbox
{
public static function get($profile) public static function get($profile)
{ {
abort_if(!config_cache('federation.activitypub.enabled'), 404); abort_if(! (bool) config_cache('federation.activitypub.enabled'), 404);
abort_if(! config('federation.activitypub.outbox'), 404); abort_if(! config('federation.activitypub.outbox'), 404);
if ($profile->status != null) { if ($profile->status != null) {
@ -43,9 +41,9 @@ class Outbox {
'id' => $profile->permalink('/outbox'), 'id' => $profile->permalink('/outbox'),
'type' => 'OrderedCollection', 'type' => 'OrderedCollection',
'totalItems' => $count, 'totalItems' => $count,
'orderedItems' => $res['data'] 'orderedItems' => $res['data'],
]; ];
return $outbox; return $outbox;
} }
} }

View file

@ -298,7 +298,7 @@
<tr> <tr>
<td><span class="badge badge-primary">FEDERATION</span></td> <td><span class="badge badge-primary">FEDERATION</span></td>
<td><strong>ACTIVITY_PUB</strong></td> <td><strong>ACTIVITY_PUB</strong></td>
<td><span>{{config_cache('federation.activitypub.enabled') ? '✅ true' : '❌ false' }}</span></td> <td><span>{{(bool) config_cache('federation.activitypub.enabled') ? '✅ true' : '❌ false' }}</span></td>
</tr> </tr>
<tr> <tr>
<td><span class="badge badge-primary">FEDERATION</span></td> <td><span class="badge badge-primary">FEDERATION</span></td>