diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b40e432..e89cbf10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,8 @@ - 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)) +- 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) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 70ae2f40..d7699943 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1026,33 +1026,45 @@ 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); } } + 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 + '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); } /** 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; }