created the follows model
This commit is contained in:
parent
cd3cde3423
commit
4cd0dc96df
@ -5,6 +5,7 @@ namespace App\Http\Controllers\AP;
|
||||
use App\Models\User;
|
||||
use App\Models\Actor;
|
||||
use App\Models\Activity;
|
||||
use App\Models\Follow;
|
||||
|
||||
use App\Types\TypeActor;
|
||||
use App\Types\TypeActivity;
|
||||
@ -50,6 +51,12 @@ class APInboxController extends Controller
|
||||
// there's no follows model, it'll be handled with the activity model
|
||||
$act = Activity::create ($activity);
|
||||
|
||||
$follow = Follow::create ([
|
||||
"activity_id" => $act->id,
|
||||
"actor" => $actor->id,
|
||||
"object" => $target->id,
|
||||
]);
|
||||
|
||||
// TODO: Users should be able to manually check this
|
||||
$accept_activity = TypeActivity::craft_accept ($act);
|
||||
$response = TypeActivity::post_activity ($accept_activity, $target, $actor);
|
||||
|
@ -3,19 +3,21 @@
|
||||
namespace App\Http\Controllers\AP;
|
||||
|
||||
use App\Models\Note;
|
||||
use App\Models\NoteAttachment;
|
||||
use App\Models\User;
|
||||
use App\Models\Actor;
|
||||
use App\Types\TypeNote;
|
||||
use App\Models\Activity;
|
||||
use App\Models\Instance;
|
||||
use App\Models\Follow;
|
||||
|
||||
use App\Types\TypeActor;
|
||||
use App\Types\TypeActivity;
|
||||
|
||||
use App\Types\TypeNote;
|
||||
use App\Actions\ActionsPost;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Models\NoteAttachment;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@ -152,6 +154,12 @@ class APOutboxController extends Controller
|
||||
$follow_activity = TypeActivity::craft_follow ($user->actor ()->first (), $object_actor);
|
||||
$response = TypeActivity::post_activity ($follow_activity, $user->actor ()->first (), $object_actor);
|
||||
|
||||
$follow = Follow::create ([
|
||||
"activity_id" => $follow_activity->id,
|
||||
"actor" => $user->actor ()->first ()->id,
|
||||
"object" => $object_actor->id,
|
||||
]);
|
||||
|
||||
if ($response->getStatusCode () < 200 || $response->getStatusCode () >= 300)
|
||||
return response ()->json ([ "error" => "failed to post activity" ], 500);
|
||||
|
||||
|
14
app/Models/Follow.php
Normal file
14
app/Models/Follow.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Follow extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
"activity_id",
|
||||
"actor",
|
||||
"object"
|
||||
];
|
||||
}
|
@ -75,44 +75,51 @@ class User extends Authenticatable
|
||||
|
||||
public function mutual_friends ()
|
||||
{
|
||||
$followers = Activity::where ("type", "Follow")->where ("object", '"' . $this->actor->actor_id . '"')->pluck ("actor")->toArray ();
|
||||
$following = Activity::where ("type", "Follow")->where ("actor", $this->actor->actor_id)->pluck ("object")->toArray ();
|
||||
$followers = Follow::where ("actor", $this->actor->id)->pluck ("object")->toArray ();
|
||||
$following = Follow::where ("object", $this->actor->id)->pluck ("actor")->toArray ();
|
||||
|
||||
return array_intersect ($followers, $following);
|
||||
$mutuals = array_intersect ($followers, $following);
|
||||
$actors = [];
|
||||
|
||||
foreach ($mutuals as $id)
|
||||
{
|
||||
$actors[] = Actor::where ("id", $id)->first ()->actor_id;
|
||||
}
|
||||
|
||||
return $actors;
|
||||
}
|
||||
|
||||
public function received_requests ()
|
||||
{
|
||||
// users following me, where I am the object and I retrieve the actors
|
||||
$following = Activity::where ("type", "Follow")
|
||||
->where ("object", '"' . $this->actor->actor_id . '"') // i am the object being followed
|
||||
->pluck ("actor")
|
||||
->map (fn ($actor) => json_encode ($actor, JSON_UNESCAPED_SLASHES))
|
||||
->toArray ();
|
||||
// users following me, that I am not following them
|
||||
$followers = Follow::where ("object", $this->actor->id)->pluck ("actor")->toArray ();
|
||||
$following = Follow::where ("actor", $this->actor->id)->pluck ("object")->toArray ();
|
||||
|
||||
// users i am following, where I am the actor and I retrieve the objects
|
||||
$followers = Activity::where ("type", "Follow")
|
||||
->whereIn ("object", $following) // actors
|
||||
->where ("actor", $this->actor->actor_id) // following me
|
||||
->pluck ("actor")->toArray ();
|
||||
$diff = array_diff ($followers, $following);
|
||||
|
||||
return array_diff ($following, $followers);
|
||||
$actors = [];
|
||||
foreach ($diff as $id)
|
||||
{
|
||||
$actors[] = Actor::where ("id", $id)->first ()->actor_id;
|
||||
}
|
||||
return $actors;
|
||||
}
|
||||
|
||||
public function sent_requests ()
|
||||
{
|
||||
// users i am following, where I am the actor and I retrieve the objects
|
||||
$followers = Activity::where ("type", "Follow")
|
||||
->where ("actor", $this->actor->actor_id) // actors I follow
|
||||
->pluck ("object")->toArray ();
|
||||
// users i am following
|
||||
$followers = Follow::where ("actor", $this->actor->id)->pluck ("object")->toArray ();
|
||||
$following = Follow::where ("object", $this->actor->id)->pluck ("actor")->toArray ();
|
||||
|
||||
// users following me, where I am the object and I retrieve the actors
|
||||
$following = Activity::where ("type", "Follow")
|
||||
->whereIn ("actor", $followers) // actors
|
||||
->where ("object", '"' . $this->actor->actor_id . '"') // that following me
|
||||
->pluck ("actor")->toArray ();
|
||||
$diff = array_diff ($followers, $following);
|
||||
|
||||
return array_diff ($followers, $following);
|
||||
$actors = [];
|
||||
foreach ($diff as $id)
|
||||
{
|
||||
$actors[] = Actor::where ("id", $id)->first ()->actor_id;
|
||||
}
|
||||
|
||||
return $actors;
|
||||
}
|
||||
|
||||
public function feed ()
|
||||
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('follows', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->foreignId ("activity_id")->constrained()->onDelete("cascade");
|
||||
$table->foreignId ("actor")->constrained("actors")->onDelete("cascade");
|
||||
$table->foreignId ("object")->constrained("actors")->onDelete("cascade");
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('follows');
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user