forked from GNUsocial/gnu-social
[ActivityPub][Model][Activity] Translate including objects
This commit is contained in:
parent
e7ee558f4a
commit
6f543ccc06
@ -14,18 +14,11 @@ use App\Entity\Activity;
|
||||
use App\Entity\Actor;
|
||||
use App\Entity\LocalUser;
|
||||
use App\Util\Common;
|
||||
use App\Util\Exception\NicknameEmptyException;
|
||||
use App\Util\Exception\NicknameException;
|
||||
use App\Util\Exception\NicknameInvalidException;
|
||||
use App\Util\Exception\NicknameNotAllowedException;
|
||||
use App\Util\Exception\NicknameTakenException;
|
||||
use App\Util\Exception\NicknameTooLongException;
|
||||
use App\Util\Exception\NoSuchActorException;
|
||||
use App\Util\Nickname;
|
||||
use Exception;
|
||||
use Plugin\ActivityPub\Controller\Inbox;
|
||||
use Plugin\ActivityPub\Entity\ActivitypubActor;
|
||||
use Plugin\ActivityPub\Util\Explorer;
|
||||
use Plugin\ActivityPub\Util\HTTPSignature;
|
||||
use Plugin\ActivityPub\Util\Model\EntityToType\EntityToType;
|
||||
use Plugin\ActivityPub\Util\Response\ActorResponse;
|
||||
@ -110,7 +103,8 @@ class ActivityPub extends Plugin
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
public function onAddFreeNetworkProtocol (array &$protocols): bool {
|
||||
public function onAddFreeNetworkProtocol(array &$protocols): bool
|
||||
{
|
||||
$protocols[] = '\Plugin\ActivityPub\ActivityPub';
|
||||
return Event::next;
|
||||
}
|
||||
@ -288,11 +282,11 @@ class ActivityPub extends Plugin
|
||||
}
|
||||
|
||||
/**
|
||||
* Profile URL matches: @example.com/mublog/user
|
||||
*
|
||||
* @param string $text The text from which to extract URL mentions
|
||||
* Profile URL matches: @param string $text The text from which to extract URL mentions
|
||||
* @param string $preMention Character(s) that signals a mention ('@', '!'...)
|
||||
* @return array The matching URLs (without @ or acct:) and each respective position in the given string.
|
||||
* @example.com/mublog/user
|
||||
*
|
||||
*/
|
||||
public static function extractUrlMentions(string $text, string $preMention = '@'): array
|
||||
{
|
||||
@ -317,11 +311,11 @@ class ActivityPub extends Plugin
|
||||
/**
|
||||
* Find any explicit remote mentions. Accepted forms:
|
||||
* Webfinger: @user@example.com
|
||||
* Profile link: @example.com/mublog/user
|
||||
* @param Actor $sender
|
||||
* Profile link: @param Actor $sender
|
||||
* @param string $text input markup text
|
||||
* @param $mentions
|
||||
* @return bool hook return value
|
||||
* @example.com/mublog/user
|
||||
*/
|
||||
public function onEndFindMentions(Actor $sender, string $text, array &$mentions): bool
|
||||
{
|
||||
@ -421,10 +415,10 @@ class ActivityPub extends Plugin
|
||||
/**
|
||||
* Profile from URI.
|
||||
*
|
||||
* @author GNU social
|
||||
* @param string $uri
|
||||
* @param Actor &$profile in/out param: Profile got from URI
|
||||
* @return mixed hook return code
|
||||
* @author GNU social
|
||||
*/
|
||||
//public function onStartGetProfileFromURI($uri, &$profile)
|
||||
//{
|
||||
|
@ -17,7 +17,7 @@ use Plugin\ActivityPub\Entity\ActivitypubActivity;
|
||||
|
||||
abstract class AS2ToEntity
|
||||
{
|
||||
public static function activity_stream_two_verb_to_gs_verb($verb)
|
||||
public static function activity_stream_two_verb_to_gs_verb(string $verb): string
|
||||
{
|
||||
return match ($verb) {
|
||||
'Create' => 'create',
|
||||
@ -25,7 +25,7 @@ abstract class AS2ToEntity
|
||||
};
|
||||
}
|
||||
|
||||
public static function activity_stream_two_object_type_to_gs_table($object)
|
||||
public static function activity_stream_two_object_type_to_gs_table(string $object): string
|
||||
{
|
||||
return match ($object) {
|
||||
'Note' => 'note',
|
||||
|
@ -32,9 +32,9 @@ class ActivityToType
|
||||
'id' => Router::url('activity_view', ['id' => $activity->getId()], Router::ABSOLUTE_URL),
|
||||
'published' => $activity->getCreated()->format(DateTimeInterface::RFC3339),
|
||||
'actor' => $activity->getActor()->getUri(Router::ABSOLUTE_URL),
|
||||
//'to' => $to,
|
||||
//'cc' => $cc,
|
||||
'object' => $activity->getObject()->getUrl(),
|
||||
'to' => ['https://www.w3.org/ns/activitystreams#Public'], // TODO: implement proper scope address
|
||||
'cc' => ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
'object' => EntityToType::translate($activity->getObject()),
|
||||
];
|
||||
return Type::create($attr);
|
||||
}
|
||||
|
@ -22,9 +22,9 @@ class NoteToType
|
||||
'id' => Router::url('note_view', ['id' => $note->getId()], Router::ABSOLUTE_URL),
|
||||
'published' => $note->getCreated()->format(DateTimeInterface::RFC3339),
|
||||
'attributedTo' => $note->getActor()->getUri(Router::ABSOLUTE_URL),
|
||||
//'to' => $to,
|
||||
//'cc' => $cc,
|
||||
'content' => json_encode($note->getRendered()),
|
||||
'to' => ['https://www.w3.org/ns/activitystreams#Public'], // TODO: implement proper scope address
|
||||
'cc' => ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
'content' => $note->getRendered(),
|
||||
//'tag' => $tags
|
||||
];
|
||||
return Type::create(type: 'Note', attributes: $attr);
|
||||
|
@ -260,8 +260,8 @@ abstract class AbstractObject
|
||||
public function toJson(?int $options = null): string
|
||||
{
|
||||
return json_encode(
|
||||
$this->toArray(),
|
||||
(int) $options,
|
||||
value: $this->toArray(),
|
||||
flags: (int) $options,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,8 @@ declare(strict_types = 1);
|
||||
|
||||
namespace Plugin\ActivityPub\Util\Type\Core;
|
||||
|
||||
use Plugin\ActivityPub\Util\Type;
|
||||
|
||||
/**
|
||||
* \Plugin\ActivityPub\Util\Type\Core\Activity is an implementation of one of the
|
||||
* Activity Streams Core Types.
|
||||
@ -39,5 +41,5 @@ class Activity extends AbstractActivity
|
||||
* | Link
|
||||
* | null
|
||||
*/
|
||||
protected string $object;
|
||||
protected ObjectType $object;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user