Merge pull request #5904 from annando/ap-announce
AP: Announce will now work
This commit is contained in:
commit
db0b848ae3
|
@ -46,7 +46,7 @@ if ($a->isMaxProcessesReached() || $a->isMaxLoadReached()) {
|
||||||
System::httpExit(503, ['title' => 'Error 503 - Service Temporarily Unavailable', 'description' => 'System is currently overloaded. Please try again later.']);
|
System::httpExit(503, ['title' => 'Error 503 - Service Temporarily Unavailable', 'description' => 'System is currently overloaded. Please try again later.']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strstr($a->query_string, '.well-known/host-meta') and ($a->query_string != '.well-known/host-meta')) {
|
if (strstr($a->query_string, '.well-known/host-meta') && ($a->query_string != '.well-known/host-meta')) {
|
||||||
System::httpExit(404);
|
System::httpExit(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ function crepair_content(App $a)
|
||||||
$remote_self_options = ['0' => L10n::t('No mirroring'), '2' => L10n::t('Mirror as my own posting')];
|
$remote_self_options = ['0' => L10n::t('No mirroring'), '2' => L10n::t('Mirror as my own posting')];
|
||||||
}
|
}
|
||||||
|
|
||||||
$update_profile = in_array($contact['network'], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]);
|
$update_profile = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]);
|
||||||
|
|
||||||
$tab_str = contacts_tab($a, $contact, 5);
|
$tab_str = contacts_tab($a, $contact, 5);
|
||||||
|
|
||||||
|
|
|
@ -212,8 +212,13 @@ class Processor
|
||||||
$item['content-warning'] = HTML::toBBCode($activity['summary']);
|
$item['content-warning'] = HTML::toBBCode($activity['summary']);
|
||||||
$item['body'] = self::convertMentions(HTML::toBBCode($activity['content']));
|
$item['body'] = self::convertMentions(HTML::toBBCode($activity['content']));
|
||||||
$item['location'] = $activity['location'];
|
$item['location'] = $activity['location'];
|
||||||
|
|
||||||
|
if (!empty($item['latitude']) && !empty($item['longitude'])) {
|
||||||
|
$item['coord'] = $item['latitude'] . ' ' . $item['longitude'];
|
||||||
|
}
|
||||||
|
|
||||||
$item['tag'] = self::constructTagList($activity['tags'], $activity['sensitive']);
|
$item['tag'] = self::constructTagList($activity['tags'], $activity['sensitive']);
|
||||||
$item['app'] = $activity['service'];
|
$item['app'] = $activity['generator'];
|
||||||
$item['plink'] = defaults($activity, 'alternate-url', $item['uri']);
|
$item['plink'] = defaults($activity, 'alternate-url', $item['uri']);
|
||||||
$item['diaspora_signed_text'] = defaults($activity, 'diaspora:comment', '');
|
$item['diaspora_signed_text'] = defaults($activity, 'diaspora:comment', '');
|
||||||
|
|
||||||
|
|
|
@ -513,24 +513,15 @@ class Receiver
|
||||||
private static function addActivityFields($object_data, $activity)
|
private static function addActivityFields($object_data, $activity)
|
||||||
{
|
{
|
||||||
if (!empty($activity['published']) && empty($object_data['published'])) {
|
if (!empty($activity['published']) && empty($object_data['published'])) {
|
||||||
$object_data['published'] = JsonLD::fetchElement($activity, 'published', '@value');
|
$object_data['published'] = JsonLD::fetchElement($activity, 'as:published', '@value');
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($activity['updated']) && empty($object_data['updated'])) {
|
|
||||||
$object_data['updated'] = JsonLD::fetchElement($activity, 'updated', '@value');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($activity['diaspora:guid']) && empty($object_data['diaspora:guid'])) {
|
if (!empty($activity['diaspora:guid']) && empty($object_data['diaspora:guid'])) {
|
||||||
$object_data['diaspora:guid'] = JsonLD::fetchElement($activity, 'diaspora:guid');
|
$object_data['diaspora:guid'] = JsonLD::fetchElement($activity, 'diaspora:guid');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($activity['inReplyTo']) && empty($object_data['parent-uri'])) {
|
$object_data['service'] = JsonLD::fetchElement($activity, 'as:instrument', 'as:name', '@type', 'as:Service');
|
||||||
$object_data['parent-uri'] = JsonLD::fetchElement($activity, 'inReplyTo');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($activity['instrument'])) {
|
|
||||||
$object_data['service'] = JsonLD::fetchElement($activity, 'instrument', 'name', 'type', 'Service');
|
|
||||||
}
|
|
||||||
return $object_data;
|
return $object_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -696,10 +687,13 @@ class Receiver
|
||||||
$object_data['content'] = JsonLD::fetchElement($object, 'as:content');
|
$object_data['content'] = JsonLD::fetchElement($object, 'as:content');
|
||||||
$object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/bbcode');
|
$object_data['source'] = JsonLD::fetchElement($object, 'as:source', 'as:content', 'as:mediaType', 'text/bbcode');
|
||||||
$object_data['location'] = JsonLD::fetchElement($object, 'as:location', 'as:name', '@type', 'as:Place');
|
$object_data['location'] = JsonLD::fetchElement($object, 'as:location', 'as:name', '@type', 'as:Place');
|
||||||
|
$object_data['latitude'] = JsonLD::fetchElement($object, 'as:location', 'as:latitude', '@type', 'as:Place');
|
||||||
|
$object_data['latitude'] = JsonLD::fetchElement($object_data, 'latitude', '@value');
|
||||||
|
$object_data['longitude'] = JsonLD::fetchElement($object, 'as:location', 'as:longitude', '@type', 'as:Place');
|
||||||
|
$object_data['longitude'] = JsonLD::fetchElement($object_data, 'longitude', '@value');
|
||||||
$object_data['attachments'] = self::processAttachments(JsonLD::fetchElementArray($object, 'as:attachment'));
|
$object_data['attachments'] = self::processAttachments(JsonLD::fetchElementArray($object, 'as:attachment'));
|
||||||
$object_data['tags'] = self::processTags(JsonLD::fetchElementArray($object, 'as:tag'));
|
$object_data['tags'] = self::processTags(JsonLD::fetchElementArray($object, 'as:tag'));
|
||||||
// $object_data['service'] = JsonLD::fetchElement($object, 'instrument', 'name', 'type', 'Service'); // todo
|
$object_data['generator'] = JsonLD::fetchElement($object, 'as:generator', 'as:name', '@type', 'as:Application');
|
||||||
$object_data['service'] = null;
|
|
||||||
$object_data['alternate-url'] = JsonLD::fetchElement($object, 'as:url');
|
$object_data['alternate-url'] = JsonLD::fetchElement($object, 'as:url');
|
||||||
|
|
||||||
// Special treatment for Hubzilla links
|
// Special treatment for Hubzilla links
|
||||||
|
@ -719,7 +713,7 @@ class Receiver
|
||||||
// @context, type, actor, signature, mediaType, duration, replies, icon
|
// @context, type, actor, signature, mediaType, duration, replies, icon
|
||||||
|
|
||||||
// Also missing: (Defined in the standard, but currently unused)
|
// Also missing: (Defined in the standard, but currently unused)
|
||||||
// audience, preview, endTime, startTime, generator, image
|
// audience, preview, endTime, startTime, image
|
||||||
|
|
||||||
// Data in Notes:
|
// Data in Notes:
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
*/
|
*/
|
||||||
namespace Friendica\Protocol\ActivityPub;
|
namespace Friendica\Protocol\ActivityPub;
|
||||||
|
|
||||||
|
use Friendica\BaseObject;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Util\HTTPSignature;
|
use Friendica\Util\HTTPSignature;
|
||||||
|
@ -22,22 +23,21 @@ use Friendica\Model\Profile;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Object\Image;
|
use Friendica\Object\Image;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
use Friendica\Core\Cache;
|
use Friendica\Core\Cache;
|
||||||
|
use Friendica\Util\Map;
|
||||||
|
|
||||||
|
require_once 'include/api.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ActivityPub Transmitter Protocol class
|
* @brief ActivityPub Transmitter Protocol class
|
||||||
*
|
*
|
||||||
* To-Do:
|
* To-Do:
|
||||||
*
|
*
|
||||||
* Missing object fields:
|
|
||||||
* - service (App)
|
|
||||||
* - location
|
|
||||||
*
|
|
||||||
* Missing object types:
|
* Missing object types:
|
||||||
* - Event
|
* - Event
|
||||||
*
|
*
|
||||||
* Complicated object types:
|
* Complicated object types:
|
||||||
* - Announce
|
|
||||||
* - Undo Announce
|
* - Undo Announce
|
||||||
*
|
*
|
||||||
* General:
|
* General:
|
||||||
|
@ -327,7 +327,7 @@ class Transmitter
|
||||||
foreach ($terms as $term) {
|
foreach ($terms as $term) {
|
||||||
$profile = APContact::getByURL($term['url'], false);
|
$profile = APContact::getByURL($term['url'], false);
|
||||||
if (!empty($profile) && empty($contacts[$profile['url']])) {
|
if (!empty($profile) && empty($contacts[$profile['url']])) {
|
||||||
$data['cc'][] = $profile['url'];
|
$data['to'][] = $profile['url'];
|
||||||
$contacts[$profile['url']] = $profile['url'];
|
$contacts[$profile['url']] = $profile['url'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -379,11 +379,6 @@ class Transmitter
|
||||||
}
|
}
|
||||||
DBA::close($parents);
|
DBA::close($parents);
|
||||||
|
|
||||||
if (empty($data['to'])) {
|
|
||||||
$data['to'] = $data['cc'];
|
|
||||||
$data['cc'] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,7 +462,9 @@ class Transmitter
|
||||||
*/
|
*/
|
||||||
private static function getTypeOfItem($item)
|
private static function getTypeOfItem($item)
|
||||||
{
|
{
|
||||||
if ($item['verb'] == ACTIVITY_POST) {
|
if (!empty(Diaspora::isReshare($item['body'], false))) {
|
||||||
|
$type = 'Announce';
|
||||||
|
} elseif ($item['verb'] == ACTIVITY_POST) {
|
||||||
if ($item['created'] == $item['edited']) {
|
if ($item['created'] == $item['edited']) {
|
||||||
$type = 'Create';
|
$type = 'Create';
|
||||||
} else {
|
} else {
|
||||||
|
@ -556,10 +553,14 @@ class Transmitter
|
||||||
|
|
||||||
$data['published'] = DateTimeFormat::utc($item['created'] . '+00:00', DateTimeFormat::ATOM);
|
$data['published'] = DateTimeFormat::utc($item['created'] . '+00:00', DateTimeFormat::ATOM);
|
||||||
|
|
||||||
|
$data['instrument'] = ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()];
|
||||||
|
|
||||||
$data = array_merge($data, self::createPermissionBlockForItem($item));
|
$data = array_merge($data, self::createPermissionBlockForItem($item));
|
||||||
|
|
||||||
if (in_array($data['type'], ['Create', 'Update', 'Announce', 'Delete'])) {
|
if (in_array($data['type'], ['Create', 'Update', 'Delete'])) {
|
||||||
$data['object'] = self::createNote($item);
|
$data['object'] = self::createNote($item);
|
||||||
|
} elseif ($data['type'] == 'Announce') {
|
||||||
|
$data['object'] = self::createAnnounce($item);
|
||||||
} elseif ($data['type'] == 'Undo') {
|
} elseif ($data['type'] == 'Undo') {
|
||||||
$data['object'] = self::createActivityFromItem($item_id, true);
|
$data['object'] = self::createActivityFromItem($item_id, true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -599,6 +600,40 @@ class Transmitter
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a location entry for a given item array
|
||||||
|
*
|
||||||
|
* @param array $item
|
||||||
|
*
|
||||||
|
* @return array with location array
|
||||||
|
*/
|
||||||
|
private static function createLocation($item)
|
||||||
|
{
|
||||||
|
$location = ['type' => 'Place'];
|
||||||
|
|
||||||
|
if (!empty($item['location'])) {
|
||||||
|
$location['name'] = $item['location'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$coord = [];
|
||||||
|
|
||||||
|
if (empty($item['coord'])) {
|
||||||
|
$coord = Map::getCoordinates($item['location']);
|
||||||
|
} else {
|
||||||
|
$coords = explode(' ', $item['coord']);
|
||||||
|
if (count($coords) == 2) {
|
||||||
|
$coord = ['lat' => $coords[0], 'lon' => $coords[1]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($coord['lat']) && !empty($coord['lon'])) {
|
||||||
|
$location['latitude'] = $coord['lat'];
|
||||||
|
$location['longitude'] = $coord['lon'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $location;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a tag array for a given item array
|
* Returns a tag array for a given item array
|
||||||
*
|
*
|
||||||
|
@ -800,11 +835,37 @@ class Transmitter
|
||||||
|
|
||||||
$data['attachment'] = self::createAttachmentList($item, $type);
|
$data['attachment'] = self::createAttachmentList($item, $type);
|
||||||
$data['tag'] = self::createTagList($item);
|
$data['tag'] = self::createTagList($item);
|
||||||
|
|
||||||
|
if (!empty($item['coord']) || !empty($item['location'])) {
|
||||||
|
$data['location'] = self::createLocation($item);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($item['app'])) {
|
||||||
|
$data['generator'] = ['type' => 'Application', 'name' => $item['app']];
|
||||||
|
}
|
||||||
|
|
||||||
$data = array_merge($data, self::createPermissionBlockForItem($item));
|
$data = array_merge($data, self::createPermissionBlockForItem($item));
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an announce object entry
|
||||||
|
*
|
||||||
|
* @param array $item
|
||||||
|
*
|
||||||
|
* @return string with announced object url
|
||||||
|
*/
|
||||||
|
public static function createAnnounce($item)
|
||||||
|
{
|
||||||
|
$announce = api_share_as_retweet($item);
|
||||||
|
if (empty($announce['plink'])) {
|
||||||
|
return self::createNote($item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $announce['plink'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transmits a contact suggestion to a given inbox
|
* Transmits a contact suggestion to a given inbox
|
||||||
*
|
*
|
||||||
|
@ -825,7 +886,7 @@ class Transmitter
|
||||||
'actor' => $owner['url'],
|
'actor' => $owner['url'],
|
||||||
'object' => $suggestion['url'],
|
'object' => $suggestion['url'],
|
||||||
'content' => $suggestion['note'],
|
'content' => $suggestion['note'],
|
||||||
'published' => DateTimeFormat::utc($suggestion['created'] . '+00:00', DateTimeFormat::ATOM),
|
'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
|
||||||
'to' => [ActivityPub::PUBLIC_COLLECTION],
|
'to' => [ActivityPub::PUBLIC_COLLECTION],
|
||||||
'cc' => []];
|
'cc' => []];
|
||||||
|
|
||||||
|
@ -852,6 +913,7 @@ class Transmitter
|
||||||
'actor' => $owner['url'],
|
'actor' => $owner['url'],
|
||||||
'object' => $owner['url'],
|
'object' => $owner['url'],
|
||||||
'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
|
'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
|
||||||
|
'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
|
||||||
'to' => [ActivityPub::PUBLIC_COLLECTION],
|
'to' => [ActivityPub::PUBLIC_COLLECTION],
|
||||||
'cc' => []];
|
'cc' => []];
|
||||||
|
|
||||||
|
@ -878,6 +940,7 @@ class Transmitter
|
||||||
'actor' => $owner['url'],
|
'actor' => $owner['url'],
|
||||||
'object' => self::getProfile($uid),
|
'object' => self::getProfile($uid),
|
||||||
'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
|
'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
|
||||||
|
'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
|
||||||
'to' => [$profile['followers']],
|
'to' => [$profile['followers']],
|
||||||
'cc' => []];
|
'cc' => []];
|
||||||
|
|
||||||
|
@ -905,6 +968,7 @@ class Transmitter
|
||||||
'type' => $activity,
|
'type' => $activity,
|
||||||
'actor' => $owner['url'],
|
'actor' => $owner['url'],
|
||||||
'object' => $profile['url'],
|
'object' => $profile['url'],
|
||||||
|
'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
|
||||||
'to' => $profile['url']];
|
'to' => $profile['url']];
|
||||||
|
|
||||||
logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG);
|
logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG);
|
||||||
|
@ -932,6 +996,7 @@ class Transmitter
|
||||||
'object' => ['id' => $id, 'type' => 'Follow',
|
'object' => ['id' => $id, 'type' => 'Follow',
|
||||||
'actor' => $profile['url'],
|
'actor' => $profile['url'],
|
||||||
'object' => $owner['url']],
|
'object' => $owner['url']],
|
||||||
|
'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
|
||||||
'to' => $profile['url']];
|
'to' => $profile['url']];
|
||||||
|
|
||||||
logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
|
logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
|
||||||
|
@ -959,6 +1024,7 @@ class Transmitter
|
||||||
'object' => ['id' => $id, 'type' => 'Follow',
|
'object' => ['id' => $id, 'type' => 'Follow',
|
||||||
'actor' => $profile['url'],
|
'actor' => $profile['url'],
|
||||||
'object' => $owner['url']],
|
'object' => $owner['url']],
|
||||||
|
'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
|
||||||
'to' => $profile['url']];
|
'to' => $profile['url']];
|
||||||
|
|
||||||
logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
|
logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
|
||||||
|
@ -987,6 +1053,7 @@ class Transmitter
|
||||||
'object' => ['id' => $id, 'type' => 'Follow',
|
'object' => ['id' => $id, 'type' => 'Follow',
|
||||||
'actor' => $owner['url'],
|
'actor' => $owner['url'],
|
||||||
'object' => $profile['url']],
|
'object' => $profile['url']],
|
||||||
|
'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
|
||||||
'to' => $profile['url']];
|
'to' => $profile['url']];
|
||||||
|
|
||||||
logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
|
logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user