From 7c559860dc4cd0fbaaad81c435f2f072b73e43b8 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Fri, 12 Oct 2018 18:49:08 +0100 Subject: [PATCH 1/3] Squashed commit of the following: commit c0f71111d6a73da0a4ffd123b03dcade03b6742d Author: Jonny Barnes Date: Fri Oct 12 18:48:45 2018 +0100 Remove facebook as a syndication target, update twitter profile image --- config/syndication.php | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/config/syndication.php b/config/syndication.php index 18f3d755..5d3b2389 100644 --- a/config/syndication.php +++ b/config/syndication.php @@ -19,21 +19,8 @@ return [ 'user' => [ 'name' => 'jonnybarnes', 'url' => 'https://twitter.com/jonnybarnes', - 'photo' => 'https://pbs.twimg.com/profile_images/1853565405/jmb-bw.jpg', + 'photo' => 'https://pbs.twimg.com/profile_images/875422855932121089/W628ZI8w_400x400.jpg', ], ], - [ - 'uid' => 'https://facebook.com/jonnybarnes', - 'name' => 'jonnybarnes on Facebook', - 'service' => [ - 'name' => 'Facebook', - 'url' => 'https://facebook.com', - 'photo' => 'https://en.facebookbrand.com/wp-content/uploads/2016/05/FB-fLogo-Blue-broadcast-2.png', - ], - 'user' => [ - 'name' => 'jonnybarnes', - 'url' => 'https://facebook.com/jonnybarnes', - ], - ] ] ]; From 151072cd1b02c563616c57f3269e49fc7c27718a Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Fri, 12 Oct 2018 19:38:08 +0100 Subject: [PATCH 2/3] Squashed commit of the following: commit 63912e4c20fc9b3d49670a0f547137d59aaa2ef4 Author: Jonny Barnes Date: Fri Oct 12 19:18:21 2018 +0100 Remove facebook syndication code --- app/Jobs/SyndicateBookmarkToFacebook.php | 59 ------------------- app/Jobs/SyndicateNoteToFacebook.php | 56 ------------------ app/Models/Note.php | 44 -------------- app/Services/BookmarkService.php | 7 --- app/Services/NoteService.php | 11 +--- tests/Feature/BookmarksTest.php | 24 -------- tests/Feature/BridgyPosseTest.php | 8 --- tests/Feature/MicropubControllerTest.php | 30 ---------- .../SyndicateBookmarkToFacebookJobTest.php | 38 ------------ .../Jobs/SyndicateNoteToFacebookJobTest.php | 38 ------------ 10 files changed, 1 insertion(+), 314 deletions(-) delete mode 100644 app/Jobs/SyndicateBookmarkToFacebook.php delete mode 100644 app/Jobs/SyndicateNoteToFacebook.php delete mode 100644 tests/Unit/Jobs/SyndicateBookmarkToFacebookJobTest.php delete mode 100644 tests/Unit/Jobs/SyndicateNoteToFacebookJobTest.php diff --git a/app/Jobs/SyndicateBookmarkToFacebook.php b/app/Jobs/SyndicateBookmarkToFacebook.php deleted file mode 100644 index 973ea249..00000000 --- a/app/Jobs/SyndicateBookmarkToFacebook.php +++ /dev/null @@ -1,59 +0,0 @@ -bookmark = $bookmark; - } - - /** - * Execute the job. - * - * @param \GuzzleHttp\Client $guzzle - */ - public function handle(Client $guzzle) - { - //send webmention - $response = $guzzle->request( - 'POST', - 'https://brid.gy/publish/webmention', - [ - 'form_params' => [ - 'source' => $this->bookmark->longurl, - 'target' => 'https://brid.gy/publish/facebook', - 'bridgy_omit_link' => 'maybe', - ], - ] - ); - //parse for syndication URL - if ($response->getStatusCode() == 201) { - $json = json_decode((string) $response->getBody()); - $syndicates = $this->bookmark->syndicates; - $syndicates['facebook'] = $json->url; - $this->bookmark->syndicates = $syndicates; - $this->bookmark->save(); - } - } -} diff --git a/app/Jobs/SyndicateNoteToFacebook.php b/app/Jobs/SyndicateNoteToFacebook.php deleted file mode 100644 index 74cda117..00000000 --- a/app/Jobs/SyndicateNoteToFacebook.php +++ /dev/null @@ -1,56 +0,0 @@ -note = $note; - } - - /** - * Execute the job. - * - * @param \GuzzleHttp\Client $guzzle - */ - 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/facebook', - 'bridgy_omit_link' => 'maybe', - ], - ] - ); - //parse for syndication URL - if ($response->getStatusCode() == 201) { - $json = json_decode((string) $response->getBody()); - $this->note->facebook_url = $json->url; - $this->note->save(); - } - } -} diff --git a/app/Models/Note.php b/app/Models/Note.php index 8ed7f9c1..81053f85 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -400,50 +400,6 @@ class Note extends Model return $this->convertMarkdown($swapped); } - /** - * Show a specific form of the note for Facebook. - * - * That is we swap the contacts names for their known Facebook usernames. - * - * @return string|null - */ - public function getFacebookContentAttribute(): ?string - { - if ($this->contacts === null) { - return null; - } - - if (count($this->contacts) === 0) { - return null; - } - - if (count(array_unique(array_values($this->contacts))) === 1 - && array_unique(array_values($this->contacts))[0] === null) { - return null; - } - - // swap in facebook 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->facebook) { - return '' . $contact->name . ''; - } - - return $contact->name; - }, - $this->getOriginal('note') - ); - - return $this->convertMarkdown($swapped); - } - /** * Scope a query to select a note via a NewBase60 id. * diff --git a/app/Services/BookmarkService.php b/app/Services/BookmarkService.php index f05d6a1e..abadd633 100644 --- a/app/Services/BookmarkService.php +++ b/app/Services/BookmarkService.php @@ -11,7 +11,6 @@ use App\Jobs\ProcessBookmark; use App\Models\{Bookmark, Tag}; use Spatie\Browsershot\Browsershot; use App\Jobs\SyndicateBookmarkToTwitter; -use App\Jobs\SyndicateBookmarkToFacebook; use GuzzleHttp\Exception\ClientException; use App\Exceptions\InternetArchiveException; @@ -63,9 +62,6 @@ class BookmarkService if ($service == 'Twitter') { SyndicateBookmarkToTwitter::dispatch($bookmark); } - if ($service == 'Facebook') { - SyndicateBookmarkToFacebook::dispatch($bookmark); - } } if (is_array($mpSyndicateTo)) { foreach ($mpSyndicateTo as $uid) { @@ -73,9 +69,6 @@ class BookmarkService if ($service == 'Twitter') { SyndicateBookmarkToTwitter::dispatch($bookmark); } - if ($service == 'Facebook') { - SyndicateBookmarkToFacebook::dispatch($bookmark); - } } } diff --git a/app/Services/NoteService.php b/app/Services/NoteService.php index eb3e25a0..476c5b2b 100644 --- a/app/Services/NoteService.php +++ b/app/Services/NoteService.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace App\Services; use App\Models\{Media, Note, Place}; -use App\Jobs\{SendWebMentions, SyndicateNoteToFacebook, SyndicateNoteToTwitter}; +use App\Jobs\{SendWebMentions, SyndicateNoteToTwitter}; class NoteService { @@ -52,9 +52,6 @@ class NoteService if (in_array('twitter', $this->getSyndicationTargets($request))) { dispatch(new SyndicateNoteToTwitter($note)); } - if (in_array('facebook', $this->getSyndicationTargets($request))) { - dispatch(new SyndicateNoteToFacebook($note)); - } } return $note; @@ -211,9 +208,6 @@ class NoteService if ($service == 'Twitter') { $syndication[] = 'twitter'; } - if ($service == 'Facebook') { - $syndication[] = 'facebook'; - } } if (is_array($mpSyndicateTo)) { foreach ($mpSyndicateTo as $uid) { @@ -221,9 +215,6 @@ class NoteService if ($service == 'Twitter') { $syndication[] = 'twitter'; } - if ($service == 'Facebook') { - $syndication[] = 'facebook'; - } } } diff --git a/tests/Feature/BookmarksTest.php b/tests/Feature/BookmarksTest.php index 3ec9c6e6..7b7521bc 100644 --- a/tests/Feature/BookmarksTest.php +++ b/tests/Feature/BookmarksTest.php @@ -7,7 +7,6 @@ use Tests\TestToken; use App\Jobs\ProcessBookmark; use Illuminate\Support\Facades\Queue; use App\Jobs\SyndicateBookmarkToTwitter; -use App\Jobs\SyndicateBookmarkToFacebook; use Illuminate\Foundation\Testing\DatabaseTransactions; class BookmarksTest extends TestCase @@ -37,7 +36,6 @@ class BookmarksTest extends TestCase 'bookmark-of' => 'https://example.org/blog-post', 'mp-syndicate-to' => [ 'https://twitter.com/jonnybarnes', - 'https://facebook.com/jonnybarnes', ], ]); @@ -45,7 +43,6 @@ class BookmarksTest extends TestCase Queue::assertPushed(ProcessBookmark::class); Queue::assertPushed(SyndicateBookmarkToTwitter::class); - Queue::assertPushed(SyndicateBookmarkToFacebook::class); $this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']); } @@ -61,7 +58,6 @@ class BookmarksTest extends TestCase 'bookmark-of' => ['https://example.org/blog-post'], 'mp-syndicate-to' => [ 'https://twitter.com/jonnybarnes', - 'https://facebook.com/jonnybarnes', ], ], ]); @@ -70,7 +66,6 @@ class BookmarksTest extends TestCase Queue::assertPushed(ProcessBookmark::class); Queue::assertPushed(SyndicateBookmarkToTwitter::class); - Queue::assertPushed(SyndicateBookmarkToFacebook::class); $this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']); } @@ -93,25 +88,6 @@ class BookmarksTest extends TestCase $this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']); } - public function test_single_facebook_syndication_target_causes_job_dispatch_http_post_syntax() - { - Queue::fake(); - - $response = $this->withHeaders([ - 'Authorization' => 'Bearer ' . $this->getToken(), - ])->post('/api/post', [ - 'h' => 'entry', - 'bookmark-of' => 'https://example.org/blog-post', - 'mp-syndicate-to' => 'https://facebook.com/jonnybarnes', - ]); - - $response->assertJson(['response' => 'created']); - - Queue::assertPushed(ProcessBookmark::class); - Queue::assertPushed(SyndicateBookmarkToFacebook::class); - $this->assertDatabaseHas('bookmarks', ['url' => 'https://example.org/blog-post']); - } - public function test_tags_created_with_new_bookmark() { Queue::fake(); diff --git a/tests/Feature/BridgyPosseTest.php b/tests/Feature/BridgyPosseTest.php index ed191b33..7adcaf5e 100644 --- a/tests/Feature/BridgyPosseTest.php +++ b/tests/Feature/BridgyPosseTest.php @@ -13,12 +13,4 @@ class BridgyPosseTest extends TestCase $html = $response->content(); $this->assertTrue(is_string(mb_stristr($html, 'p-bridgy-twitter-content'))); } - - public function test_bridgy_facebook_content() - { - $response = $this->get('/notes/E'); - - $html = $response->content(); - $this->assertTrue(is_string(mb_stristr($html, 'p-bridgy-facebook-content'))); - } } diff --git a/tests/Feature/MicropubControllerTest.php b/tests/Feature/MicropubControllerTest.php index d9891d1b..2c138e10 100644 --- a/tests/Feature/MicropubControllerTest.php +++ b/tests/Feature/MicropubControllerTest.php @@ -12,7 +12,6 @@ use App\Models\{Media, Place}; use Illuminate\Http\UploadedFile; use App\Jobs\SyndicateNoteToTwitter; use Lcobucci\JWT\Signer\Hmac\Sha256; -use App\Jobs\SyndicateNoteToFacebook; use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Storage; use Phaza\LaravelPostgis\Geometries\Point; @@ -169,33 +168,6 @@ class MicropubControllerTest extends TestCase Queue::assertPushed(SyndicateNoteToTwitter::class); } - /** - * Test a valid micropub requests creates a new note and syndicates to Facebook. - * - * @return void - */ - public function test_micropub_post_request_creates_new_note_sends_to_facebook() - { - Queue::fake(); - $faker = \Faker\Factory::create(); - $note = $faker->text; - $response = $this->call( - 'POST', - '/api/post', - [ - 'h' => 'entry', - 'content' => $note, - 'mp-syndicate-to' => 'https://facebook.com/jonnybarnes' - ], - [], - [], - ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] - ); - $response->assertJson(['response' => 'created']); - $this->assertDatabaseHas('notes', ['note' => $note]); - Queue::assertPushed(SyndicateNoteToFacebook::class); - } - /** * Test a valid micropub requests creates a new place. * @@ -320,7 +292,6 @@ class MicropubControllerTest extends TestCase 'in-reply-to' => ['https://aaronpk.localhost'], 'mp-syndicate-to' => [ 'https://twitter.com/jonnybarnes', - 'https://facebook.com/jonnybarnes', ], 'photo' => [config('filesystems.disks.s3.url') . '/test-photo.jpg'], ], @@ -332,7 +303,6 @@ class MicropubControllerTest extends TestCase ->assertJson(['response' => 'created']); Queue::assertPushed(SendWebMentions::class); Queue::assertPushed(SyndicateNoteToTwitter::class); - Queue::assertPushed(SyndicateNoteToFacebook::class); } /** diff --git a/tests/Unit/Jobs/SyndicateBookmarkToFacebookJobTest.php b/tests/Unit/Jobs/SyndicateBookmarkToFacebookJobTest.php deleted file mode 100644 index 682af20d..00000000 --- a/tests/Unit/Jobs/SyndicateBookmarkToFacebookJobTest.php +++ /dev/null @@ -1,38 +0,0 @@ - 'https://facebook.com/123' - ]); - $mock = new MockHandler([ - new Response(201, ['Content-Type' => 'application/json'], $json), - ]); - $handler = HandlerStack::create($mock); - $client = new Client(['handler' => $handler]); - - $bookmark = Bookmark::find(1); - $job = new SyndicateBookmarkToFacebook($bookmark); - $job->handle($client); - - $this->assertDatabaseHas('bookmarks', [ - 'id' => 1, - 'syndicates' => '{"facebook": "https://facebook.com/123"}', - ]); - } -} diff --git a/tests/Unit/Jobs/SyndicateNoteToFacebookJobTest.php b/tests/Unit/Jobs/SyndicateNoteToFacebookJobTest.php deleted file mode 100644 index 80c7801d..00000000 --- a/tests/Unit/Jobs/SyndicateNoteToFacebookJobTest.php +++ /dev/null @@ -1,38 +0,0 @@ - 'https://facebook.com/123' - ]); - $mock = new MockHandler([ - new Response(201, ['Content-Type' => 'application/json'], $json), - ]); - $handler = HandlerStack::create($mock); - $client = new Client(['handler' => $handler]); - - $note = Note::find(1); - $job = new SyndicateNoteToFacebook($note); - $job->handle($client); - - $this->assertDatabaseHas('notes', [ - 'id' => 1, - 'facebook_url' => 'https://facebook.com/123', - ]); - } -} From ed39a9e44495f927e61aa9a3dd69449d44b7c9ad Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Fri, 12 Oct 2018 19:47:52 +0100 Subject: [PATCH 3/3] Update changelog --- changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.md b/changelog.md index 61e8dc64..ded152ad 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## Version 0.17.1 (2018-10-12) + - Remove settinga and code for syndicatong to Facebook (issue#88) + ## Version 0.17 - Update the underlying Laravel framework to release 5.7