From d295e6059b60c93fcb2bbc9a1f1a5e4408cb8d1c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 25 Sep 2023 04:23:04 -0600 Subject: [PATCH 1/2] Update StatusTagsPipeline, fix object tags and slug normalization --- .../StatusPipeline/StatusTagsPipeline.php | 13 +- tests/Unit/ActivityPubTagObjectTest.php | 133 ++++++++++++++++++ 2 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 tests/Unit/ActivityPubTagObjectTest.php diff --git a/app/Jobs/StatusPipeline/StatusTagsPipeline.php b/app/Jobs/StatusPipeline/StatusTagsPipeline.php index a72e6d50e..6282370f8 100644 --- a/app/Jobs/StatusPipeline/StatusTagsPipeline.php +++ b/app/Jobs/StatusPipeline/StatusTagsPipeline.php @@ -45,6 +45,11 @@ class StatusTagsPipeline implements ShouldQueue { $res = $this->activity; $status = $this->status; + + if(isset($res['tag']['type'], $res['tag']['name'])) { + $res['tag'] = [$res['tag']]; + } + $tags = collect($res['tag']); // Emoji @@ -73,19 +78,19 @@ class StatusTagsPipeline implements ShouldQueue if(config('database.default') === 'pgsql') { $hashtag = Hashtag::where('name', 'ilike', $name) - ->orWhere('slug', 'ilike', str_slug($name)) + ->orWhere('slug', 'ilike', str_slug($name, '-', false)) ->first(); if(!$hashtag) { $hashtag = new Hashtag; $hashtag->name = $name; - $hashtag->slug = str_slug($name); + $hashtag->slug = str_slug($name, '-', false); $hashtag->save(); } } else { $hashtag = Hashtag::firstOrCreate([ - 'slug' => str_slug($name) - ], [ + 'slug' => str_slug($name, '-', false), + ],[ 'name' => $name ]); } diff --git a/tests/Unit/ActivityPubTagObjectTest.php b/tests/Unit/ActivityPubTagObjectTest.php new file mode 100644 index 000000000..f402ff0da --- /dev/null +++ b/tests/Unit/ActivityPubTagObjectTest.php @@ -0,0 +1,133 @@ + [ + "href" => "https://gotosocial.example.org/users/GotosocialUser", + "name" => "@GotosocialUser@gotosocial.example.org", + "type" => "Mention" + ] + ]; + + if(isset($res['tag']['type'], $res['tag']['name'])) { + $res['tag'] = [$res['tag']]; + } + + $tags = collect($res['tag']) + ->filter(function($tag) { + return $tag && + $tag['type'] == 'Mention' && + isset($tag['href']) && + substr($tag['href'], 0, 8) === 'https://'; + }); + $this->assertTrue($tags->count() === 1); + } + + public function test_pixelfed_hashtags(): void + { + $res = [ + "tag" => [ + [ + "type" => "Mention", + "href" => "https://pixelfed.social/dansup", + "name" => "@dansup@pixelfed.social" + ], + [ + "type" => "Hashtag", + "href" => "https://pixelfed.social/discover/tags/dogsofpixelfed", + "name" => "#dogsOfPixelFed" + ], + [ + "type" => "Hashtag", + "href" => "https://pixelfed.social/discover/tags/doggo", + "name" => "#doggo" + ], + [ + "type" => "Hashtag", + "href" => "https://pixelfed.social/discover/tags/dog", + "name" => "#dog" + ], + [ + "type" => "Hashtag", + "href" => "https://pixelfed.social/discover/tags/drake", + "name" => "#drake" + ], + [ + "type" => "Hashtag", + "href" => "https://pixelfed.social/discover/tags/blacklab", + "name" => "#blacklab" + ], + [ + "type" => "Hashtag", + "href" => "https://pixelfed.social/discover/tags/iconic", + "name" => "#Iconic" + ], + [ + "type" => "Hashtag", + "href" => "https://pixelfed.social/discover/tags/majestic", + "name" => "#majestic" + ] + ] + ]; + + if(isset($res['tag']['type'], $res['tag']['name'])) { + $res['tag'] = [$res['tag']]; + } + + $tags = collect($res['tag']) + ->filter(function($tag) { + return $tag && + $tag['type'] == 'Hashtag' && + isset($tag['href']) && + substr($tag['href'], 0, 8) === 'https://'; + }); + $this->assertTrue($tags->count() === 7); + } + + + public function test_pixelfed_mentions(): void + { + $res = [ + "tag" => [ + [ + "type" => "Mention", + "href" => "https://pixelfed.social/dansup", + "name" => "@dansup@pixelfed.social" + ], + [ + "type" => "Hashtag", + "href" => "https://pixelfed.social/discover/tags/dogsofpixelfed", + "name" => "#dogsOfPixelFed" + ], + [ + "type" => "Hashtag", + "href" => "https://pixelfed.social/discover/tags/doggo", + "name" => "#doggo" + ], + ] + ]; + + if(isset($res['tag']['type'], $res['tag']['name'])) { + $res['tag'] = [$res['tag']]; + } + + $tags = collect($res['tag']) + ->filter(function($tag) { + return $tag && + $tag['type'] == 'Mention' && + isset($tag['href']) && + substr($tag['href'], 0, 8) === 'https://'; + }); + $this->assertTrue($tags->count() === 1); + } +} From bf5b72f0829abffae8a8db202887884a08418a9d Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 25 Sep 2023 04:23:28 -0600 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36092276a..97d07ba2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,9 @@ - Update StatusService, hydrate accounts on request instead of caching them along with status objects ([223661ec](https://github.com/pixelfed/pixelfed/commit/223661ec)) - Update profile embed, fix resize ([dc23c21d](https://github.com/pixelfed/pixelfed/commit/dc23c21d)) - Update Status model, improve thumb logic ([d969a973](https://github.com/pixelfed/pixelfed/commit/d969a973)) +- Update Status model, allow unlisted thumbnails ([1f0a45b7](https://github.com/pixelfed/pixelfed/commit/1f0a45b7)) +- Update StatusTagsPipeline, fix object tags and slug normalization ([d295e605](https://github.com/pixelfed/pixelfed/commit/d295e605)) +- ([](https://github.com/pixelfed/pixelfed/commit/)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.9 (2023-08-21)](https://github.com/pixelfed/pixelfed/compare/v0.11.8...v0.11.9)