pixelfed/app/Jobs/MentionPipeline/MentionPipeline.php

80 lines
1.9 KiB
PHP
Raw Normal View History

2018-06-09 03:32:46 +00:00
<?php
namespace App\Jobs\MentionPipeline;
2018-08-28 03:07:36 +00:00
use App\Mention;
use App\Notification;
use App\Status;
2018-06-09 03:32:46 +00:00
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
2018-08-28 03:07:36 +00:00
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Services\StatusService;
2018-06-09 03:32:46 +00:00
class MentionPipeline implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $status;
protected $mention;
2019-01-12 22:17:28 +00:00
/**
* Delete the job if its models no longer exist.
*
* @var bool
*/
public $deleteWhenMissingModels = true;
2018-06-09 03:32:46 +00:00
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Status $status, Mention $mention)
{
$this->status = $status;
$this->mention = $mention;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$status = $this->status;
$mention = $this->mention;
$actor = $this->status->profile;
$target = $this->mention->profile_id;
$exists = Notification::whereProfileId($target)
->whereActorId($actor->id)
->whereIn('action', ['mention', 'comment'])
2018-06-09 03:32:46 +00:00
->whereItemId($status->id)
->whereItemType('App\Status')
->count();
2018-08-28 03:07:36 +00:00
if ($actor->id === $target || $exists !== 0) {
2018-06-09 03:32:46 +00:00
return true;
}
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);
2018-06-09 03:32:46 +00:00
}
}