瀏覽代碼

Update FollowRequest model

Daniel Supernault 3 年之前
父節點
當前提交
85fb46668c

+ 11 - 1
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);
+    }
 }

+ 0 - 5
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);
 		}

+ 25 - 0
app/Transformer/ActivityPub/Verb/AcceptFollow.php

@@ -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()
+			]
+		];
+	}
+}

+ 1 - 1
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;