Merge pull request #755 from jonnybarnes/753-remove-twitter-posse-support
Remove Twitter POSSE support
This commit is contained in:
commit
b862186a4f
15 changed files with 1 additions and 365 deletions
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Bookmark;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SyndicateBookmarkToTwitter implements ShouldQueue
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithQueue;
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(
|
||||
protected Bookmark $bookmark
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function handle(Client $guzzle): void
|
||||
{
|
||||
//send webmention
|
||||
$response = $guzzle->request(
|
||||
'POST',
|
||||
'https://brid.gy/publish/webmention',
|
||||
[
|
||||
'form_params' => [
|
||||
'source' => $this->bookmark->longurl,
|
||||
'target' => 'https://brid.gy/publish/twitter',
|
||||
'bridgy_omit_link' => 'maybe',
|
||||
],
|
||||
]
|
||||
);
|
||||
//parse for syndication URL
|
||||
if ($response->getStatusCode() === 201) {
|
||||
$json = json_decode((string) $response->getBody());
|
||||
$syndicates = $this->bookmark->syndicates;
|
||||
$syndicates['twitter'] = $json->url;
|
||||
$this->bookmark->syndicates = $syndicates;
|
||||
$this->bookmark->save();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Note;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SyndicateNoteToTwitter implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue;
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(
|
||||
protected Note $note
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function handle(Client $guzzle)
|
||||
{
|
||||
//send webmention
|
||||
$response = $guzzle->request(
|
||||
'POST',
|
||||
'https://brid.gy/publish/webmention',
|
||||
[
|
||||
'form_params' => [
|
||||
'source' => $this->note->longurl,
|
||||
'target' => 'https://brid.gy/publish/twitter',
|
||||
'bridgy_omit_link' => 'maybe',
|
||||
],
|
||||
]
|
||||
);
|
||||
//parse for syndication URL
|
||||
if ($response->getStatusCode() == 201) {
|
||||
$json = json_decode((string) $response->getBody());
|
||||
$tweet_id = basename(parse_url($json->url, PHP_URL_PATH));
|
||||
$this->note->tweet_id = $tweet_id;
|
||||
$this->note->save();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -279,50 +279,6 @@ class Note extends Model
|
|||
return $oEmbed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a specific form of the note for twitter.
|
||||
*
|
||||
* That is we swap the contacts names for their known Twitter handles.
|
||||
*/
|
||||
public function getTwitterContentAttribute(): string
|
||||
{
|
||||
$this->getContacts();
|
||||
|
||||
// check for contacts
|
||||
if ($this->contacts === null || count($this->contacts) === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// here we check the matched contact from the note corresponds to a contact
|
||||
// in the database
|
||||
if (
|
||||
count(array_unique(array_values($this->contacts))) === 1
|
||||
&& array_unique(array_values($this->contacts))[0] === null
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// swap in Twitter usernames
|
||||
$swapped = preg_replace_callback(
|
||||
self::USERNAMES_REGEX,
|
||||
function ($matches) {
|
||||
if (is_null($this->contacts[$matches[1]])) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
$contact = $this->contacts[$matches[1]];
|
||||
if ($contact->twitter) {
|
||||
return '@' . $contact->twitter;
|
||||
}
|
||||
|
||||
return $contact->name;
|
||||
},
|
||||
$this->getRawOriginal('note')
|
||||
);
|
||||
|
||||
return $this->convertMarkdown($swapped);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to select a note via a NewBase60 id.
|
||||
*/
|
||||
|
|
|
@ -6,9 +6,7 @@ namespace App\Services;
|
|||
|
||||
use App\Exceptions\InternetArchiveException;
|
||||
use App\Jobs\ProcessBookmark;
|
||||
use App\Jobs\SyndicateBookmarkToTwitter;
|
||||
use App\Models\Bookmark;
|
||||
use App\Models\SyndicationTarget;
|
||||
use App\Models\Tag;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
|
@ -47,23 +45,6 @@ class BookmarkService extends Service
|
|||
$bookmark->tags()->save($tag);
|
||||
}
|
||||
|
||||
$mpSyndicateTo = null;
|
||||
if (Arr::get($request, 'mp-syndicate-to')) {
|
||||
$mpSyndicateTo = Arr::get($request, 'mp-syndicate-to');
|
||||
}
|
||||
if (Arr::get($request, 'properties.mp-syndicate-to')) {
|
||||
$mpSyndicateTo = Arr::get($request, 'properties.mp-syndicate-to');
|
||||
}
|
||||
$mpSyndicateTo = Arr::wrap($mpSyndicateTo);
|
||||
foreach ($mpSyndicateTo as $uid) {
|
||||
$target = SyndicationTarget::where('uid', $uid)->first();
|
||||
if ($target && $target->service_name === 'Twitter') {
|
||||
SyndicateBookmarkToTwitter::dispatch($bookmark);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ProcessBookmark::dispatch($bookmark);
|
||||
|
||||
return $bookmark;
|
||||
|
|
|
@ -6,7 +6,6 @@ namespace App\Services;
|
|||
|
||||
use App\Jobs\SendWebMentions;
|
||||
use App\Jobs\SyndicateNoteToMastodon;
|
||||
use App\Jobs\SyndicateNoteToTwitter;
|
||||
use App\Models\Media;
|
||||
use App\Models\Note;
|
||||
use App\Models\Place;
|
||||
|
@ -50,11 +49,6 @@ class NoteService extends Service
|
|||
|
||||
dispatch(new SendWebMentions($note));
|
||||
|
||||
// Syndication targets
|
||||
if (in_array('twitter', $this->getSyndicationTargets($request), true)) {
|
||||
dispatch(new SyndicateNoteToTwitter($note));
|
||||
}
|
||||
|
||||
if (in_array('mastodon', $this->getSyndicationTargets($request), true)) {
|
||||
dispatch(new SyndicateNoteToMastodon($note));
|
||||
}
|
||||
|
|
|
@ -4,7 +4,4 @@
|
|||
|
||||
@section('content')
|
||||
@include('templates.like', ['like' => $like])
|
||||
|
||||
<!-- POSSE to Twitter -->
|
||||
<a href="https://brid.gy/publish/twitter"></a>
|
||||
@stop
|
||||
|
|
|
@ -46,8 +46,6 @@
|
|||
</p>
|
||||
@endforeach
|
||||
@endif
|
||||
<!-- this empty tags are for https://brid.gy’s publishing service -->
|
||||
<a href="https://brid.gy/publish/twitter"></a>
|
||||
@stop
|
||||
|
||||
@section('scripts')
|
||||
|
|
|
@ -26,7 +26,4 @@
|
|||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
<p class="p-bridgy-twitter-content">🔖 {{ $bookmark->url }} 🔗 {{ $bookmark->longurl }}</p>
|
||||
<!-- these empty tags are for https://brid.gy’s publishing service -->
|
||||
<a href="https://brid.gy/publish/twitter"></a>
|
||||
</div>
|
||||
|
|
|
@ -26,11 +26,6 @@
|
|||
@endif
|
||||
@endforeach
|
||||
</div>
|
||||
@if ($note->twitter_content)
|
||||
<div class="p-bridgy-twitter-content">
|
||||
{!! $note->twitter_content !!}
|
||||
</div>
|
||||
@endif
|
||||
<div class="note-metadata">
|
||||
<div>
|
||||
<a class="u-url" href="/notes/{{ $note->nb60id }}">
|
||||
|
|
|
@ -5,9 +5,7 @@ declare(strict_types=1);
|
|||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\ProcessBookmark;
|
||||
use App\Jobs\SyndicateBookmarkToTwitter;
|
||||
use App\Models\Bookmark;
|
||||
use App\Models\SyndicationTarget;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Tests\TestCase;
|
||||
|
@ -37,25 +35,16 @@ class BookmarksTest extends TestCase
|
|||
{
|
||||
Queue::fake();
|
||||
|
||||
SyndicationTarget::factory()->create([
|
||||
'uid' => 'https://twitter.com/jonnybarnes',
|
||||
'service_name' => 'Twitter',
|
||||
]);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'Authorization' => 'Bearer ' . $this->getToken(),
|
||||
])->post('/api/post', [
|
||||
'h' => 'entry',
|
||||
'bookmark-of' => 'https://example.org/blog-post',
|
||||
'mp-syndicate-to' => [
|
||||
'https://twitter.com/jonnybarnes',
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertJson(['response' => 'created']);
|
||||
|
||||
Queue::assertPushed(ProcessBookmark::class);
|
||||
Queue::assertPushed(SyndicateBookmarkToTwitter::class);
|
||||
$this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']);
|
||||
}
|
||||
|
||||
|
@ -64,52 +53,18 @@ class BookmarksTest extends TestCase
|
|||
{
|
||||
Queue::fake();
|
||||
|
||||
SyndicationTarget::factory()->create([
|
||||
'uid' => 'https://twitter.com/jonnybarnes',
|
||||
'service_name' => 'Twitter',
|
||||
]);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'Authorization' => 'Bearer ' . $this->getToken(),
|
||||
])->json('POST', '/api/post', [
|
||||
'type' => ['h-entry'],
|
||||
'properties' => [
|
||||
'bookmark-of' => ['https://example.org/blog-post'],
|
||||
'mp-syndicate-to' => [
|
||||
'https://twitter.com/jonnybarnes',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertJson(['response' => 'created']);
|
||||
|
||||
Queue::assertPushed(ProcessBookmark::class);
|
||||
Queue::assertPushed(SyndicateBookmarkToTwitter::class);
|
||||
$this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function whenTheBookmarkIsMarkedForPostingToTwitterCheckWeInvokeTheCorrectJob(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
SyndicationTarget::factory()->create([
|
||||
'uid' => 'https://twitter.com/jonnybarnes',
|
||||
'service_name' => 'Twitter',
|
||||
]);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'Authorization' => 'Bearer ' . $this->getToken(),
|
||||
])->post('/api/post', [
|
||||
'h' => 'entry',
|
||||
'bookmark-of' => 'https://example.org/blog-post',
|
||||
'mp-syndicate-to' => 'https://twitter.com/jonnybarnes',
|
||||
]);
|
||||
|
||||
$response->assertJson(['response' => 'created']);
|
||||
|
||||
Queue::assertPushed(ProcessBookmark::class);
|
||||
Queue::assertPushed(SyndicateBookmarkToTwitter::class);
|
||||
$this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Contact;
|
||||
use App\Models\Note;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BridgyPosseTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/** @test */
|
||||
public function notesWeWantCopiedToTwitterShouldHaveNecessaryMarkup(): void
|
||||
{
|
||||
Contact::factory()->create([
|
||||
'nick' => 'joe',
|
||||
'twitter' => 'joe__',
|
||||
]);
|
||||
$note = Note::factory()->create(['note' => 'Hi @joe']);
|
||||
|
||||
$response = $this->get($note->longurl);
|
||||
|
||||
$html = $response->content();
|
||||
$this->assertStringContainsString('Hi @joe__', $html);
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@ namespace Tests\Feature;
|
|||
|
||||
use App\Jobs\SendWebMentions;
|
||||
use App\Jobs\SyndicateNoteToMastodon;
|
||||
use App\Jobs\SyndicateNoteToTwitter;
|
||||
use App\Models\Media;
|
||||
use App\Models\Note;
|
||||
use App\Models\Place;
|
||||
|
@ -145,7 +144,6 @@ class MicropubControllerTest extends TestCase
|
|||
'h' => 'entry',
|
||||
'content' => $note,
|
||||
'mp-syndicate-to' => [
|
||||
'https://twitter.com/jonnybarnes',
|
||||
'https://mastodon.social/@jonnybarnes',
|
||||
],
|
||||
],
|
||||
|
@ -153,7 +151,6 @@ class MicropubControllerTest extends TestCase
|
|||
);
|
||||
$response->assertJson(['response' => 'created']);
|
||||
$this->assertDatabaseHas('notes', ['note' => $note]);
|
||||
Queue::assertPushed(SyndicateNoteToTwitter::class);
|
||||
Queue::assertPushed(SyndicateNoteToMastodon::class);
|
||||
}
|
||||
|
||||
|
@ -248,10 +245,6 @@ class MicropubControllerTest extends TestCase
|
|||
'path' => 'test-photo.jpg',
|
||||
'type' => 'image',
|
||||
]);
|
||||
SyndicationTarget::factory()->create([
|
||||
'uid' => 'https://twitter.com/jonnybarnes',
|
||||
'service_name' => 'Twitter',
|
||||
]);
|
||||
SyndicationTarget::factory()->create([
|
||||
'uid' => 'https://mastodon.social/@jonnybarnes',
|
||||
'service_name' => 'Mastodon',
|
||||
|
@ -267,7 +260,6 @@ class MicropubControllerTest extends TestCase
|
|||
'content' => [$note],
|
||||
'in-reply-to' => ['https://aaronpk.localhost'],
|
||||
'mp-syndicate-to' => [
|
||||
'https://twitter.com/jonnybarnes',
|
||||
'https://mastodon.social/@jonnybarnes',
|
||||
],
|
||||
'photo' => [config('filesystems.disks.s3.url') . '/test-photo.jpg'],
|
||||
|
@ -279,7 +271,6 @@ class MicropubControllerTest extends TestCase
|
|||
->assertStatus(201)
|
||||
->assertJson(['response' => 'created']);
|
||||
Queue::assertPushed(SendWebMentions::class);
|
||||
Queue::assertPushed(SyndicateNoteToTwitter::class);
|
||||
Queue::assertPushed(SyndicateNoteToMastodon::class);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ class NotesControllerTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function unknownNoteGives404()
|
||||
public function unknownNoteGives404(): void
|
||||
{
|
||||
$response = $this->get('/notes/112233');
|
||||
$response->assertNotFound();
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use App\Jobs\SyndicateBookmarkToTwitter;
|
||||
use App\Models\Bookmark;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SyndicateBookmarkToTwitterJobTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/** @test */
|
||||
public function weSendBookmarksToTwitter(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$randomNumber = $faker->randomNumber();
|
||||
$json = json_encode([
|
||||
'url' => 'https://twitter.com/' . $randomNumber,
|
||||
]);
|
||||
$mock = new MockHandler([
|
||||
new Response(201, ['Content-Type' => 'application/json'], $json),
|
||||
]);
|
||||
$handler = HandlerStack::create($mock);
|
||||
$client = new Client(['handler' => $handler]);
|
||||
|
||||
$bookmark = Bookmark::factory()->create();
|
||||
$job = new SyndicateBookmarkToTwitter($bookmark);
|
||||
$job->handle($client);
|
||||
|
||||
$this->assertDatabaseHas('bookmarks', [
|
||||
'syndicates' => '{"twitter": "https://twitter.com/' . $randomNumber . '"}',
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use App\Jobs\SyndicateNoteToTwitter;
|
||||
use App\Models\Note;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SyndicateNoteToTwitterJobTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/** @test */
|
||||
public function weSyndicateNotesToTwitter(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
$randomNumber = $faker->randomNumber();
|
||||
$json = json_encode([
|
||||
'url' => 'https://twitter.com/i/web/status/' . $randomNumber,
|
||||
]);
|
||||
$mock = new MockHandler([
|
||||
new Response(201, ['Content-Type' => 'application/json'], $json),
|
||||
]);
|
||||
$handler = HandlerStack::create($mock);
|
||||
$client = new Client(['handler' => $handler]);
|
||||
|
||||
$note = Note::factory()->create();
|
||||
$job = new SyndicateNoteToTwitter($note);
|
||||
$job->handle($client);
|
||||
|
||||
$this->assertDatabaseHas('notes', [
|
||||
'tweet_id' => $randomNumber,
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue