Skip to content

Commit d295e60

Browse files
committed
Update StatusTagsPipeline, fix object tags and slug normalization
1 parent 1f0a45b commit d295e60

File tree

2 files changed

+142
-4
lines changed

2 files changed

+142
-4
lines changed

app/Jobs/StatusPipeline/StatusTagsPipeline.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public function handle()
4545
{
4646
$res = $this->activity;
4747
$status = $this->status;
48+
49+
if(isset($res['tag']['type'], $res['tag']['name'])) {
50+
$res['tag'] = [$res['tag']];
51+
}
52+
4853
$tags = collect($res['tag']);
4954

5055
// Emoji
@@ -73,19 +78,19 @@ public function handle()
7378

7479
if(config('database.default') === 'pgsql') {
7580
$hashtag = Hashtag::where('name', 'ilike', $name)
76-
->orWhere('slug', 'ilike', str_slug($name))
81+
->orWhere('slug', 'ilike', str_slug($name, '-', false))
7782
->first();
7883

7984
if(!$hashtag) {
8085
$hashtag = new Hashtag;
8186
$hashtag->name = $name;
82-
$hashtag->slug = str_slug($name);
87+
$hashtag->slug = str_slug($name, '-', false);
8388
$hashtag->save();
8489
}
8590
} else {
8691
$hashtag = Hashtag::firstOrCreate([
87-
'slug' => str_slug($name)
88-
], [
92+
'slug' => str_slug($name, '-', false),
93+
],[
8994
'name' => $name
9095
]);
9196
}
+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
class ActivityPubTagObjectTest extends TestCase
8+
{
9+
/**
10+
* A basic unit test example.
11+
*/
12+
public function test_gotosocial(): void
13+
{
14+
$res = [
15+
"tag" => [
16+
"href" => "https://gotosocial.example.org/users/GotosocialUser",
17+
"name" => "@GotosocialUser@gotosocial.example.org",
18+
"type" => "Mention"
19+
]
20+
];
21+
22+
if(isset($res['tag']['type'], $res['tag']['name'])) {
23+
$res['tag'] = [$res['tag']];
24+
}
25+
26+
$tags = collect($res['tag'])
27+
->filter(function($tag) {
28+
return $tag &&
29+
$tag['type'] == 'Mention' &&
30+
isset($tag['href']) &&
31+
substr($tag['href'], 0, 8) === 'https://';
32+
});
33+
$this->assertTrue($tags->count() === 1);
34+
}
35+
36+
public function test_pixelfed_hashtags(): void
37+
{
38+
$res = [
39+
"tag" => [
40+
[
41+
"type" => "Mention",
42+
"href" => "https://pixelfed.social/dansup",
43+
"name" => "@dansup@pixelfed.social"
44+
],
45+
[
46+
"type" => "Hashtag",
47+
"href" => "https://pixelfed.social/discover/tags/dogsofpixelfed",
48+
"name" => "#dogsOfPixelFed"
49+
],
50+
[
51+
"type" => "Hashtag",
52+
"href" => "https://pixelfed.social/discover/tags/doggo",
53+
"name" => "#doggo"
54+
],
55+
[
56+
"type" => "Hashtag",
57+
"href" => "https://pixelfed.social/discover/tags/dog",
58+
"name" => "#dog"
59+
],
60+
[
61+
"type" => "Hashtag",
62+
"href" => "https://pixelfed.social/discover/tags/drake",
63+
"name" => "#drake"
64+
],
65+
[
66+
"type" => "Hashtag",
67+
"href" => "https://pixelfed.social/discover/tags/blacklab",
68+
"name" => "#blacklab"
69+
],
70+
[
71+
"type" => "Hashtag",
72+
"href" => "https://pixelfed.social/discover/tags/iconic",
73+
"name" => "#Iconic"
74+
],
75+
[
76+
"type" => "Hashtag",
77+
"href" => "https://pixelfed.social/discover/tags/majestic",
78+
"name" => "#majestic"
79+
]
80+
]
81+
];
82+
83+
if(isset($res['tag']['type'], $res['tag']['name'])) {
84+
$res['tag'] = [$res['tag']];
85+
}
86+
87+
$tags = collect($res['tag'])
88+
->filter(function($tag) {
89+
return $tag &&
90+
$tag['type'] == 'Hashtag' &&
91+
isset($tag['href']) &&
92+
substr($tag['href'], 0, 8) === 'https://';
93+
});
94+
$this->assertTrue($tags->count() === 7);
95+
}
96+
97+
98+
public function test_pixelfed_mentions(): void
99+
{
100+
$res = [
101+
"tag" => [
102+
[
103+
"type" => "Mention",
104+
"href" => "https://pixelfed.social/dansup",
105+
"name" => "@dansup@pixelfed.social"
106+
],
107+
[
108+
"type" => "Hashtag",
109+
"href" => "https://pixelfed.social/discover/tags/dogsofpixelfed",
110+
"name" => "#dogsOfPixelFed"
111+
],
112+
[
113+
"type" => "Hashtag",
114+
"href" => "https://pixelfed.social/discover/tags/doggo",
115+
"name" => "#doggo"
116+
],
117+
]
118+
];
119+
120+
if(isset($res['tag']['type'], $res['tag']['name'])) {
121+
$res['tag'] = [$res['tag']];
122+
}
123+
124+
$tags = collect($res['tag'])
125+
->filter(function($tag) {
126+
return $tag &&
127+
$tag['type'] == 'Mention' &&
128+
isset($tag['href']) &&
129+
substr($tag['href'], 0, 8) === 'https://';
130+
});
131+
$this->assertTrue($tags->count() === 1);
132+
}
133+
}

0 commit comments

Comments
 (0)