pixelfed/app/DirectMessage.php

51 lines
1 KiB
PHP
Raw Normal View History

2018-10-17 18:21:39 +00:00
<?php
namespace App;
use Auth;
use Illuminate\Database\Eloquent\Model;
class DirectMessage extends Model
{
public function status()
{
return $this->hasOne(Status::class, 'id', 'status_id');
}
public function url()
{
2020-11-18 21:19:02 +00:00
return config('app.url') . '/account/direct/m/' . $this->status_id;
2018-10-17 18:21:39 +00:00
}
public function author()
{
return $this->hasOne(Profile::class, 'id', 'from_id');
}
2020-11-18 21:19:02 +00:00
public function recipient()
{
return $this->hasOne(Profile::class, 'id', 'to_id');
}
2018-10-17 18:21:39 +00:00
public function me()
{
return Auth::user()->profile->id === $this->from_id;
}
2020-11-18 21:19:02 +00:00
public function toText()
{
$actorName = $this->author->username;
return "{$actorName} sent a direct message.";
}
public function toHtml()
{
$actorName = $this->author->username;
$actorUrl = $this->author->url();
$url = $this->url();
return "<a href='{$actorUrl}' class='profile-link'>{$actorName}</a> sent a <a href='{$url}' class='dm-link'>direct message</a>.";
}
2018-10-17 18:21:39 +00:00
}