mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-22 07:42:41 +00:00
Update StatusTagsPipeline, fix object tags and slug normalization
This commit is contained in:
parent
1f0a45b7f4
commit
d295e6059b
2 changed files with 142 additions and 4 deletions
|
@ -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
|
||||
]);
|
||||
}
|
||||
|
|
133
tests/Unit/ActivityPubTagObjectTest.php
Normal file
133
tests/Unit/ActivityPubTagObjectTest.php
Normal file
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ActivityPubTagObjectTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*/
|
||||
public function test_gotosocial(): void
|
||||
{
|
||||
$res = [
|
||||
"tag" => [
|
||||
"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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue