diff --git a/app/Http/Controllers/NotesController.php b/app/Http/Controllers/NotesController.php index 97422ea7..302f71a5 100644 --- a/app/Http/Controllers/NotesController.php +++ b/app/Http/Controllers/NotesController.php @@ -37,35 +37,9 @@ class NotesController extends Controller */ public function show($urlId) { - $note = Note::nb60($urlId)->first(); - $replies = []; - $reposts = []; - $likes = []; - foreach ($note->webmentions as $webmention) { - $content['author'] = $webmention->author; - $content['published'] = $webmention->published; - $content['source'] = $webmention->source; - switch ($webmention->type) { - case 'in-reply-to': - $content['reply'] = $webmention->reply; - $microformats = json_decode($webmention->mf2, true); - $content['reply'] = $this->filterHTML( - $microformats['items'][0]['properties']['content'][0]['html'] - ); - $replies[] = $content; - break; + $note = Note::nb60($urlId)->with('webmentions')->first(); - case 'repost-of': - $reposts[] = $content; - break; - - case 'like-of': - $likes[] = $content; - break; - } - } - - return view('notes.show', compact('note', 'replies', 'reposts', 'likes')); + return view('notes.show', compact('note')); } /** diff --git a/resources/views/notes/show.blade.php b/resources/views/notes/show.blade.php index ec6e9e41..e4817757 100644 --- a/resources/views/notes/show.blade.php +++ b/resources/views/notes/show.blade.php @@ -7,7 +7,9 @@ @section('content')
@include('templates.note', ['note' => $note]) -@foreach($replies as $reply) +@foreach($note->webmentions->filter(function ($webmention) { + return ($webmention->type == 'in-reply-to'); +}) as $reply)
{{ $reply['author']['properties']['name'][0] }} @@ -17,16 +19,26 @@
@endforeach -@if(count($likes) > 0)

Likes

@endif -@foreach($likes as $like) +@if($note->webmentions->filter(function ($webmention) { + return ($webmention->type == 'like-of'); +})->count() > 0)

Likes

+@foreach($note->webmentions->filter(function ($webmention) { + return ($webmention->type == 'like-of'); +}) as $like)
profile picture of {{ $like['author']['properties']['name'][0] }} @endforeach -@if(count($reposts) > 0)

Reposts

@endif -@foreach($reposts as $repost) +@endif +@if($note->webmentions->filter(function ($webmention) { + return ($webmention->type == 'repost-of'); +})->count() > 0)

Reposts

+@foreach($note->webmentions->filter(function ($webmention) { + return ($webmention->type == 'repost-of'); +}) as $repost)

{{ $repost['author']['properties']['name'][0] }} reposted this at {{ $repost['published'] }}.

@endforeach +@endif