Skip to content

Commit

Permalink
Update MentionPipeline, store non-local mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Jan 31, 2023
1 parent 4be9d0f commit 1714923
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
28 changes: 16 additions & 12 deletions app/Jobs/MentionPipeline/MentionPipeline.php
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Services\StatusService;

class MentionPipeline implements ShouldQueue
{
Expand Down Expand Up @@ -59,17 +60,20 @@ public function handle()
return true;
}

try {
$notification = new Notification();
$notification->profile_id = $target;
$notification->actor_id = $actor->id;
$notification->action = 'mention';
$notification->message = $mention->toText();
$notification->rendered = $mention->toHtml();
$notification->item_id = $status->id;
$notification->item_type = "App\Status";
$notification->save();
} catch (Exception $e) {
}
Notification::firstOrCreate(
[
'profile_id' => $target,
'actor_id' => $actor->id,
'action' => 'mention',
'item_type' => 'App\Status',
'item_id' => $status->id,
],
[
'message' => $mention->toText(),
'rendered' => $mention->toHtml()
]
);

StatusService::del($status->id);
}
}
28 changes: 18 additions & 10 deletions app/Jobs/StatusPipeline/StatusTagsPipeline.php
Expand Up @@ -8,14 +8,15 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Services\AccountService;
use App\Services\CustomEmojiService;
use App\Services\StatusService;
use App\Jobs\MentionPipeline\MentionPipeline;
use App\Mention;
use App\Services\AccountService;
use App\Hashtag;
use App\StatusHashtag;
use App\Services\TrendingHashtagService;
use App\Util\ActivityPub\Helpers;

class StatusTagsPipeline implements ShouldQueue
{
Expand Down Expand Up @@ -89,17 +90,24 @@ public function handle()
return $tag &&
$tag['type'] == 'Mention' &&
isset($tag['href']) &&
substr($tag['href'], 0, 8) === 'https://' &&
parse_url($tag['href'], PHP_URL_HOST) == config('pixelfed.domain.app');
substr($tag['href'], 0, 8) === 'https://';
})
->map(function($tag) use($status) {
$parts = explode('/', $status['href']);
if(!$parts) {
return;
}
$pid = AccountService::usernameToId(end($parts));
if(!$pid) {
return;
if(Helpers::validateLocalUrl($tag['href'])) {
$parts = explode('/', $tag['href']);
if(!$parts) {
return;
}
$pid = AccountService::usernameToId(end($parts));
if(!$pid) {
return;
}
} else {
$acct = Helpers::profileFetch($tag['href']);
if(!$acct) {
return;
}
$pid = $acct->id;
}
$mention = new Mention;
$mention->status_id = $status->id;
Expand Down

0 comments on commit 1714923

Please sign in to comment.