From cf286fb046efd2b80a6650a32bf55f6f37aec4de Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Feb 2022 23:01:50 -0700 Subject: [PATCH 1/5] Update Inbox, fix undo announce --- app/Util/ActivityPub/Inbox.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index 31b6e89f..68940c50 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -114,6 +114,10 @@ class Inbox $this->handleStoryReplyActivity(); break; + // case 'Update': + // (new UpdateActivity($this->payload, $this->profile))->handle(); + // break; + default: // TODO: decide how to handle invalid verbs. break; @@ -688,11 +692,13 @@ class Inbox break; case 'Announce': - $obj = $obj['object']; - if(!Helpers::validateLocalUrl($obj)) { + if(is_array($obj) && isset($obj['object'])) { + $obj = $obj['object']; + } + if(!is_string($obj) || !Helpers::validateLocalUrl($obj)) { return; } - $status = Helpers::statusFetch($obj); + $status = Status::whereUri($obj)->exists(); if(!$status) { return; } From 0a8b9f61f5074754a061966930b44e44e947be11 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Feb 2022 23:02:37 -0700 Subject: [PATCH 2/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b40e432..b8992daf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ - Updated filesystems config, set S3 visibility to public by default. Fixes #2913. ([49a53c27](https://github.com/pixelfed/pixelfed/commit/49a53c27)) - Updated CommentPipeline, improve parent reply_count calculation. ([ccc94802](https://github.com/pixelfed/pixelfed/commit/ccc94802)) - Updated StatusTagsPipeline, process federated hashtags and mentions ([a84b1736](https://github.com/pixelfed/pixelfed/commit/a84b1736)) +- Updated Inbox, fix undo announce. ([cf286fb0](https://github.com/pixelfed/pixelfed/commit/cf286fb0)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.2 (2022-01-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.1...v0.11.2) From 151dc17c25aa30a56940585120b7c95b987967ea Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 13 Feb 2022 00:23:29 -0700 Subject: [PATCH 3/5] Update ApiV1Controller, improve favourites endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 31 ++++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 70ae2f40..6b393549 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1026,33 +1026,38 @@ class ApiV1Controller extends Controller $user = $request->user(); - $status = Status::findOrFail($id); + $status = StatusService::getMastodon($id, false); - if($status->profile_id !== $user->profile_id) { - if($status->scope == 'private') { - abort_if(!$status->profile->followedBy($user->profile), 403); + abort_unless($status, 400); + + $spid = $status['account']['id']; + + if($spid !== $user->profile_id) { + if($status['visibility'] == 'private') { + abort_if(!FollowerService::follows($user->profile_id, $spid), 403); } else { - abort_if(!in_array($status->scope, ['public','unlisted']), 403); + abort_if(!in_array($status['visibility'], ['public','unlisted']), 403); } } $like = Like::firstOrCreate([ 'profile_id' => $user->profile_id, - 'status_id' => $status->id + 'status_id' => $status['id'] ]); if($like->wasRecentlyCreated == true) { - $like->status_profile_id = $status->profile_id; - $like->is_comment = !empty($status->in_reply_to_id); + $like->status_profile_id = $spid; + $like->is_comment = !empty($status['in_reply_to_id']); $like->save(); - $status->likes_count = $status->likes()->count(); - $status->save(); + Status::findOrFail($status['id'])->update([ + 'favourites_count' => ($status['favourites_count'] ?? 0) + 1 + ]); LikePipeline::dispatch($like); } - $res = StatusService::getMastodon($status->id, false); - $res['favourited'] = true; - return response()->json($res); + $status['favourited'] = true; + $status['favourites_count'] = $status['favourites_count'] + 1; + return response()->json($status); } /** From 156940c3997e797bc3b3cd96c30d75936898ee63 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 13 Feb 2022 00:24:42 -0700 Subject: [PATCH 4/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8992daf..e89cbf10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ - Updated CommentPipeline, improve parent reply_count calculation. ([ccc94802](https://github.com/pixelfed/pixelfed/commit/ccc94802)) - Updated StatusTagsPipeline, process federated hashtags and mentions ([a84b1736](https://github.com/pixelfed/pixelfed/commit/a84b1736)) - Updated Inbox, fix undo announce. ([cf286fb0](https://github.com/pixelfed/pixelfed/commit/cf286fb0)) +- Updated ApiV1Controller, improve favourites endpoint. ([151dc17c](https://github.com/pixelfed/pixelfed/commit/151dc17c)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.2 (2022-01-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.1...v0.11.2) From 2848620a32fa9f59af67cca79a6703cd2e37fc8d Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 13 Feb 2022 00:32:25 -0700 Subject: [PATCH 5/5] Update ApiV1Controller, improve favourites endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 6b393549..d7699943 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1040,6 +1040,13 @@ class ApiV1Controller extends Controller } } + abort_if( + Like::whereProfileId($user->profile_id) + ->where('created_at', '>', now()->subDay()) + ->count() >= 100, + 429 + ); + $like = Like::firstOrCreate([ 'profile_id' => $user->profile_id, 'status_id' => $status['id']