pixelfed/app/Http/Controllers/GroupFederationController.php

109 wiersze
3.7 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Group;
use App\Models\GroupPost;
use App\Models\InstanceActor;
use App\Services\MediaService;
use App\Status;
use App\Util\Lexer\Autolink;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class GroupFederationController extends Controller
{
public function getGroupObject(Request $request, $id)
{
$group = Group::whereLocal(true)->whereActivitypub(true)->findOrFail($id);
$res = $this->showGroupObject($group);
return response()->json($res, 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
}
public function showGroupObject($group)
{
return Cache::remember('ap:groups:object:'.$group->id, 3600, function () use ($group) {
return [
'@context' => 'https://www.w3.org/ns/activitystreams',
'id' => $group->url(),
'inbox' => $group->permalink('/inbox'),
'name' => $group->name,
'outbox' => $group->permalink('/outbox'),
'summary' => $group->description,
'type' => 'Group',
'attributedTo' => [
'type' => 'Person',
'id' => $group->admin->permalink(),
],
// 'endpoints' => [
// 'sharedInbox' => config('app.url') . '/f/inbox'
// ],
'preferredUsername' => 'gid_'.$group->id,
'publicKey' => [
'id' => $group->permalink('#main-key'),
'owner' => $group->permalink(),
'publicKeyPem' => InstanceActor::first()->public_key,
],
'url' => $group->permalink(),
];
Staging (#6343) * Prepared new docker * Docker setup improvements and fixes * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update .dockerignore * DB/Redis health check * updated health checks * updated install guide * updated DOCKER_SETUP * Updated DOCKER_SETUP * Updated DOCKER_SETUP * Update and rename DOCKER_SETUP.md to DOCKER_COMPOSE_SETUP.md * RemoveUnreachableStatementRector * Update GroupActivityPubService.php * Larastan: Add @property * Delete rector.php * more properties * 2fa_enabled needs to be refactored * Fix AdminUser.php syntax error - remove invalid property declaration * Update AdminUser.php * update * Upgrade predis from v2.0 to v3.2 - Update predis/predis from ^2.0 to ^3.2 - Predis v3.2.0 includes RESP3 support, improved pipeline abstractions - No code changes required, configuration remains compatible - Tested successfully with tinker * Upgrade predis from v2.0 to v3.2 * Update * Update .env.docker.example * Update DOCKER_COMPOSE_SETUP.md * Create ImageDriverManager.php * Update image.php * Update ImageResizePipeline.php * Update StoryComposeController.php * Update AvatarOptimize.php * Update Image.php * Update composer.json * Update AvatarOptimize.php * update lock * Update composer.lock * update * update * update * Allow to set new image types in admin interface * Update composer, fix deps * Update composer --------- Co-authored-by: Shlee <github@shl.ee> Co-authored-by: Your Name <you@example.com> Co-authored-by: Severin <savewish@icloud.com>
2025-11-14 05:16:16 +00:00
//Dead - after a return
// if ($group->metadata && isset($group->metadata['avatar'])) {
// $res['icon'] = [
// 'type' => 'Image',
// 'url' => $group->metadata['avatar']['url'],
// ];
// }
Staging (#6343) * Prepared new docker * Docker setup improvements and fixes * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update .dockerignore * DB/Redis health check * updated health checks * updated install guide * updated DOCKER_SETUP * Updated DOCKER_SETUP * Updated DOCKER_SETUP * Update and rename DOCKER_SETUP.md to DOCKER_COMPOSE_SETUP.md * RemoveUnreachableStatementRector * Update GroupActivityPubService.php * Larastan: Add @property * Delete rector.php * more properties * 2fa_enabled needs to be refactored * Fix AdminUser.php syntax error - remove invalid property declaration * Update AdminUser.php * update * Upgrade predis from v2.0 to v3.2 - Update predis/predis from ^2.0 to ^3.2 - Predis v3.2.0 includes RESP3 support, improved pipeline abstractions - No code changes required, configuration remains compatible - Tested successfully with tinker * Upgrade predis from v2.0 to v3.2 * Update * Update .env.docker.example * Update DOCKER_COMPOSE_SETUP.md * Create ImageDriverManager.php * Update image.php * Update ImageResizePipeline.php * Update StoryComposeController.php * Update AvatarOptimize.php * Update Image.php * Update composer.json * Update AvatarOptimize.php * update lock * Update composer.lock * update * update * update * Allow to set new image types in admin interface * Update composer, fix deps * Update composer --------- Co-authored-by: Shlee <github@shl.ee> Co-authored-by: Your Name <you@example.com> Co-authored-by: Severin <savewish@icloud.com>
2025-11-14 05:16:16 +00:00
// if ($group->metadata && isset($group->metadata['header'])) {
// $res['image'] = [
// 'type' => 'Image',
// 'url' => $group->metadata['header']['url'],
// ];
// }
// ksort($res);
Staging (#6343) * Prepared new docker * Docker setup improvements and fixes * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update DOCKER_SETUP.md * Update .dockerignore * DB/Redis health check * updated health checks * updated install guide * updated DOCKER_SETUP * Updated DOCKER_SETUP * Updated DOCKER_SETUP * Update and rename DOCKER_SETUP.md to DOCKER_COMPOSE_SETUP.md * RemoveUnreachableStatementRector * Update GroupActivityPubService.php * Larastan: Add @property * Delete rector.php * more properties * 2fa_enabled needs to be refactored * Fix AdminUser.php syntax error - remove invalid property declaration * Update AdminUser.php * update * Upgrade predis from v2.0 to v3.2 - Update predis/predis from ^2.0 to ^3.2 - Predis v3.2.0 includes RESP3 support, improved pipeline abstractions - No code changes required, configuration remains compatible - Tested successfully with tinker * Upgrade predis from v2.0 to v3.2 * Update * Update .env.docker.example * Update DOCKER_COMPOSE_SETUP.md * Create ImageDriverManager.php * Update image.php * Update ImageResizePipeline.php * Update StoryComposeController.php * Update AvatarOptimize.php * Update Image.php * Update composer.json * Update AvatarOptimize.php * update lock * Update composer.lock * update * update * update * Allow to set new image types in admin interface * Update composer, fix deps * Update composer --------- Co-authored-by: Shlee <github@shl.ee> Co-authored-by: Your Name <you@example.com> Co-authored-by: Severin <savewish@icloud.com>
2025-11-14 05:16:16 +00:00
// return $res;
});
}
public function getStatusObject(Request $request, $gid, $sid)
{
$group = Group::whereLocal(true)->whereActivitypub(true)->findOrFail($gid);
$gp = GroupPost::whereGroupId($gid)->findOrFail($sid);
$status = Status::findOrFail($gp->status_id);
// permission check
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
$res = [
'@context' => 'https://www.w3.org/ns/activitystreams',
'id' => $gp->url(),
'type' => 'Note',
'summary' => null,
'content' => $content,
'inReplyTo' => null,
'published' => $status->created_at->toAtomString(),
'url' => $gp->url(),
'attributedTo' => $status->profile->permalink(),
'to' => [
'https://www.w3.org/ns/activitystreams#Public',
$group->permalink('/followers'),
],
'cc' => [],
'sensitive' => (bool) $status->is_nsfw,
'attachment' => MediaService::activitypub($status->id),
'target' => [
'type' => 'Collection',
'id' => $group->permalink('/wall'),
'attributedTo' => $group->permalink(),
],
];
// ksort($res);
return response()->json($res, 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
}
}