now posts can contain replies

This commit is contained in:
Ghostie 2025-01-05 13:50:19 -05:00
parent 2c7c18c7a6
commit e0f7100e60
11 changed files with 114 additions and 31 deletions

View File

@ -24,6 +24,9 @@ Notice that the styles were taken from [AnySpace](https://anyspace.3to.moe/about
- [ ] Handle Rejection - [ ] Handle Rejection
- [x] Likes - [x] Likes
- [ ] Comments - [ ] Comments
- [ ] Boosts
- [ ] Tags
- [ ] Pinned Posts
- [-] Social features - [-] Social features
- [x] Profile - [x] Profile

View File

@ -43,6 +43,7 @@ class ActionsPost
"summary" => $request->summary, "summary" => $request->summary,
"content" => $processed_content, "content" => $processed_content,
"attachments" => $attachments, "attachments" => $attachments,
"inReplyTo" => $request->inReplyTo ?? null,
]; ];
} }
@ -79,12 +80,13 @@ class ActionsPost
"summary" => $processed ["summary"], "summary" => $processed ["summary"],
"content" => $processed ["content"], "content" => $processed ["content"],
"attachments" => $processed ["attachments"], "attachments" => $processed ["attachments"],
"inReplyTo" => $processed ["inReplyTo"] ?? null,
] ]
]); ]);
} }
catch (\Exception $e) catch (\Exception $e)
{ {
return ["error" => "Could not connect to server."]; return ["error" => "Could not connect to server: " . $e->getMessage ()];
} }
return ["success" => "Post created"]; return ["success" => "Post created"];
@ -105,7 +107,7 @@ class ActionsPost
} }
catch (\Exception $e) catch (\Exception $e)
{ {
return ["error" => "Could not connect to server."]; return ["error" => "Could not connect to server: " . $e->getMessage ()];
} }
return $response; return $response;

View File

@ -32,7 +32,7 @@ class UserActionController extends Controller
$request->validate ([ $request->validate ([
"summary" => "nullable|string", "summary" => "nullable|string",
"content" => "required", "content" => "required",
"files.*" => "mimes:jpeg,png,jpg,gif,webm|max:4096" "files.*" => "max:4096"
]); ]);
$response = ActionsPost::post_new ($request); $response = ActionsPost::post_new ($request);

View File

@ -35,6 +35,17 @@ class Note extends Model
return $this->hasMany (Like::class); 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 () public function attachments ()
{ {
return $this->hasMany (NoteAttachment::class); return $this->hasMany (NoteAttachment::class);

View File

@ -134,7 +134,7 @@ class User extends Authenticatable
$friends_id[] = Actor::where ("actor_id", $friend)->first ()->id; $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; return $notes;
} }

View File

@ -89,6 +89,8 @@ class TypeNote
foreach ($request ["attachment"] as $attachment) 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"]; $attachment_url = $attachment ["url"];
$exists = NoteAttachment::where ("url", $attachment_url)->first (); $exists = NoteAttachment::where ("url", $attachment_url)->first ();
if (!$exists) if (!$exists)

View File

@ -31,6 +31,13 @@ else
</b> </b>
</p> </p>
@if ($post->in_reply_to)
<small>
In response to
<a href="{{ route ('posts.show', [ 'note' => $post->get_parent ()->first ()->id ]) }}">this post</a>
</small>
@endif
<h4>{{ $post->summary }}</h4> <h4>{{ $post->summary }}</h4>
{!! $post->content !!} {!! $post->content !!}
@ -42,10 +49,43 @@ else
</p> </p>
<br> <br>
@if ($post->get_replies ()->count () > 0)
<div class="comment-replies">
@foreach ($post->get_replies ()->get () as $reply)
<div class="comment-reply">
<h4>{{ $reply->summary }}</h4>
{!! $reply->content !!}
<p>
@foreach ($reply->attachments as $attachment)
<img loading="lazy" src="{{ $attachment->url }}" alt="{{ $attachment->name }}" width="100">
@endforeach
</p>
<p>
<small>
by
<a href="{{ route ('users.show', [ 'user_name' => $reply->get_actor ()->first ()->user_id ? $reply->get_actor ()->first ()->user->name : $reply->get_actor ()->first ()->local_actor_id ]) }}">
<b>{{ $reply->get_actor ()->first ()->name }}</b>
</a>
;
<time class="ago">{{ $reply->created_at->diffForHumans () }}</time>
</small>
</p>
</div>
@endforeach
</div>
@endif
<hr> <hr>
<p> <p>
<span><b>Likes:</b> {{ $post->get_likes ()->count () }}</span> <b>Likes:</b> {{ $post->get_likes ()->count () }}
</p>
<p>
<b>Replies:</b> {{ $post->get_replies ()->count () }}
</p> </p>
<a href="{{ route ('posts.show', [ 'note' => $post ]) }}"> <a href="{{ route ('posts.show', [ 'note' => $post ]) }}">

View File

@ -0,0 +1,24 @@
<form action="{{ route ('user.post.new') }}" method="POST" enctype="multipart/form-data">
@csrf
@if (isset ($inreplyto))
<input type="hidden" name="inReplyTo" value="{{ $inreplyto->note_id }}">
@endif
<input type="text" name="summary" placeholder="Title" size="60">
<br>
<textarea name="content" placeholder="What's on your mind?" cols="60" rows="5"></textarea>
<input type="file" name="files[]" accept="image/*" multiple>
<button type="submit">Post</button>
<small>Markdown is supported</small>
@error ("content")
<div class="error">{{ $message }}</div>
@enderror
@error ("files.*")
<div class="error">{{ $message }}</div>
@enderror
</form>

View File

@ -138,6 +138,8 @@
</div> </div>
<div class="inner"> <div class="inner">
<x-create_note /><Br>
<table class="comments-table" cellspacing="0" cellpadding="3" bordercollor="#ffffff" border="1"> <table class="comments-table" cellspacing="0" cellpadding="3" bordercollor="#ffffff" border="1">
<tbody> <tbody>
@foreach (auth ()->user ()->feed () as $post) @foreach (auth ()->user ()->feed () as $post)

View File

@ -49,6 +49,13 @@
<button type="submit">Delete</button> <button type="submit">Delete</button>
</form> </form>
@endif @endif
@if ($note->in_reply_to)
<p>
<b>In Reply To</b>: <a href="{{ route ('posts.show', [ 'note' => $note->get_parent ()->first ()->id ]) }}">this post</a>
</p>
@endif
<div class="content"> <div class="content">
<div class="heading"> <div class="heading">
<h4>{{ $note->summary }}</h4> <h4>{{ $note->summary }}</h4>
@ -62,12 +69,14 @@
<br> <br>
<div class="buttons"> @auth
<form action="{{ route ('posts.like', [ 'note' => $note->id ]) }}" method="POST"> <div class="buttons">
@csrf <form action="{{ route ('posts.like', [ 'note' => $note->id ]) }}" method="POST">
<button type="submit">{{ auth ()->user ()->actor ()->first ()->liked_note ($note) ? "Undo Like" : "Like" }}</button> @csrf
</form> <button type="submit">{{ auth ()->user ()->actor ()->first ()->liked_note ($note) ? "Undo Like" : "Like" }}</button>
</div> </form>
</div>
@endauth
<p> <p>
<b>Likes</b>: {{ $note->get_likes ()->count () }} <b>Likes</b>: {{ $note->get_likes ()->count () }}
@ -79,14 +88,20 @@
</div> </div>
<div class="inner"> <div class="inner">
@auth
<x-create_note :inreplyto="$note" />
<br>
@endauth
<p> <p>
<b>Displaying <span class="count">0</span> of <span class="count">0</span> comments</b> <b>Displaying <span class="count">0</span> of <span class="count">{{ $note->get_replies ()->count () }}</span> comments</b>
</p> </p>
<table class="comments-table" cellspacing="0" cellpadding="3" bordercolor="ffffff" border="1"> <table class="comments-table" cellspacing="0" cellpadding="3" bordercolor="ffffff" border="1">
<tbody> <tbody>
<!-- TODO: Comments --> @foreach ($note->get_replies ()->get () as $reply)
Comments go here <x-comment_block :actor="$reply->get_actor ()->first ()" :post="$reply" />
@endforeach
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -293,23 +293,7 @@
</p> </p>
@if (auth ()->user () && auth ()->user ()->is ($user)) @if (auth ()->user () && auth ()->user ()->is ($user))
<form action="{{ route ('user.post.new') }}" method="POST" enctype="multipart/form-data"> <x-create_note />
@csrf
<input type="text" name="summary" placeholder="Title" size="60">
<br>
<textarea name="content" placeholder="What's on your mind?" cols="60" rows="5"></textarea>
<input type="file" name="files[]" accept="image/*" multiple>
<button type="submit">Post</button>
<small>Markdown is supported</small>
@error ("content")
<div class="error">{{ $message }}</div>
@enderror
@error ("files.*")
<div class="error">{{ $message }}</div>
@enderror
</form>
@endif @endif
<br> <br>