2021-08-25 04:29:26 +09:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2021-08-25 04:29:26 +09:00
|
|
|
// {{{ License
|
|
|
|
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
namespace Plugin\ActivityPub\Controller;
|
|
|
|
|
|
|
|
use App\Core\Controller;
|
|
|
|
use App\Core\DB\DB;
|
|
|
|
use function App\Core\I18n\_m;
|
|
|
|
use App\Util\Exception\ClientException;
|
|
|
|
use Plugin\ActivityPub\ActivityPub;
|
2021-10-05 01:00:58 +09:00
|
|
|
use Plugin\ActivityPub\Util\Model\AS2ToEntity\AS2ToEntity;
|
|
|
|
use Plugin\ActivityPub\Util\Response\TypeResponse;
|
|
|
|
use Plugin\ActivityPub\Util\Type;
|
|
|
|
use Plugin\ActivityPub\Util\Type\Util;
|
2021-08-25 04:29:26 +09:00
|
|
|
|
|
|
|
class Inbox extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Inbox handler
|
|
|
|
*/
|
2021-10-18 21:22:02 +09:00
|
|
|
public function handle(?int $gsactor_id = null): TypeResponse
|
2021-08-25 04:29:26 +09:00
|
|
|
{
|
2021-10-10 17:26:18 +09:00
|
|
|
if (!\is_null($gsactor_id)) {
|
2021-09-21 01:03:23 +09:00
|
|
|
$user = DB::find('local_user', ['id' => $gsactor_id]);
|
2021-10-10 17:26:18 +09:00
|
|
|
if (\is_null($user)) {
|
2021-09-21 01:03:23 +09:00
|
|
|
throw new ClientException(_m('No such actor.'), 404);
|
|
|
|
}
|
2021-08-25 04:29:26 +09:00
|
|
|
}
|
|
|
|
|
2021-10-05 01:00:58 +09:00
|
|
|
// TODO: Check if Actor can post
|
2021-08-25 04:29:26 +09:00
|
|
|
|
|
|
|
// Get content
|
|
|
|
$payload = Util::decodeJson(
|
2021-10-10 17:26:18 +09:00
|
|
|
(string) $this->request->getContent(),
|
2021-08-25 04:29:26 +09:00
|
|
|
);
|
|
|
|
|
|
|
|
// Cast as an ActivityStreams type
|
|
|
|
$type = Type::create($payload);
|
|
|
|
|
2021-10-05 01:00:58 +09:00
|
|
|
// TODO: Check if Actor has authority over payload
|
|
|
|
|
|
|
|
// Store Activity
|
2021-11-28 00:06:46 +09:00
|
|
|
$ap_act = AS2ToEntity::store(activity: $type->toArray(), source: 'ActivityPub');
|
2021-10-05 01:00:58 +09:00
|
|
|
DB::flush();
|
2021-11-28 00:06:46 +09:00
|
|
|
dd($ap_act, $act = $ap_act->getActivity(), $act->getActor(), $act->getObject());
|
2021-08-25 04:29:26 +09:00
|
|
|
|
|
|
|
return new TypeResponse($type, status: 202);
|
|
|
|
}
|
|
|
|
}
|