From e0f7100e6098a66b0e1509fbc5b7eb31b68a3915 Mon Sep 17 00:00:00 2001
From: Ghostie
Date: Sun, 5 Jan 2025 13:50:19 -0500
Subject: [PATCH] now posts can contain replies
---
README.md | 3 ++
app/Actions/ActionsPost.php | 6 ++-
app/Http/Controllers/UserActionController.php | 2 +-
app/Models/Note.php | 11 +++++
app/Models/User.php | 2 +-
app/Types/TypeNote.php | 2 +
.../views/components/comment_block.blade.php | 42 ++++++++++++++++++-
.../views/components/create_note.blade.php | 24 +++++++++++
resources/views/home_loggedin.blade.php | 2 +
resources/views/posts/show.blade.php | 33 +++++++++++----
resources/views/users/profile.blade.php | 18 +-------
11 files changed, 114 insertions(+), 31 deletions(-)
create mode 100644 resources/views/components/create_note.blade.php
diff --git a/README.md b/README.md
index fb4e47d..9716858 100644
--- a/README.md
+++ b/README.md
@@ -24,6 +24,9 @@ Notice that the styles were taken from [AnySpace](https://anyspace.3to.moe/about
- [ ] Handle Rejection
- [x] Likes
- [ ] Comments
+ - [ ] Boosts
+ - [ ] Tags
+ - [ ] Pinned Posts
- [-] Social features
- [x] Profile
diff --git a/app/Actions/ActionsPost.php b/app/Actions/ActionsPost.php
index 0be048b..4dcef64 100644
--- a/app/Actions/ActionsPost.php
+++ b/app/Actions/ActionsPost.php
@@ -43,6 +43,7 @@ class ActionsPost
"summary" => $request->summary,
"content" => $processed_content,
"attachments" => $attachments,
+ "inReplyTo" => $request->inReplyTo ?? null,
];
}
@@ -79,12 +80,13 @@ class ActionsPost
"summary" => $processed ["summary"],
"content" => $processed ["content"],
"attachments" => $processed ["attachments"],
+ "inReplyTo" => $processed ["inReplyTo"] ?? null,
]
]);
}
catch (\Exception $e)
{
- return ["error" => "Could not connect to server."];
+ return ["error" => "Could not connect to server: " . $e->getMessage ()];
}
return ["success" => "Post created"];
@@ -105,7 +107,7 @@ class ActionsPost
}
catch (\Exception $e)
{
- return ["error" => "Could not connect to server."];
+ return ["error" => "Could not connect to server: " . $e->getMessage ()];
}
return $response;
diff --git a/app/Http/Controllers/UserActionController.php b/app/Http/Controllers/UserActionController.php
index aa5b586..6f345b9 100644
--- a/app/Http/Controllers/UserActionController.php
+++ b/app/Http/Controllers/UserActionController.php
@@ -32,7 +32,7 @@ class UserActionController extends Controller
$request->validate ([
"summary" => "nullable|string",
"content" => "required",
- "files.*" => "mimes:jpeg,png,jpg,gif,webm|max:4096"
+ "files.*" => "max:4096"
]);
$response = ActionsPost::post_new ($request);
diff --git a/app/Models/Note.php b/app/Models/Note.php
index 0079ceb..9dc6ae8 100644
--- a/app/Models/Note.php
+++ b/app/Models/Note.php
@@ -35,6 +35,17 @@ class Note extends Model
return $this->hasMany (Like::class);
}
+ public function get_replies ()
+ {
+ return $this->hasMany (Note::class, "in_reply_to", "note_id");
+ }
+
+ public function get_parent ()
+ {
+ if ($this->in_reply_to)
+ return $this->hasOne (Note::class, "note_id", "in_reply_to");
+ }
+
public function attachments ()
{
return $this->hasMany (NoteAttachment::class);
diff --git a/app/Models/User.php b/app/Models/User.php
index dd457a2..1d42cac 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -134,7 +134,7 @@ class User extends Authenticatable
$friends_id[] = Actor::where ("actor_id", $friend)->first ()->id;
}
- $notes = Note::whereIn ("actor_id", $friends_id)->orderBy ("created_at", "desc")->get ();
+ $notes = Note::whereIn ("actor_id", $friends_id)->where ("in_reply_to", null)->orderBy ("created_at", "desc")->get ();
return $notes;
}
diff --git a/app/Types/TypeNote.php b/app/Types/TypeNote.php
index 3a7fa25..39184ef 100644
--- a/app/Types/TypeNote.php
+++ b/app/Types/TypeNote.php
@@ -89,6 +89,8 @@ class TypeNote
foreach ($request ["attachment"] as $attachment)
{
+ // TODO: Check if it's type and proceed based on that
+ // TODO: Store its type in the database
$attachment_url = $attachment ["url"];
$exists = NoteAttachment::where ("url", $attachment_url)->first ();
if (!$exists)
diff --git a/resources/views/components/comment_block.blade.php b/resources/views/components/comment_block.blade.php
index f2ac51b..094d802 100644
--- a/resources/views/components/comment_block.blade.php
+++ b/resources/views/components/comment_block.blade.php
@@ -31,6 +31,13 @@ else
+ @if ($post->in_reply_to)
+
+ In response to
+ this post
+
+ @endif
+
{{ $post->summary }}
{!! $post->content !!}
@@ -42,10 +49,43 @@ else
+
+ @if ($post->get_replies ()->count () > 0)
+
+ @endif
+
- Likes: {{ $post->get_likes ()->count () }}
+ Likes: {{ $post->get_likes ()->count () }}
+
+
+ Replies: {{ $post->get_replies ()->count () }}
diff --git a/resources/views/components/create_note.blade.php b/resources/views/components/create_note.blade.php
new file mode 100644
index 0000000..b3bc87b
--- /dev/null
+++ b/resources/views/components/create_note.blade.php
@@ -0,0 +1,24 @@
+
diff --git a/resources/views/home_loggedin.blade.php b/resources/views/home_loggedin.blade.php
index 088dce6..8a5bf0d 100644
--- a/resources/views/home_loggedin.blade.php
+++ b/resources/views/home_loggedin.blade.php
@@ -138,6 +138,8 @@
+
+
{{ $reply->summary }}
+ + {!! $reply->content !!} + ++ @foreach ($reply->attachments as $attachment) +
+ @endforeach
+
+ ++ + by + + {{ $reply->get_actor ()->first ()->name }} + + ; + + +
+