From fdb9d09f0ddd68e5e8ff76761a8b0e7dacd5133c Mon Sep 17 00:00:00 2001
From: Ghostie
Date: Sun, 29 Dec 2024 22:19:29 -0500
Subject: [PATCH] added a page to show a single post
---
README.md | 10 +--
.../AP/APInstanceInboxController.php | 21 +++++
app/Http/Controllers/PostController.php | 17 ++++
app/Models/User.php | 17 ++++
app/Types/TypeNote.php | 16 +++-
.../views/components/comment_block.blade.php | 26 ++++++-
resources/views/home_loggedin.blade.php | 10 ++-
resources/views/posts/show.blade.php | 77 +++++++++++++++++++
routes/web.php | 4 +
9 files changed, 183 insertions(+), 15 deletions(-)
create mode 100644 app/Http/Controllers/PostController.php
create mode 100644 resources/views/posts/show.blade.php
diff --git a/README.md b/README.md
index bb9420e..1e1c55f 100644
--- a/README.md
+++ b/README.md
@@ -14,8 +14,8 @@ Notice that the styles were taken from [AnySpace](https://anyspace.3to.moe/about
- [-] Activitypub
- [x] Accounts
- [-] Posts
- - [ ] Local posts should be federated
- - [ ] Local posts should be deleted
+ - [x] Local posts should be federated
+ - [x] Local posts should be deleted
- [x] Remote posts should be fetched
- [x] Remote posts should be deleted
- [x] Follows
@@ -28,7 +28,7 @@ Notice that the styles were taken from [AnySpace](https://anyspace.3to.moe/about
- [x] Profile
- [ ] Show when the user is online
- [ ] Set mood
- - [ ] Set interests
+ - [x] Set interests
- [x] Update profile picture
- [ ] Mark account as private (in federation manual approval is needed)
- [ ] Allow custom CSS
@@ -36,8 +36,8 @@ Notice that the styles were taken from [AnySpace](https://anyspace.3to.moe/about
- [x] Friends (they are known as follows in the activitypub protocol)
- [x] Add friends
- [x] Remove friends
- - [ ] Posts (everything should be federated)
- - [ ] Create posts
+ - [x] Posts (everything should be federated)
+ - [x] Create posts
- [ ] Delete posts
- [ ] Like posts
- [ ] Comment posts
diff --git a/app/Http/Controllers/AP/APInstanceInboxController.php b/app/Http/Controllers/AP/APInstanceInboxController.php
index a08ef48..09c85ef 100644
--- a/app/Http/Controllers/AP/APInstanceInboxController.php
+++ b/app/Http/Controllers/AP/APInstanceInboxController.php
@@ -95,6 +95,15 @@ class APInstanceInboxController extends Controller
case "Person":
return $this->handle_update_person ($object);
break;
+
+ case "Note":
+ return $this->handle_update_note ($object);
+ break;
+
+ default:
+ Log::info ("APInstanceInboxController:handle_update");
+ Log::info (json_encode ($activity));
+ break;
}
return response ()->json (["status" => "ok"]);
@@ -127,4 +136,16 @@ class APInstanceInboxController extends Controller
return response ()->json (["status" => "ok"]);
}
+
+ public function handle_update_note ($object)
+ {
+ $note = TypeNote::note_exists ($object ["id"]);
+ if (!$note)
+ return response ()->json (["status" => "ok"]);
+
+ TypeNote::update_from_request ($note, $object, $note->get_activity ()->first (), $note->get_actor ()->first ());
+ $note->save ();
+
+ return response ()->json (["status" => "ok"]);
+ }
}
diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php
new file mode 100644
index 0000000..61c44e6
--- /dev/null
+++ b/app/Http/Controllers/PostController.php
@@ -0,0 +1,17 @@
+get_actor ()->first ();
+
+ return view ("posts.show", compact ("note", "actor"));
+ }
+}
diff --git a/app/Models/User.php b/app/Models/User.php
index 7179a3c..0238c3b 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -92,4 +92,21 @@ class User extends Authenticatable
return array_diff ($followers, $following);
}
+
+ public function feed ()
+ {
+ $mutual_friends = $this->mutual_friends ();
+ $friends_id = [
+ $this->actor ()->first ()->id
+ ];
+
+ foreach ($mutual_friends as $friend)
+ {
+ $friends_id[] = Actor::where ("actor_id", $friend)->first ()->id;
+ }
+
+ $notes = Note::whereIn ("actor_id", $friends_id)->orderBy ("created_at", "desc")->get ();
+
+ return $notes;
+ }
}
diff --git a/app/Types/TypeNote.php b/app/Types/TypeNote.php
index f3ecb55..306079b 100644
--- a/app/Types/TypeNote.php
+++ b/app/Types/TypeNote.php
@@ -76,14 +76,22 @@ class TypeNote
$note->content = $request["content"] ?? null;
$note->tag = $request["tag"] ?? null;
+ $attachments = $note->attachments ()->get ();
+ foreach ($attachments as $attachment)
+ $attachment->delete ();
+
if ($request ["attachment"])
{
+
foreach ($request ["attachment"] as $attachment)
{
- $note_attachment = NoteAttachment::create ([
- "note_id" => $note->id,
- "url" => $attachment ["url"]
- ]);
+ $attachment_url = $attachment ["url"];
+ $exists = NoteAttachment::where ("url", $attachment_url)->first ();
+ if (!$exists)
+ $note_attachment = NoteAttachment::create ([
+ "note_id" => $note->id,
+ "url" => $attachment ["url"]
+ ]);
}
}
}
diff --git a/resources/views/components/comment_block.blade.php b/resources/views/components/comment_block.blade.php
index f4469eb..ac4ee0e 100644
--- a/resources/views/components/comment_block.blade.php
+++ b/resources/views/components/comment_block.blade.php
@@ -27,16 +27,34 @@ else
-
+
-
- {!! $post->content !!}
-
+
+ {!! $post->content !!}
+
@foreach ($post->attachments as $attachment)
@endforeach
+
+
+
+
+
+
+
+ @if ($actor->user && auth ()->check () && auth ()->user ()->is ($actor->user))
+
+ @endif
|
diff --git a/resources/views/home_loggedin.blade.php b/resources/views/home_loggedin.blade.php
index c2cd31a..c00bbe8 100644
--- a/resources/views/home_loggedin.blade.php
+++ b/resources/views/home_loggedin.blade.php
@@ -87,7 +87,7 @@
Joined:
- {{ Carbon\Carbon::parse (auth ()->user ()->created_at)->diffForHumans () }}
+ {{ auth ()->user ()->created_at->diffForHumans () }}
@@ -121,7 +121,13 @@
- Feed goes here
+
diff --git a/resources/views/posts/show.blade.php b/resources/views/posts/show.blade.php
new file mode 100644
index 0000000..26c0642
--- /dev/null
+++ b/resources/views/posts/show.blade.php
@@ -0,0 +1,77 @@
+@extends("partials.layout")
+
+@section ("title", "View Post")
+
+@section ("content")
+
+
+
+
+

+
+
+
+
+
+
+ published
+
+
+
+
+
+
+ View Profile
+
+
+
+
+
+
+
+
{{ $actor->name }}'s Post
+ @if (auth ()->check () && auth ()->user ()->is ($actor->user))
+
+ @endif
+
+ {!! $note->content !!}
+
+
+
+
+
+
+
+@endsection
diff --git a/routes/web.php b/routes/web.php
index 9143332..324db14 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -3,6 +3,7 @@
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
+use App\Http\Controllers\PostController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\UserActionController;
@@ -26,6 +27,9 @@ Route::get ("/user/edit", [ ProfileController::class, "edit" ])->name ("users.ed
Route::post ("/user/edit", [ ProfileController::class, "update" ])->middleware ("auth");
Route::get ("/user/{user_name}", [ ProfileController::class, "show" ])->name ("users.show");
+// posts routes
+Route::get ("/post/{note}", [ PostController::class, "show" ])->name ("posts.show");
+
// other routes
Route::get ("/search", [ HomeController::class, "search" ])->name ("search");
Route::get ("/requests", [ HomeController::class, "requests" ])->name ("requests")->middleware ("auth");
Comments
++ Displaying 0 of 0 comments +
+ +