Make some tweaks around dealing with replies
This commit is contained in:
parent
4bea97df0c
commit
6c43363c78
7 changed files with 100 additions and 74 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
]
|
||||
);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,7 @@
|
|||
generating a name property for the h-feed -->
|
||||
<span class="p-name"></span>
|
||||
@foreach ($notes as $note)
|
||||
<div class="h-entry">
|
||||
@include('templates.note', ['note' => $note])
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
{!! $notes->render() !!}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
@section('title'){{ strip_tags($note->getOriginal('note')) }} « Notes « @stop
|
||||
|
||||
@section('content')
|
||||
<div class="h-entry">
|
||||
@include('templates.note', ['note' => $note])
|
||||
@foreach($note->webmentions->filter(function ($webmention) {
|
||||
return ($webmention->type == 'in-reply-to');
|
||||
|
@ -49,7 +48,6 @@
|
|||
@endif
|
||||
<!-- this empty tags are for https://brid.gy’s publishing service -->
|
||||
<a href="https://brid.gy/publish/twitter"></a>
|
||||
</div>
|
||||
@stop
|
||||
|
||||
@section('scripts')
|
||||
|
|
|
@ -1,19 +1,30 @@
|
|||
@if ($note->twitter)
|
||||
<div class="h-entry">
|
||||
@if ($note->twitter)
|
||||
{!! $note->twitter->html !!}
|
||||
@elseif ($note->in_reply_to)
|
||||
<div class="p-in-reply-to h-cite reply-to">
|
||||
@elseif ($note->in_reply_to)
|
||||
<div class="u-in-reply-to h-cite reply-to">
|
||||
In reply to <a href="{{ $note->in_reply_to }}" class="u-url">{{ $note->in_reply_to }}</a>
|
||||
</div>
|
||||
@endif
|
||||
@endif
|
||||
<div class="note">
|
||||
<div class="e-content p-name">
|
||||
{!! $note->note !!}
|
||||
@foreach($note->media as $media)
|
||||
@if($media->type === 'image') <a class="naked-link" href="{{ $media->url }}"><img class="u-photo" src="{{ $media->url }}" alt="" @if($media->image_widths !== null) srcset="{{ $media->url }} {{ $media->image_widths }}w, {{ $media->mediumurl }} 1000w, {{ $media->smallurl }} 500w" sizes="80vh"@endif></a>@endif
|
||||
@if($media->type === 'audio') <audio class="u-audio" src="{{ $media->url }}" controls>@endif
|
||||
@if($media->type === 'video') <video class="u-video" src="{{ $media->url }}" controls>@endif
|
||||
@if($media->type === 'download') <p><a class="u-attachment" href="{{ $media->url }}">Download the attached media</a></p>@endif
|
||||
@endforeach
|
||||
@foreach($note->media as $media)
|
||||
@if($media->type === 'image')
|
||||
<a class="naked-link" href="{{ $media->url }}">
|
||||
<img class="u-photo" src="{{ $media->url }}" alt="" @if($media->image_widths !== null) srcset="{{ $media->url }} {{ $media->image_widths }}w, {{ $media->mediumurl }} 1000w, {{ $media->smallurl }} 500w" sizes="80vh"@endif>
|
||||
</a>
|
||||
@endif
|
||||
@if($media->type === 'audio')
|
||||
<audio class="u-audio" src="{{ $media->url }}" controls>
|
||||
@endif
|
||||
@if($media->type === 'video')
|
||||
<video class="u-video" src="{{ $media->url }}" controls>
|
||||
@endif
|
||||
@if($media->type === 'download')
|
||||
<p><a class="u-attachment" href="{{ $media->url }}">Download the attached media</a></p>
|
||||
@endif
|
||||
@endforeach
|
||||
</div>
|
||||
@if ($note->twitter_content)
|
||||
<div class="p-bridgy-twitter-content">
|
||||
|
@ -22,18 +33,26 @@
|
|||
@endif
|
||||
<div class="note-metadata">
|
||||
<div>
|
||||
<a class="u-url" href="/notes/{{ $note->nb60id }}"><time class="dt-published" datetime="{{ $note->iso8601 }}" title="{{ $note->iso8601 }}">{{ $note->humandiff }}</time></a>@if($note->client) via <a class="client" href="{{ $note->client->client_url }}">{{ $note->client->client_name }}</a>@endif
|
||||
@if($note->place)@if($note->getOriginal('note')) in <span class="p-location h-card"><a class="p-name u-url" href="{{ $note->place->longurl }}">{{ $note->address }}</a><data class="p-latitude" value="{{ $note->place->latitude }}"></data><data class="p-longitude" value="{{ $note->place->longitude }}"></data></span>@endif
|
||||
@elseif($note->address) in <span class="p-location h-adr">{!! $note->address !!}<data class="p-latitude" value="{{ $note->latitude }}"></data><data class="p-longitude" value="{{ $note->longitude }}"></data></span>@endif
|
||||
|
||||
<a class="u-url" href="/notes/{{ $note->nb60id }}">
|
||||
<time class="dt-published" datetime="{{ $note->iso8601 }}" title="{{ $note->iso8601 }}">{{ $note->humandiff }}</time>
|
||||
</a>
|
||||
@if($note->client) via <a class="client" href="{{ $note->client->client_url }}">{{ $note->client->client_name }}</a>@endif
|
||||
@if($note->place)
|
||||
@if($note->getOriginal('note'))
|
||||
in <span class="p-location h-card"><a class="p-name u-url" href="{{ $note->place->longurl }}">{{ $note->address }}</a><data class="p-latitude" value="{{ $note->place->latitude }}"></data><data class="p-longitude" value="{{ $note->place->longitude }}"></data></span>
|
||||
@endif
|
||||
@elseif($note->address)
|
||||
in <span class="p-location h-adr">{!! $note->address !!}<data class="p-latitude" value="{{ $note->latitude }}"></data><data class="p-longitude" value="{{ $note->longitude }}"></data></span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="syndication-links">
|
||||
@if(
|
||||
@if(
|
||||
$note->tweet_id ||
|
||||
$note->facebook_url ||
|
||||
$note->swarm_url ||
|
||||
$note->instagram_url ||
|
||||
$note->mastodon_url)
|
||||
$note->mastodon_url
|
||||
)
|
||||
@include('templates.social-links', [
|
||||
'tweet_id' => $note->tweet_id,
|
||||
'facebook_url' => $note->facebook_url,
|
||||
|
@ -41,15 +60,16 @@
|
|||
'instagram_url' => $note->instagram_url,
|
||||
'mastodon_url' => $note->mastodon_url,
|
||||
])
|
||||
@endif
|
||||
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@if ($note->place)
|
||||
@if ($note->place)
|
||||
<div class="map"
|
||||
data-latitude="{{ $note->place->latitude }}"
|
||||
data-longitude="{{ $note->place->longitude }}"
|
||||
data-name="{{ $note->place->name }}"
|
||||
data-marker="{{ $note->place->icon }}"></div>
|
||||
@endif
|
||||
data-marker="{{ $note->place->icon }}"
|
||||
></div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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 = <<<JSON
|
||||
|
|
Loading…
Add table
Reference in a new issue