Update FollowRequest model

This commit is contained in:
Daniel Supernault 2022-06-03 01:29:50 -06:00
parent 4f99039c15
commit 85fb46668c
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
4 changed files with 37 additions and 7 deletions

View File

@ -6,7 +6,11 @@ use Illuminate\Database\Eloquent\Model;
class FollowRequest extends Model
{
protected $fillable = ['follower_id', 'following_id'];
protected $fillable = ['follower_id', 'following_id', 'activity', 'handled_at'];
protected $casts = [
'activity' => 'array',
];
public function follower()
{
@ -27,4 +31,10 @@ class FollowRequest extends Model
{
return $this->belongsTo(Profile::class, 'following_id', 'id');
}
public function permalink($append = null)
{
$path = $this->target->permalink("#accepts/follows/{$this->id}{$append}");
return url($path);
}
}

View File

@ -63,11 +63,6 @@ class FollowPipeline implements ShouldQueue
$notification->item_id = $target->id;
$notification->item_type = "App\Profile";
$notification->save();
$redis = Redis::connection();
$nkey = config('cache.prefix').':user.'.$target->id.'.notifications';
$redis->lpush($nkey, $notification->id);
} catch (Exception $e) {
Log::error($e);
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Transformer\ActivityPub\Verb;
use App\FollowRequest;
use League\Fractal;
class AcceptFollow extends Fractal\TransformerAbstract
{
public function transform(FollowRequest $follow)
{
return [
'@context' => 'https://www.w3.org/ns/activitystreams',
'type' => 'Accept',
'id' => $follow->permalink(),
'actor' => $follow->target->permalink(),
'object' => [
'type' => 'Follow',
'id' => $follow->activity ? $follow->activity['id'] : null,
'actor' => $follow->actor->permalink(),
'object' => $follow->target->permalink()
]
];
}
}

View File

@ -477,7 +477,7 @@ class Inbox
'follower_id' => $actor->id,
'following_id' => $target->id,
],[
'activity' => collect($this->payload)->only(['id','actor','object'])->toArray()
'activity' => collect($this->payload)->only(['id','actor','object','type'])->toArray()
]);
} else {
$follower = new Follower;