forked from mirror/pixelfed
Update Status model
This commit is contained in:
parent
89b1712603
commit
5695cfaab5
1 changed files with 67 additions and 0 deletions
|
@ -218,4 +218,71 @@ class Status extends Model
|
|||
{
|
||||
return $this->comments()->orderBy('created_at', 'desc')->take(3);
|
||||
}
|
||||
|
||||
public function toActivityPubObject()
|
||||
{
|
||||
if($this->local == false) {
|
||||
return;
|
||||
}
|
||||
$profile = $this->profile;
|
||||
$to = $this->scopeToAudience('to');
|
||||
$cc = $this->scopeToAudience('cc');
|
||||
return [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => $this->permalink(),
|
||||
'type' => 'Create',
|
||||
'actor' => $profile->permalink(),
|
||||
'published' => $this->created_at->format('c'),
|
||||
'to' => $to,
|
||||
'cc' => $cc,
|
||||
'object' => [
|
||||
'id' => $this->url(),
|
||||
'type' => 'Note',
|
||||
'summary' => null,
|
||||
'inReplyTo' => null,
|
||||
'published' => $this->created_at->format('c'),
|
||||
'url' => $this->url(),
|
||||
'attributedTo' => $this->profile->url(),
|
||||
'to' => $to,
|
||||
'cc' => $cc,
|
||||
'sensitive' => (bool) $this->is_nsfw,
|
||||
'content' => $this->rendered,
|
||||
'attachment' => $this->media->map(function($media) {
|
||||
return [
|
||||
'type' => 'Document',
|
||||
'mediaType' => $media->mime,
|
||||
'url' => $media->url(),
|
||||
'name' => null
|
||||
];
|
||||
})
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function scopeToAudience($audience)
|
||||
{
|
||||
if(!in_array($audience, ['to', 'cc']) || $this->local == false) {
|
||||
return;
|
||||
}
|
||||
$res = [];
|
||||
$res['to'] = [];
|
||||
$res['cc'] = [];
|
||||
$scope = $this->scope;
|
||||
switch ($scope) {
|
||||
case 'public':
|
||||
$res['to'] = [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
];
|
||||
$res['cc'] = [
|
||||
$this->profile->permalink('/followers')
|
||||
];
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
return $res[$audience];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue