From 85fb46668c421d8c27c4fcbf1a84b26a5c90450a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 3 Jun 2022 01:29:50 -0600 Subject: [PATCH] Update FollowRequest model --- app/FollowRequest.php | 12 ++++++++- app/Jobs/FollowPipeline/FollowPipeline.php | 5 ---- .../ActivityPub/Verb/AcceptFollow.php | 25 +++++++++++++++++++ app/Util/ActivityPub/Inbox.php | 2 +- 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 app/Transformer/ActivityPub/Verb/AcceptFollow.php diff --git a/app/FollowRequest.php b/app/FollowRequest.php index 89bd26e9a..7852e2688 100644 --- a/app/FollowRequest.php +++ b/app/FollowRequest.php @@ -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); + } } diff --git a/app/Jobs/FollowPipeline/FollowPipeline.php b/app/Jobs/FollowPipeline/FollowPipeline.php index 986f22425..f2bab5a96 100644 --- a/app/Jobs/FollowPipeline/FollowPipeline.php +++ b/app/Jobs/FollowPipeline/FollowPipeline.php @@ -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); } diff --git a/app/Transformer/ActivityPub/Verb/AcceptFollow.php b/app/Transformer/ActivityPub/Verb/AcceptFollow.php new file mode 100644 index 000000000..cb5b54a41 --- /dev/null +++ b/app/Transformer/ActivityPub/Verb/AcceptFollow.php @@ -0,0 +1,25 @@ + '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() + ] + ]; + } +} diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index a874a39fe..2d48cb97f 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -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;