now posts can contain replies
This commit is contained in:
parent
2c7c18c7a6
commit
e0f7100e60
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -31,6 +31,13 @@ else
|
||||
</b>
|
||||
</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>
|
||||
|
||||
{!! $post->content !!}
|
||||
@ -42,10 +49,43 @@ else
|
||||
</p>
|
||||
|
||||
<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>
|
||||
|
||||
<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>
|
||||
|
||||
<a href="{{ route ('posts.show', [ 'note' => $post ]) }}">
|
||||
|
24
resources/views/components/create_note.blade.php
Normal file
24
resources/views/components/create_note.blade.php
Normal 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>
|
@ -138,6 +138,8 @@
|
||||
</div>
|
||||
|
||||
<div class="inner">
|
||||
<x-create_note /><Br>
|
||||
|
||||
<table class="comments-table" cellspacing="0" cellpadding="3" bordercollor="#ffffff" border="1">
|
||||
<tbody>
|
||||
@foreach (auth ()->user ()->feed () as $post)
|
||||
|
@ -49,6 +49,13 @@
|
||||
<button type="submit">Delete</button>
|
||||
</form>
|
||||
@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="heading">
|
||||
<h4>{{ $note->summary }}</h4>
|
||||
@ -62,12 +69,14 @@
|
||||
|
||||
<br>
|
||||
|
||||
<div class="buttons">
|
||||
<form action="{{ route ('posts.like', [ 'note' => $note->id ]) }}" method="POST">
|
||||
@csrf
|
||||
<button type="submit">{{ auth ()->user ()->actor ()->first ()->liked_note ($note) ? "Undo Like" : "Like" }}</button>
|
||||
</form>
|
||||
</div>
|
||||
@auth
|
||||
<div class="buttons">
|
||||
<form action="{{ route ('posts.like', [ 'note' => $note->id ]) }}" method="POST">
|
||||
@csrf
|
||||
<button type="submit">{{ auth ()->user ()->actor ()->first ()->liked_note ($note) ? "Undo Like" : "Like" }}</button>
|
||||
</form>
|
||||
</div>
|
||||
@endauth
|
||||
|
||||
<p>
|
||||
<b>Likes</b>: {{ $note->get_likes ()->count () }}
|
||||
@ -79,14 +88,20 @@
|
||||
</div>
|
||||
|
||||
<div class="inner">
|
||||
@auth
|
||||
<x-create_note :inreplyto="$note" />
|
||||
<br>
|
||||
@endauth
|
||||
|
||||
<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>
|
||||
|
||||
<table class="comments-table" cellspacing="0" cellpadding="3" bordercolor="ffffff" border="1">
|
||||
<tbody>
|
||||
<!-- TODO: Comments -->
|
||||
Comments go here
|
||||
@foreach ($note->get_replies ()->get () as $reply)
|
||||
<x-comment_block :actor="$reply->get_actor ()->first ()" :post="$reply" />
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -293,23 +293,7 @@
|
||||
</p>
|
||||
|
||||
@if (auth ()->user () && auth ()->user ()->is ($user))
|
||||
<form action="{{ route ('user.post.new') }}" method="POST" enctype="multipart/form-data">
|
||||
@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>
|
||||
<x-create_note />
|
||||
@endif
|
||||
|
||||
<br>
|
||||
|
Loading…
x
Reference in New Issue
Block a user