Merge pull request #833 from jonnybarnes/793-remove-activitystreams-support
Remove activity stream functionality from controllers and providers
This commit is contained in:
commit
d7258d0ee3
5 changed files with 0 additions and 140 deletions
|
@ -7,7 +7,6 @@ use App\Models\Bio;
|
|||
use App\Models\Bookmark;
|
||||
use App\Models\Like;
|
||||
use App\Models\Note;
|
||||
use App\Services\ActivityStreamsService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\View\View;
|
||||
|
@ -19,10 +18,6 @@ class FrontPageController extends Controller
|
|||
*/
|
||||
public function index(Request $request): Response|View
|
||||
{
|
||||
if ($request->wantsActivityStream()) {
|
||||
return (new ActivityStreamsService())->siteOwnerResponse();
|
||||
}
|
||||
|
||||
$notes = Note::latest()->with(['media', 'client', 'place'])->get();
|
||||
$articles = Article::latest()->get();
|
||||
$bookmarks = Bookmark::latest()->get();
|
||||
|
|
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Note;
|
||||
use App\Services\ActivityStreamsService;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
@ -23,10 +22,6 @@ class NotesController extends Controller
|
|||
*/
|
||||
public function index(Request $request): View|Response
|
||||
{
|
||||
if ($request->wantsActivityStream()) {
|
||||
return (new ActivityStreamsService())->siteOwnerResponse();
|
||||
}
|
||||
|
||||
$notes = Note::latest()
|
||||
->with('place', 'media', 'client')
|
||||
->withCount(['webmentions As replies' => function ($query) {
|
||||
|
@ -47,10 +42,6 @@ class NotesController extends Controller
|
|||
abort(404);
|
||||
}
|
||||
|
||||
if (request()->wantsActivityStream()) {
|
||||
return (new ActivityStreamsService())->singleNoteResponse($note);
|
||||
}
|
||||
|
||||
return view('notes.show', compact('note'));
|
||||
}
|
||||
|
||||
|
|
|
@ -8,11 +8,9 @@ use Codebird\Codebird;
|
|||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Middleware;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Dusk\DuskServiceProvider;
|
||||
use Lcobucci\JWT\Configuration;
|
||||
use Lcobucci\JWT\Signer\Hmac\Sha256;
|
||||
|
@ -30,11 +28,6 @@ class AppServiceProvider extends ServiceProvider
|
|||
{
|
||||
Note::observe(NoteObserver::class);
|
||||
|
||||
// Request AS macro
|
||||
Request::macro('wantsActivityStream', function () {
|
||||
return Str::contains(mb_strtolower($this->header('Accept')), 'application/activity+json');
|
||||
});
|
||||
|
||||
// configure Intervention/Image
|
||||
$this->app->bind('Intervention\Image\ImageManager', function () {
|
||||
return new \Intervention\Image\ImageManager(['driver' => config('image.driver')]);
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Note;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class ActivityStreamsService
|
||||
{
|
||||
/**
|
||||
* Return the relevant data to an AS2.0 request to the root path.
|
||||
*/
|
||||
public function siteOwnerResponse(): Response
|
||||
{
|
||||
$data = json_encode([
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => config('app.url'),
|
||||
'type' => 'Person',
|
||||
'name' => config('user.displayname'),
|
||||
'preferredUsername' => config('user.username'),
|
||||
]);
|
||||
|
||||
return response($data)->header('Content-Type', 'application/activity+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the relevant data to an AS2.0 request for a particular note.
|
||||
*/
|
||||
public function singleNoteResponse(Note $note): Response
|
||||
{
|
||||
$data = json_encode([
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'summary' => strtok(config('user.displayname'), ' ') . ' added a note to their microblog',
|
||||
'type' => 'Add',
|
||||
'published' => $note->updated_at->toW3cString(),
|
||||
'actor' => [
|
||||
'type' => 'Person',
|
||||
'id' => config('app.url'),
|
||||
'name' => config('app.display_name'),
|
||||
'url' => config('app.url'),
|
||||
'image' => [
|
||||
'type' => 'Link',
|
||||
'href' => config('app.url') . '/assets/img/profile.jpg',
|
||||
'mediaType' => '/image/jpeg',
|
||||
],
|
||||
],
|
||||
'object' => [
|
||||
'id' => $note->longurl,
|
||||
'type' => 'Note',
|
||||
'url' => $note->longurl,
|
||||
'name' => strip_tags($note->note),
|
||||
],
|
||||
]);
|
||||
|
||||
return response($data)->header('Content-Type', 'application/activity+json');
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Note;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ActivityStreamTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/** @test */
|
||||
public function homepageRequestReturnsDataForSiteOwner(): void
|
||||
{
|
||||
$response = $this->get('/', ['Accept' => 'application/activity+json']);
|
||||
$response->assertHeader('Content-Type', 'application/activity+json');
|
||||
$response->assertJson([
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => config('app.url'),
|
||||
'type' => 'Person',
|
||||
'name' => config('user.displayname'),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function notesPageContainsAuthorActivityStreamData(): void
|
||||
{
|
||||
$response = $this->get('/notes', ['Accept' => 'application/activity+json']);
|
||||
$response->assertHeader('Content-Type', 'application/activity+json');
|
||||
$response->assertJson([
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => config('app.url'),
|
||||
'type' => 'Person',
|
||||
'name' => config('user.displayname'),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function requestForNoteIncludesActivityStreamData(): void
|
||||
{
|
||||
$note = Note::factory()->create();
|
||||
$response = $this->get($note->longurl, ['Accept' => 'application/activity+json']);
|
||||
$response->assertHeader('Content-Type', 'application/activity+json');
|
||||
$response->assertJson([
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'type' => 'Add',
|
||||
'actor' => [
|
||||
'type' => 'Person',
|
||||
'id' => config('app.url'),
|
||||
],
|
||||
'object' => [
|
||||
'type' => 'Note',
|
||||
'name' => strip_tags($note->note),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue