diff --git a/app/Jobs/SendWebMentions.php b/app/Jobs/SendWebMentions.php index 92267d18..dcdd4237 100644 --- a/app/Jobs/SendWebMentions.php +++ b/app/Jobs/SendWebMentions.php @@ -6,8 +6,8 @@ namespace App\Jobs; use App\Models\Note; use GuzzleHttp\Client; +use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Psr7\Header; -use GuzzleHttp\Psr7\Uri; use GuzzleHttp\Psr7\UriResolver; use GuzzleHttp\Psr7\Utils; use Illuminate\Bus\Queueable; @@ -22,8 +22,7 @@ class SendWebMentions implements ShouldQueue use Queueable; use SerializesModels; - /** @var Note */ - protected $note; + protected Note $note; /** * Create the job instance, inject dependencies. @@ -39,15 +38,14 @@ class SendWebMentions implements ShouldQueue * Execute the job. * * @return void + * + * @throws GuzzleException */ - public function handle() + public function handle(): void { - //grab the URLs - $inReplyTo = $this->note->in_reply_to ?? ''; - // above so explode doesn’t complain about null being passed in - $urlsInReplyTo = explode(' ', $inReplyTo); + $urlsInReplyTo = explode(' ', $this->note->in_reply_to ?? ''); $urlsNote = $this->getLinks($this->note->note); - $urls = array_filter(array_merge($urlsInReplyTo, $urlsNote)); //filter out none URLs + $urls = array_filter(array_merge($urlsInReplyTo, $urlsNote)); foreach ($urls as $url) { $endpoint = $this->discoverWebmentionEndpoint($url); if ($endpoint !== null) { @@ -67,10 +65,12 @@ class SendWebMentions implements ShouldQueue * * @param string $url * @return string|null + * + * @throws GuzzleException */ public function discoverWebmentionEndpoint(string $url): ?string { - //let’s not send webmentions to myself + // let’s not send webmentions to myself if (parse_url($url, PHP_URL_HOST) === config('app.longurl')) { return null; } @@ -80,6 +80,7 @@ class SendWebMentions implements ShouldQueue $endpoint = null; + /** @var Client $guzzle */ $guzzle = resolve(Client::class); $response = $guzzle->get($url); //check HTTP Headers for webmention endpoint @@ -134,8 +135,6 @@ class SendWebMentions implements ShouldQueue /** * Resolve a URI if necessary. * - * @todo Update deprecated resolve method - * * @param string $url * @param string $base The base of the URL * @return string diff --git a/app/Services/NoteService.php b/app/Services/NoteService.php index a37b917f..049ae8c6 100644 --- a/app/Services/NoteService.php +++ b/app/Services/NoteService.php @@ -28,7 +28,7 @@ class NoteService extends Service $note = Note::create( [ 'note' => $this->getDataByKey($request, 'content'), - 'in_reply_to' => $this->getDataByKey($request, 'in-reploy-to'), + 'in_reply_to' => $this->getDataByKey($request, 'in-reply-to'), 'client_id' => $client, ] ); diff --git a/database/seeders/NotesTableSeeder.php b/database/seeders/NotesTableSeeder.php index 4a0a0bec..7218b219 100644 --- a/database/seeders/NotesTableSeeder.php +++ b/database/seeders/NotesTableSeeder.php @@ -212,6 +212,17 @@ EOF; ->where('id', $noteWithLongUrl->id) ->update(['updated_at' => $now->toDateTimeString()]); + $now = Carbon::now(); + $noteReplyingToMastodon = Note::create([ + 'note' => 'Yup, #DevOps is hard', + 'in_reply_to' => 'https://mastodon.social/@Gargron/109381161123311795', + 'created_at' => $now, + 'client_id' => 'https://quill.p3k.io/', + ]); + DB::table('notes') + ->where('id', $noteReplyingToMastodon->id) + ->update(['updated_at' => $now->toDateTimeString()]); + Note::factory(10)->create(); } } diff --git a/resources/views/notes/index.blade.php b/resources/views/notes/index.blade.php index 6205b6fc..2f32b411 100644 --- a/resources/views/notes/index.blade.php +++ b/resources/views/notes/index.blade.php @@ -8,9 +8,7 @@ generating a name property for the h-feed --> @foreach ($notes as $note) -
- @include('templates.note', ['note' => $note]) -
+ @include('templates.note', ['note' => $note]) @endforeach {!! $notes->render() !!} diff --git a/resources/views/notes/show.blade.php b/resources/views/notes/show.blade.php index 459cf5d5..94cea5c5 100644 --- a/resources/views/notes/show.blade.php +++ b/resources/views/notes/show.blade.php @@ -3,7 +3,6 @@ @section('title'){{ strip_tags($note->getOriginal('note')) }} « Notes « @stop @section('content') -
@include('templates.note', ['note' => $note]) @foreach($note->webmentions->filter(function ($webmention) { return ($webmention->type == 'in-reply-to'); @@ -49,7 +48,6 @@ @endif -
@stop @section('scripts') diff --git a/resources/views/templates/note.blade.php b/resources/views/templates/note.blade.php index 3e0c542d..de6aea62 100644 --- a/resources/views/templates/note.blade.php +++ b/resources/views/templates/note.blade.php @@ -1,55 +1,75 @@ -@if ($note->twitter) - {!! $note->twitter->html !!} -@elseif ($note->in_reply_to) -
- In reply to {{ $note->in_reply_to }} -
-@endif -
-
- {!! $note->note !!} -@foreach($note->media as $media) -@if($media->type === 'image') image_widths !== null) srcset="{{ $media->url }} {{ $media->image_widths }}w, {{ $media->mediumurl }} 1000w, {{ $media->smallurl }} 500w" sizes="80vh"@endif>@endif -@if($media->type === 'audio')
- @if ($note->twitter_content) -
- {!! $note->twitter_content !!} -
- @endif -
-
- @if($note->client) via {{ $note->client->client_name }}@endif -@if($note->place)@if($note->getOriginal('note')) in {{ $note->address }}@endif -@elseif($note->address) in {!! $note->address !!}@endif - -
- -
-@if ($note->place) -
-@endif -
+
+ @if ($note->twitter) + {!! $note->twitter->html !!} + @elseif ($note->in_reply_to) +
+ In reply to {{ $note->in_reply_to }} +
+ @endif +
+
+ {!! $note->note !!} + @foreach($note->media as $media) + @if($media->type === 'image') + + image_widths !== null) srcset="{{ $media->url }} {{ $media->image_widths }}w, {{ $media->mediumurl }} 1000w, {{ $media->smallurl }} 500w" sizes="80vh"@endif> + + @endif + @if($media->type === 'audio') +
+ @if ($note->twitter_content) +
+ {!! $note->twitter_content !!} +
+ @endif + + @if ($note->place) +
+ @endif +
+
diff --git a/tests/Unit/NotesTest.php b/tests/Unit/NotesTest.php index 098516b9..841841ff 100644 --- a/tests/Unit/NotesTest.php +++ b/tests/Unit/NotesTest.php @@ -257,7 +257,7 @@ class NotesTest extends TestCase /** @test */ public function reverseGeocodeACounty(): void { - // Note I’ve removed everything below county to test for querires where + // Note I’ve removed everything below county to test for queries where // that’s all that is returned // phpcs:disable Generic.Files.LineLength.TooLong $json = <<