now local posts can be deleted as well
This commit is contained in:
parent
d38da1722a
commit
d32c81575f
@ -37,6 +37,10 @@ class APOutboxController extends Controller
|
|||||||
return $this->handle_update_note ($user, $request);
|
return $this->handle_update_note ($user, $request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "DeleteNote":
|
||||||
|
return $this->handle_delete_note ($user, $request);
|
||||||
|
break;
|
||||||
|
|
||||||
case "Follow":
|
case "Follow":
|
||||||
return $this->handle_follow ($user, $request->get ("object"));
|
return $this->handle_follow ($user, $request->get ("object"));
|
||||||
break;
|
break;
|
||||||
@ -62,15 +66,7 @@ class APOutboxController extends Controller
|
|||||||
$actor_response = TypeActor::build_response ($actor);
|
$actor_response = TypeActor::build_response ($actor);
|
||||||
|
|
||||||
$update_activity = TypeActivity::craft_update ($actor, $actor_response);
|
$update_activity = TypeActivity::craft_update ($actor, $actor_response);
|
||||||
$instances = Instance::all ();
|
$response = TypeActivity::post_to_instances ($update_activity, $actor);
|
||||||
foreach ($instances as $instance)
|
|
||||||
{
|
|
||||||
$response = TypeActivity::post_activity ($update_activity, $actor, $instance->inbox, true);
|
|
||||||
if ($response->getStatusCode () < 200 || $response->getStatusCode () >= 300)
|
|
||||||
{
|
|
||||||
Log::info ("failed to post activity to " . $instance->inbox);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return response ()->json ("success", 200);
|
return response ()->json ("success", 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,15 +117,26 @@ class APOutboxController extends Controller
|
|||||||
|
|
||||||
$note_response = TypeNote::build_response ($note);
|
$note_response = TypeNote::build_response ($note);
|
||||||
$update_activity = TypeActivity::craft_update ($actor, $note_response);
|
$update_activity = TypeActivity::craft_update ($actor, $note_response);
|
||||||
$instances = Instance::all ();
|
$response = TypeActivity::post_to_instances ($update_activity, $actor);
|
||||||
foreach ($instances as $instance)
|
|
||||||
{
|
return response ()->json ("success", 200);
|
||||||
$response = TypeActivity::post_activity ($update_activity, $actor, $instance->inbox, true);
|
}
|
||||||
if ($response->getStatusCode () < 200 || $response->getStatusCode () >= 300)
|
|
||||||
{
|
public function handle_delete_note (User $user, $request)
|
||||||
Log::info ("failed to post activity to " . $instance->inbox);
|
{
|
||||||
}
|
$actor = $user->actor ()->first ();
|
||||||
}
|
$note = Note::where ("id", $request ["note"])->first ();
|
||||||
|
if (!$note)
|
||||||
|
return response ()->json ([ "error" => "note not found" ], 404);
|
||||||
|
|
||||||
|
$note_actor = $note->get_actor ()->first ();
|
||||||
|
if ($actor != $note_actor)
|
||||||
|
return response ()->json ([ "error" => "not allowed" ], 403);
|
||||||
|
|
||||||
|
$note->delete ();
|
||||||
|
|
||||||
|
$delete_activity = TypeActivity::craft_delete ($actor, $note->note_id);
|
||||||
|
$response = TypeActivity::post_to_instances ($delete_activity, $actor);
|
||||||
|
|
||||||
return response ()->json ("success", 200);
|
return response ()->json ("success", 200);
|
||||||
}
|
}
|
||||||
@ -208,13 +215,7 @@ class APOutboxController extends Controller
|
|||||||
$note->activity_id = $create_activity->id;
|
$note->activity_id = $create_activity->id;
|
||||||
$note->save ();
|
$note->save ();
|
||||||
|
|
||||||
$instances = Instance::all ();
|
$response = TypeActivity::post_to_instances ($create_activity, $actor);
|
||||||
|
return response ()->json ("success", 200);
|
||||||
foreach ($instances as $instance)
|
|
||||||
{
|
|
||||||
$response = TypeActivity::post_activity ($create_activity, $actor, $instance->inbox);
|
|
||||||
if ($response->getStatusCode () < 200 || $response->getStatusCode () >= 300)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,4 +69,30 @@ class PostController extends Controller
|
|||||||
Log::error ($e->getMessage ());
|
Log::error ($e->getMessage ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function delete (Note $note)
|
||||||
|
{
|
||||||
|
$actor = auth ()->user ()->actor ()->first ();
|
||||||
|
$note_user = $actor->user ()->first ();
|
||||||
|
if (!auth ()->user ()->is ($note_user)) {
|
||||||
|
return back ()->with ("error", "You are not allowed to delete this post.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$client = new Client ();
|
||||||
|
$client->request ("POST", $note->get_actor ()->first ()->outbox, [
|
||||||
|
"json" => [
|
||||||
|
"type" => "DeleteNote",
|
||||||
|
"note" => $note->id
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect ()->route ("home")->with ("success", "Post deleted successfully.");
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return back ()->with ("error", "An error occurred while deleting the post.");
|
||||||
|
|
||||||
|
Log::error ("An error occurred while deleting the post.");
|
||||||
|
Log::error ($e->getMessage ());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ namespace App\Types;
|
|||||||
|
|
||||||
use App\Models\Actor;
|
use App\Models\Actor;
|
||||||
use App\Models\Activity;
|
use App\Models\Activity;
|
||||||
|
use App\Models\Instance;
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
|
||||||
@ -101,6 +102,23 @@ class TypeActivity {
|
|||||||
return $create_activity;
|
return $create_activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function craft_delete (Actor $actor, $id)
|
||||||
|
{
|
||||||
|
$delete_activity = new Activity ();
|
||||||
|
$delete_activity->activity_id = env ("APP_URL") . "/activity/" . uniqid ();
|
||||||
|
$delete_activity->type = "Delete";
|
||||||
|
$delete_activity->actor = $actor->actor_id;
|
||||||
|
|
||||||
|
$delete_activity->object = [
|
||||||
|
"id" => $id,
|
||||||
|
"type" => "Tombstone"
|
||||||
|
];
|
||||||
|
|
||||||
|
$delete_activity->save ();
|
||||||
|
|
||||||
|
return $delete_activity;
|
||||||
|
}
|
||||||
|
|
||||||
public static function get_private_key (Actor $actor)
|
public static function get_private_key (Actor $actor)
|
||||||
{
|
{
|
||||||
return openssl_get_privatekey ($actor->private_key);
|
return openssl_get_privatekey ($actor->private_key);
|
||||||
@ -234,6 +252,19 @@ class TypeActivity {
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function post_to_instances (Activity $activity, Actor $source)
|
||||||
|
{
|
||||||
|
$instances = Instance::all ();
|
||||||
|
foreach ($instances as $instance)
|
||||||
|
{
|
||||||
|
$response = TypeActivity::post_activity ($activity, $source, $instance->inbox, true);
|
||||||
|
if ($response->getStatusCode () < 200 || $response->getStatusCode () >= 300)
|
||||||
|
{
|
||||||
|
Log::info ("failed to post activity to " . $instance->inbox);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// some little functions
|
// some little functions
|
||||||
public static function activity_exists ($activity_id)
|
public static function activity_exists ($activity_id)
|
||||||
{
|
{
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
@if (auth ()->check () && auth ()->user ()->is ($actor->user))
|
@if (auth ()->check () && auth ()->user ()->is ($actor->user))
|
||||||
<form action="#" method="POST">
|
<form action="#" method="POST">
|
||||||
@csrf
|
@csrf
|
||||||
|
@method("DELETE")
|
||||||
<a href="{{ route ('posts.edit', [ 'note' => $note ]) }}">
|
<a href="{{ route ('posts.edit', [ 'note' => $note ]) }}">
|
||||||
<button type="button">Edit</button>
|
<button type="button">Edit</button>
|
||||||
</a>
|
</a>
|
||||||
|
@ -32,6 +32,7 @@ Route::get ("/user/{user_name}", [ ProfileController::class, "show" ])->name ("u
|
|||||||
Route::get ("/post/{note}/edit", [ PostController::class, "edit" ])->name ("posts.edit")->middleware ("auth");
|
Route::get ("/post/{note}/edit", [ PostController::class, "edit" ])->name ("posts.edit")->middleware ("auth");
|
||||||
Route::post ("/post/{note}/edit", [ PostController::class, "update" ])->middleware ("auth");
|
Route::post ("/post/{note}/edit", [ PostController::class, "update" ])->middleware ("auth");
|
||||||
Route::get ("/post/{note}", [ PostController::class, "show" ])->name ("posts.show");
|
Route::get ("/post/{note}", [ PostController::class, "show" ])->name ("posts.show");
|
||||||
|
Route::delete ("/post/{note}", [ PostController::class, "delete" ])->name ("posts.delete")->middleware ("auth");
|
||||||
|
|
||||||
// other routes
|
// other routes
|
||||||
Route::get ("/search", [ HomeController::class, "search" ])->name ("search");
|
Route::get ("/search", [ HomeController::class, "search" ])->name ("search");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user