You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pixelfed/app/Models/AccountInterstitial.php

78 lines
2.2 KiB
PHTML

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
5 days ago
* @property-read Status|null $status
* @property-read int $count aggregate/computed alias
* @property-read string $month_year aggregate/computed alias
*/
class AccountInterstitial extends Model
{
9 months ago
public const JSON_MESSAGE = 'Please use web browser to proceed.';
7 months ago
protected function casts(): array
{
return [
'read_at' => 'datetime',
'appeal_requested_at' => 'datetime',
];
}
public function user(): BelongsTo
9 months ago
{
return $this->belongsTo(User::class);
}
9 months ago
public function status()
{
if ($this->item_type != Status::class) {
9 months ago
return;
}
return $this->hasOne(Status::class, 'id', 'item_id');
}
/**
* Create an AccountInterstitial for a moderated status.
*
* @param Status $status The status being moderated
* @param string $type The interstitial type (e.g. 'post.cw', 'post.unlist', 'post.removed', 'post.autospam')
* @param string $view The blade view for the interstitial
*/
public static function createFromStatus(Status $status, string $type, string $view): self
{
$media = $status->media;
$ai = new self;
$ai->user_id = $status->profile->user_id;
$ai->type = $type;
$ai->view = $view;
$ai->item_type = Status::class;
$ai->item_id = $status->id;
$ai->has_media = (bool) $media->count();
$ai->blurhash = $media->count() ? $media->first()->blurhash : null;
$ai->meta = json_encode([
'caption' => $status->caption,
'created_at' => $status->created_at,
'type' => $status->type,
'url' => $status->url(),
'is_nsfw' => $status->is_nsfw,
'scope' => $status->scope,
'reblog' => $status->reblog_of_id,
'likes_count' => $status->likes_count,
'reblogs_count' => $status->reblogs_count,
]);
$ai->save();
$u = $status->profile->user;
$u->has_interstitial = true;
$u->save();
return $ai;
}
}