From 6bf72b66650252687252af9122fc57a45fb9ceb4 Mon Sep 17 00:00:00 2001 From: Nicolas Hoizey Date: Mon, 16 Jan 2023 09:05:17 +0100 Subject: [PATCH 1/6] Suggested weight optimization for the SVG logo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I ran the logo in [SVGOMG](https://jakearchibald.github.io/svgomg/), a tool for optimizing SVG images, and it saves 54 % of the weight without losing anything visually. I kept the pretty markup, even if minification would have saved a few more bytes. --- public/img/pixelfed-icon-color.svg | 187 ++++++++++++++--------------- 1 file changed, 87 insertions(+), 100 deletions(-) diff --git a/public/img/pixelfed-icon-color.svg b/public/img/pixelfed-icon-color.svg index dfaf03fb..86fe206f 100644 --- a/public/img/pixelfed-icon-color.svg +++ b/public/img/pixelfed-icon-color.svg @@ -1,101 +1,88 @@ - - - - icon/color/svg/pixelfed-icon-color - Created with Sketch. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + + From e3ed684f985d804b3a59d42c445c112ca8c6323b Mon Sep 17 00:00:00 2001 From: Brayd <116094473+br4yd@users.noreply.github.com> Date: Thu, 19 Jan 2023 21:43:57 +0100 Subject: [PATCH 2/6] Minor text change Just a minor text change. The user should be adressed by simply using "you". Otherwise a user could think it's an error that just happened randomly so they retry. By addressing them with "you" it can make this message a bit more clear. --- app/Http/Controllers/BookmarkController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/BookmarkController.php b/app/Http/Controllers/BookmarkController.php index 59ffeab3..f5f59457 100644 --- a/app/Http/Controllers/BookmarkController.php +++ b/app/Http/Controllers/BookmarkController.php @@ -31,7 +31,7 @@ class BookmarkController extends Controller abort_if( $profile->id !== $status->profile_id && !FollowerService::follows($profile->id, $status->profile_id), 404, - 'Error: Cannot bookmark private posts from accounts you do not follow.' + 'Error: You cannot bookmark private posts from accounts you do not follow.' ); } From df1327f41539050ce49eea3524cfe8e4f419c57c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 31 Jan 2023 00:28:53 -0700 Subject: [PATCH 3/6] Optimize logos --- public/img/pixelfed-icon-black.svg | 15 +---- public/img/pixelfed-icon-color.svg | 89 +----------------------------- public/img/pixelfed-icon-grey.svg | 15 +---- public/img/pixelfed-icon-white.svg | 1 + 4 files changed, 4 insertions(+), 116 deletions(-) create mode 100644 public/img/pixelfed-icon-white.svg diff --git a/public/img/pixelfed-icon-black.svg b/public/img/pixelfed-icon-black.svg index 32c7e52f..449c9d34 100644 --- a/public/img/pixelfed-icon-black.svg +++ b/public/img/pixelfed-icon-black.svg @@ -1,14 +1 @@ - - - - icon/black/svg/pixelfed-icon-black - Created with Sketch. - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/public/img/pixelfed-icon-color.svg b/public/img/pixelfed-icon-color.svg index 86fe206f..ee0ba331 100644 --- a/public/img/pixelfed-icon-color.svg +++ b/public/img/pixelfed-icon-color.svg @@ -1,88 +1 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/public/img/pixelfed-icon-grey.svg b/public/img/pixelfed-icon-grey.svg index 0bac224d..c4f8a49b 100644 --- a/public/img/pixelfed-icon-grey.svg +++ b/public/img/pixelfed-icon-grey.svg @@ -1,14 +1 @@ - - - - icon/grey/svg/pixelfed-icon-grey - Created with Sketch. - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/public/img/pixelfed-icon-white.svg b/public/img/pixelfed-icon-white.svg new file mode 100644 index 00000000..f61b9471 --- /dev/null +++ b/public/img/pixelfed-icon-white.svg @@ -0,0 +1 @@ + \ No newline at end of file From 83e1e203cedd7484a7841e3c93e6452dd3ee9840 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 31 Jan 2023 02:27:23 -0700 Subject: [PATCH 4/6] Update SharePipeline, fix share handling and notification generation --- app/Http/Controllers/Api/ApiV1Controller.php | 6 +-- app/Jobs/SharePipeline/SharePipeline.php | 45 ++++++----------- app/Jobs/SharePipeline/UndoSharePipeline.php | 53 +++++++++++--------- app/Notification.php | 2 +- app/Util/ActivityPub/Inbox.php | 27 +++++----- app/Util/ActivityPub/Validator/Announce.php | 7 +-- 6 files changed, 63 insertions(+), 77 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 0c44fd47..cd999318 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -2814,9 +2814,7 @@ class ApiV1Controller extends Controller 'visibility' => 'public' ]); - if($share->wasRecentlyCreated == true) { - SharePipeline::dispatch($share); - } + SharePipeline::dispatch($share)->onQueue('low'); StatusService::del($status->id); ReblogService::add($user->profile_id, $status->id); @@ -2858,7 +2856,7 @@ class ApiV1Controller extends Controller return $this->json($res); } - UndoSharePipeline::dispatch($reblog); + UndoSharePipeline::dispatch($reblog)->onQueue('low'); ReblogService::del($user->profile_id, $status->id); $res = StatusService::getMastodon($status->id); diff --git a/app/Jobs/SharePipeline/SharePipeline.php b/app/Jobs/SharePipeline/SharePipeline.php index cd54b90e..2cc807ac 100644 --- a/app/Jobs/SharePipeline/SharePipeline.php +++ b/app/Jobs/SharePipeline/SharePipeline.php @@ -58,47 +58,32 @@ class SharePipeline implements ShouldQueue return; } - $exists = Notification::whereProfileId($target->id) - ->whereActorId($status->profile_id) - ->whereAction('share') - ->whereItemId($status->reblog_of_id) - ->whereItemType('App\Status') - ->exists(); - if($target->id === $status->profile_id) { $this->remoteAnnounceDeliver(); return true; } - if($exists === true) { - return true; - } - - $this->remoteAnnounceDeliver(); - ReblogService::addPostReblog($parent->id, $status->id); - $parent->reblogs_count = $parent->shares()->count(); + $parent->reblogs_count = $parent->reblogs_count + 1; $parent->save(); StatusService::del($parent->id); - try { - $notification = new Notification; - $notification->profile_id = $target->id; - $notification->actor_id = $actor->id; - $notification->action = 'share'; - $notification->message = $status->shareToText(); - $notification->rendered = $status->shareToHtml(); - $notification->item_id = $status->reblog_of_id ?? $status->id; - $notification->item_type = "App\Status"; - $notification->save(); + Notification::firstOrCreate( + [ + 'profile_id' => $target->id, + 'actor_id' => $actor->id, + 'action' => 'share', + 'item_type' => 'App\Status', + 'item_id' => $status->reblog_of_id ?? $status->id, + ], + [ + 'message' => $status->shareToText(), + 'rendered' => $status->shareToHtml() + ] + ); - $redis = Redis::connection(); - $key = config('cache.prefix').':user.'.$status->profile_id.'.notifications'; - $redis->lpush($key, $notification->id); - } catch (Exception $e) { - Log::error($e); - } + return $this->remoteAnnounceDeliver(); } public function remoteAnnounceDeliver() diff --git a/app/Jobs/SharePipeline/UndoSharePipeline.php b/app/Jobs/SharePipeline/UndoSharePipeline.php index 596d4d2d..d63f909b 100644 --- a/app/Jobs/SharePipeline/UndoSharePipeline.php +++ b/app/Jobs/SharePipeline/UndoSharePipeline.php @@ -33,35 +33,39 @@ class UndoSharePipeline implements ShouldQueue { $status = $this->status; $actor = $status->profile; - $parent = $status->parent(); - $target = $status->parent()->profile; + $parent = Status::find($status->reblog_of_id); - ReblogService::removePostReblog($parent->id, $status->id); + if($parent) { + $target = $parent->profile_id; + ReblogService::removePostReblog($parent->id, $status->id); - if ($status->uri !== null) { + if($parent->reblogs_count > 0) { + $parent->reblogs_count = $parent->reblogs_count - 1; + $parent->save(); + StatusService::del($parent->id); + } + + $notification = Notification::whereProfileId($target) + ->whereActorId($status->profile_id) + ->whereAction('share') + ->whereItemId($status->reblog_of_id) + ->whereItemType('App\Status') + ->first(); + + if($notification) { + $notification->forceDelete(); + } + } + + if ($status->uri != null) { return; } - if($target->domain === null) { - Notification::whereProfileId($target->id) - ->whereActorId($status->profile_id) - ->whereAction('share') - ->whereItemId($status->reblog_of_id) - ->whereItemType('App\Status') - ->delete(); + if(config_cache('federation.activitypub.enabled') == false) { + return $status->delete(); + } else { + return $this->remoteAnnounceDeliver(); } - - $this->remoteAnnounceDeliver(); - - if($parent->reblogs_count > 0) { - $parent->reblogs_count = $parent->reblogs_count - 1; - $parent->save(); - StatusService::del($parent->id); - } - - $status->forceDelete(); - - return 1; } public function remoteAnnounceDeliver() @@ -124,5 +128,8 @@ class UndoSharePipeline implements ShouldQueue $promise->wait(); + $status->delete(); + + return 1; } } diff --git a/app/Notification.php b/app/Notification.php index ebd6f641..b0877978 100644 --- a/app/Notification.php +++ b/app/Notification.php @@ -16,7 +16,7 @@ class Notification extends Model */ protected $dates = ['deleted_at']; - protected $fillable = ['*']; + protected $guarded = []; public function actor() { diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index c8fa9500..6b658643 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -569,13 +569,9 @@ class Inbox return; } - if(Helpers::validateLocalUrl($activity) == false) { - return; - } - $parent = Helpers::statusFetch($activity); - if(empty($parent)) { + if(!$parent || empty($parent)) { return; } @@ -590,15 +586,18 @@ class Inbox 'type' => 'share' ]); - Notification::firstOrCreate([ - 'profile_id' => $parent->profile->id, - 'actor_id' => $actor->id, - 'action' => 'share', - 'message' => $status->replyToText(), - 'rendered' => $status->replyToHtml(), - 'item_id' => $parent->id, - 'item_type' => 'App\Status' - ]); + Notification::firstOrCreate( + [ + 'profile_id' => $parent->profile_id, + 'actor_id' => $actor->id, + 'action' => 'share', + 'item_id' => $parent->id, + 'item_type' => 'App\Status', + ], [ + 'message' => $status->replyToText(), + 'rendered' => $status->replyToHtml(), + ] + ); $parent->reblogs_count = $parent->reblogs_count + 1; $parent->save(); diff --git a/app/Util/ActivityPub/Validator/Announce.php b/app/Util/ActivityPub/Validator/Announce.php index b6f89eec..d862fe9d 100644 --- a/app/Util/ActivityPub/Validator/Announce.php +++ b/app/Util/ActivityPub/Validator/Announce.php @@ -11,18 +11,15 @@ class Announce { { $valid = Validator::make($payload, [ '@context' => 'required', - 'id' => 'required|string', + 'id' => 'required|url', 'type' => [ 'required', Rule::in(['Announce']) ], 'actor' => 'required|url', - 'published' => 'required|date', - 'to' => 'required', - 'cc' => 'required', 'object' => 'required|url' ])->passes(); return $valid; } -} \ No newline at end of file +} From d67fcffb02712090660183af992dc088b28923ec Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 31 Jan 2023 02:29:53 -0700 Subject: [PATCH 5/6] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b2da511..95b4820a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,8 @@ - Update AdminApiController, fix postgres support ([84fb59d0](https://github.com/pixelfed/pixelfed/commit/84fb59d0)) - Update StatusReplyPipeline, fix comment counts ([164aa577](https://github.com/pixelfed/pixelfed/commit/164aa577)) - Update ComposeModal, add Alt Text button to caption screen ([4db48188](https://github.com/pixelfed/pixelfed/commit/4db48188)) +- Update AccountService, fix actor cache invalidation ([498b46f7](https://github.com/pixelfed/pixelfed/commit/498b46f7)) +- Update SharePipeline, fix share handling and notification generation ([83e1e203](https://github.com/pixelfed/pixelfed/commit/83e1e203)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.4 (2022-10-04)](https://github.com/pixelfed/pixelfed/compare/v0.11.3...v0.11.4) From 222dc3a1925fb0d5c12c1cfe64951d5c05d091c0 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 31 Jan 2023 02:33:50 -0700 Subject: [PATCH 6/6] Update test --- tests/Unit/ActivityPub/Verb/AnnounceTest.php | 48 -------------------- 1 file changed, 48 deletions(-) diff --git a/tests/Unit/ActivityPub/Verb/AnnounceTest.php b/tests/Unit/ActivityPub/Verb/AnnounceTest.php index c38fffb3..91a4fdfe 100644 --- a/tests/Unit/ActivityPub/Verb/AnnounceTest.php +++ b/tests/Unit/ActivityPub/Verb/AnnounceTest.php @@ -53,22 +53,6 @@ class AnnounceTest extends TestCase 'object' => 'https://example.org/p/bob/100000000000000', ]; - $this->invalidDate = [ - '@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity', - 'type' => 'Announce', - 'actor' => 'https://example.org/users/alice', - 'published' => '2018-12-31T23:59:59ZEZE', - 'to' => [ - 'https://www.w3.org/ns/activitystreams#Public' - ], - 'cc' => [ - 'https://example.org/users/bob', - 'https://example.org/users/alice/followers' - ], - 'object' => 'https://example.org/p/bob/100000000000000', - ]; - $this->contextMissing = [ 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity', 'type' => 'Announce', @@ -84,25 +68,6 @@ class AnnounceTest extends TestCase 'object' => 'https://example.org/p/bob/100000000000000', ]; - $this->audienceMissing = [ - 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity', - 'type' => 'Announce', - 'actor' => 'https://example.org/users/alice', - 'published' => '2018-12-31T23:59:59Z', - 'object' => 'https://example.org/p/bob/100000000000000', - ]; - - $this->audienceMissing2 = [ - '@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity', - 'type' => 'Announce', - 'actor' => 'https://example.org/users/alice', - 'published' => '2018-12-31T23:59:59Z', - 'to' => null, - 'cc' => null, - 'object' => 'https://example.org/p/bob/100000000000000', - ]; - $this->invalidActor = [ '@context' => 'https://www.w3.org/ns/activitystreams', 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity', @@ -185,25 +150,12 @@ class AnnounceTest extends TestCase $this->assertFalse(Announce::validate($this->invalidAnnounce)); } - /** @test */ - public function invalid_date() - { - $this->assertFalse(Announce::validate($this->invalidDate)); - } - /** @test */ public function context_missing() { $this->assertFalse(Announce::validate($this->contextMissing)); } - /** @test */ - public function audience_missing() - { - $this->assertFalse(Announce::validate($this->audienceMissing)); - $this->assertFalse(Announce::validate($this->audienceMissing2)); - } - /** @test */ public function invalid_actor() {