. /** * ActivityPub implementation for GNU social * * @package GNUsocial * @author Diogo Cordeiro * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ defined('GNUSOCIAL') || die(); /** * ActivityPub direct note representation * * @author Bruno Casteleiro * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ class Activitypub_message { /** * Generates a pretty message from a Notice object * * @param Notice $message * @return array array to be used in a response * @author Bruno Casteleiro */ public static function message_to_array(Notice $message): array { $from = $message->getProfile(); $tags = []; foreach ($message->getTags() as $tag) { if ($tag != '') { // Hacky workaround to avoid stupid outputs $tags[] = Activitypub_tag::tag_to_array($tag); } } $to = []; foreach ($message->getAttentionProfiles() as $to_profile) { $to[] = $href = $to_profile->getUri(); $tags[] = Activitypub_mention_tag::mention_tag_to_array_from_values($href, $to_profile->getNickname().'@'.parse_url($href, PHP_URL_HOST)); } $item = [ '@context' => 'https://www.w3.org/ns/activitystreams', 'id' => common_local_url('showmessage', ['message' => $message->getID()]), 'type' => 'Note', 'published' => str_replace(' ', 'T', $message->created).'Z', 'attributedTo' => $from->getUri(), 'to' => $to, 'cc' => [], 'content' => $message->getRendered(), 'attachment' => [], 'tag' => $tags ]; return $item; } /** * Create a private Notice via ActivityPub Note Object. * Returns created Notice. * * @author Bruno Casteleiro * @param array $object * @param Profile $actor_profile * @return Notice * @throws Exception */ public static function create_message(array $object, Profile $actor_profile = null): Notice { return Activitypub_notice::create_notice($object, $actor_profile, true); } }