pixelfed/app/Jobs/MentionPipeline/MentionPipeline.php

76 wiersze
1.9 KiB
PHP
Czysty Zwykły widok Historia

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;
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)
->whereAction('mention')
->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;
}
try {
2018-08-28 03:07:36 +00:00
$notification = new Notification();
2018-06-09 03:32:46 +00:00
$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) {
}
}
}