diff --git a/app/Events/AP/ActivityFollowEvent.php b/app/Events/AP/ActivityFollowEvent.php new file mode 100644 index 0000000..4e792c3 --- /dev/null +++ b/app/Events/AP/ActivityFollowEvent.php @@ -0,0 +1,26 @@ +activity = $activity; + } +} diff --git a/app/Events/AP/ActivityLikeEvent.php b/app/Events/AP/ActivityLikeEvent.php new file mode 100644 index 0000000..3423dd4 --- /dev/null +++ b/app/Events/AP/ActivityLikeEvent.php @@ -0,0 +1,26 @@ +activity = $activity; + } +} diff --git a/app/Events/AP/ActivityUndoEvent.php b/app/Events/AP/ActivityUndoEvent.php index f5e94a2..ecb4527 100644 --- a/app/Events/AP/ActivityUndoEvent.php +++ b/app/Events/AP/ActivityUndoEvent.php @@ -23,8 +23,6 @@ class ActivityUndoEvent use Dispatchable, InteractsWithSockets, SerializesModels; public $activity; - public $actor; - public $object; /** * Create a new event instance. @@ -32,31 +30,5 @@ class ActivityUndoEvent public function __construct($activity) { $this->activity = $activity; - - $this->actor = TypeActor::actor_exists_or_obtain ($activity ["actor"]); - - $child_activity = $activity ["object"]; - $child_activity_id = ""; - - if (is_array ($child_activity)) - $child_activity_id = $child_activity ["id"]; - else - $child_activity_id = $child_activity; - - if (!TypeActivity::activity_exists ($child_activity_id)) - return ["error" => "Activity not found",]; - - $child_activity = Activity::where ("activity_id", $child_activity_id)->first (); - $this->object = $child_activity; - - switch ($this->object->type) - { - case "Follow": - $unfollowed_actor = Actor::where ("actor_id", $this->object->object)->first (); - UserUnfollowedEvent::dispatch ($this->object, $this->actor, $unfollowed_actor); - break; - } - - $child_activity->delete (); } } diff --git a/app/Events/NoteLikedEvent.php b/app/Events/NoteLikedEvent.php index 19aa12a..437d30b 100644 --- a/app/Events/NoteLikedEvent.php +++ b/app/Events/NoteLikedEvent.php @@ -18,14 +18,14 @@ class NoteLikedEvent { use Dispatchable, InteractsWithSockets, SerializesModels; - public Activity $activity; - public Actor $actor; - public Note $note; + public $activity; + public $actor; + public $note; /** * Create a new event instance. */ - public function __construct(Activity $activity, Actor $actor, Note $note) + public function __construct($activity, $actor, $note) { $this->activity = $activity; $this->actor = $actor; diff --git a/app/Events/NoteRepliedEvent.php b/app/Events/NoteRepliedEvent.php index 23db1db..e727d80 100644 --- a/app/Events/NoteRepliedEvent.php +++ b/app/Events/NoteRepliedEvent.php @@ -19,13 +19,13 @@ class NoteRepliedEvent use Dispatchable, InteractsWithSockets, SerializesModels; public $activity; - public Actor $actor; - public Note $object; + public $actor; + public $object; /** * Create a new event instance. */ - public function __construct($activity, Actor $actor, Note $object) + public function __construct($activity, $actor, $object) { $this->activity = $activity; $this->actor = $actor; diff --git a/app/Events/UserFollowedEvent.php b/app/Events/UserFollowedEvent.php index 1014757..1c3c4ed 100644 --- a/app/Events/UserFollowedEvent.php +++ b/app/Events/UserFollowedEvent.php @@ -18,9 +18,9 @@ class UserFollowedEvent { use Dispatchable, InteractsWithSockets, SerializesModels; - public Activity $activity; - public Actor $actor; - public Actor $object; + public $activity; + public $actor; + public $object; /** * Create a new event instance. diff --git a/app/Events/UserUnfollowedEvent.php b/app/Events/UserUnfollowedEvent.php index 32514ee..12696eb 100644 --- a/app/Events/UserUnfollowedEvent.php +++ b/app/Events/UserUnfollowedEvent.php @@ -17,14 +17,14 @@ class UserUnfollowedEvent { use Dispatchable, InteractsWithSockets, SerializesModels; - public Activity $activity; - public Actor $actor; - public Actor $object; + public $activity; + public $actor; + public $object; /** * Create a new event instance. */ - public function __construct(Activity $activity, Actor $actor, Actor $object) + public function __construct($activity, $actor, $object) { $this->activity = $activity; $this->actor = $actor; diff --git a/app/Http/Controllers/AP/APInboxController.php b/app/Http/Controllers/AP/APInboxController.php index ef43602..0cdc084 100644 --- a/app/Http/Controllers/AP/APInboxController.php +++ b/app/Http/Controllers/AP/APInboxController.php @@ -13,10 +13,11 @@ use App\Models\Like; use App\Types\TypeActor; use App\Types\TypeActivity; -use App\Events\UserFollowedEvent; use App\Events\NoteLikedEvent; use App\Events\AP\ActivityUndoEvent; +use App\Events\AP\ActivityFollowEvent; +use App\Events\AP\ActivityLikeEvent; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; @@ -54,69 +55,16 @@ class APInboxController extends Controller private function handle_follow (User $user, $activity) { - if (TypeActivity::activity_exists ($activity["id"])) - return response ()->json (["error" => "Activity already exists",], 409); - - $actor = TypeActor::actor_exists_or_obtain ($activity ["actor"]); - - $target = TypeActor::actor_get_local ($activity ["object"]); - if (!$target || !$target->user) - return response ()->json (["error" => "Target not found",], 404); - - // check follow doesn't exist - $follow_exists = Follow::where ("actor", $actor->id) - ->where ("object", $target->id) - ->first (); - if ($follow_exists) - return response ()->json (["error" => "Follow already exists",], 409); - - $activity ["activity_id"] = $activity ["id"]; - $act = Activity::create ($activity); - - UserFollowedEvent::dispatch ($act, $actor, $target); - - // TODO: Users should be able to manually check this - $accept_activity = TypeActivity::craft_accept ($act); - $response = TypeActivity::post_activity ($accept_activity, $target, $actor); - if (!$response) - { - return response ()->json ([ - "error" => "Error posting activity", - ], 500); - } + ActivityFollowEvent::dispatch ($activity); } public function handle_undo (User $user, $activity) { - ActivityUndoEvent::dispatch ($activity, $activity); - return response ()->json (ActionsActivity::activity_undo ($activity)); + ActivityUndoEvent::dispatch ($activity); } public function handle_like (User $user, $activity) { - $actor = TypeActor::actor_exists_or_obtain ($activity ["actor"]); - $note_id = $activity ["object"]; - $note = Note::where ("note_id", $note_id)->first (); - if (!$note) - { - Log::info ("Note not found: " . $note_id); - return response ()->json (["error" => "Note not found",], 404); - } - - // check like doesn't already exist - $like_exists = $actor->liked_note ($note); - if ($like_exists) - return response ()->json (["error" => "Like already exists",], 409); - - $activity ["activity_id"] = $activity ["id"]; - $activity_exists = TypeActivity::activity_exists ($activity ["id"]); - if (!$activity_exists) - $act = Activity::create ($activity); - else - $act = Activity::where ("activity_id", $activity ["id"])->first (); - - NoteLikedEvent::dispatch ($act, $actor, $note); - - return response ()->json (["success" => "Like created",], 200); + ActivityLikeEvent::dispatch ($activity); } } diff --git a/app/Listeners/AP/ActivityFollowListener.php b/app/Listeners/AP/ActivityFollowListener.php new file mode 100644 index 0000000..e400cef --- /dev/null +++ b/app/Listeners/AP/ActivityFollowListener.php @@ -0,0 +1,58 @@ +activity["id"])) + return; + + $actor = TypeActor::actor_exists_or_obtain ($event->activity ["actor"]); + + $target = TypeActor::actor_get_local ($event->activity ["object"]); + if (!$target || !$target->user) + return; + + // check follow doesn't exist + $follow_exists = Follow::where ("actor", $actor->id) + ->where ("object", $target->id) + ->first (); + if ($follow_exists) + return; + + $event->activity ["activity_id"] = $event->activity ["id"]; + $act = Activity::create ($event->activity); + + UserFollowedEvent::dispatch ($act, $actor, $target); + + // TODO: Users should be able to manually check this + $accept_activity = TypeActivity::craft_accept ($act); + TypeActivity::post_activity ($accept_activity, $target, $actor); + } +} diff --git a/app/Listeners/AP/ActivityLikeListener.php b/app/Listeners/AP/ActivityLikeListener.php new file mode 100644 index 0000000..f9fd91c --- /dev/null +++ b/app/Listeners/AP/ActivityLikeListener.php @@ -0,0 +1,57 @@ +activity ["actor"]); + $note_id = $event->activity ["object"]; + $note = Note::where ("note_id", $note_id)->first (); + if (!$note) + { + return; + } + + // check like doesn't already exist + $like_exists = $actor->liked_note ($note); + if ($like_exists) + return; + + $event->activity ["activity_id"] = $event->activity ["id"]; + $activity_exists = TypeActivity::activity_exists ($event->activity ["id"]); + if (!$activity_exists) + $act = Activity::create ($event->activity); + else + $act = Activity::where ("activity_id", $event->activity ["id"])->first (); + + NoteLikedEvent::dispatch ($act, $actor, $note); + + return; + } +} diff --git a/app/Listeners/AP/ActivityUndoListener.php b/app/Listeners/AP/ActivityUndoListener.php new file mode 100644 index 0000000..1d03dc9 --- /dev/null +++ b/app/Listeners/AP/ActivityUndoListener.php @@ -0,0 +1,58 @@ +activity ["actor"]); + + $child_activity = $event->activity ["object"]; + $child_activity_id = ""; + + if (is_array ($child_activity)) + $child_activity_id = $child_activity ["id"]; + else + $child_activity_id = $child_activity; + + if (!TypeActivity::activity_exists ($child_activity_id)) + return; + + $child_activity = Activity::where ("activity_id", $child_activity_id)->first (); + $object = $child_activity; + + switch ($object->type) + { + case "Follow": + $unfollowed_actor = Actor::where ("actor_id", $object->object)->first (); + UserUnfollowedEvent::dispatch ($object, $actor, $unfollowed_actor); + break; + } + + $child_activity->delete (); + } +} diff --git a/resources/views/home_loggedin.blade.php b/resources/views/home_loggedin.blade.php index 4ee9867..cc2b7b2 100644 --- a/resources/views/home_loggedin.blade.php +++ b/resources/views/home_loggedin.blade.php @@ -29,7 +29,7 @@ | Bulletins | - Friends + Friends
My URL: