use Friendica\Util\JsonLD;
use Friendica\Core\Config;
use Friendica\Protocol\ActivityPub;
+use Friendica\Util\DateTimeFormat;
/**
* ActivityPub Processor Protocol class
return $item;
}
+ /**
+ * Updates a message
+ *
+ * @param array $activity Activity array
+ */
+ public static function updateItem($activity)
+ {
+ $item = [];
+ $item['changed'] = DateTimeFormat::utcNow();
+ $item['edited'] = $activity['updated'];
+ $item['title'] = HTML::toBBCode($activity['name']);
+ $item['content-warning'] = HTML::toBBCode($activity['summary']);
+ $item['body'] = self::convertMentions(HTML::toBBCode($activity['content']));
+ $item['tag'] = self::constructTagList($activity['tags'], $activity['sensitive']);
+
+ Item::update($item, ['uri' => $activity['id']]);
+ }
+
/**
* Prepares data for a message
*
self::postItem($activity, $item);
}
- /**
- * Prepare the item array for a "like"
- *
- * @param array $activity Activity array
- */
- public static function likeItem($activity)
- {
- $item = [];
- $item['verb'] = ACTIVITY_LIKE;
- $item['parent-uri'] = $activity['object_id'];
- $item['gravity'] = GRAVITY_ACTIVITY;
- $item['object-type'] = ACTIVITY_OBJ_NOTE;
-
- self::postItem($activity, $item);
- }
-
/**
* Delete items
*
}
/**
- * Prepare the item array for a "dislike"
+ * Prepare the item array for an activity
*
* @param array $activity Activity array
+ * @param string $verb Activity verb
*/
- public static function dislikeItem($activity)
+ public static function createActivity($activity, $verb)
{
$item = [];
- $item['verb'] = ACTIVITY_DISLIKE;
+ $item['verb'] = $verb;
$item['parent-uri'] = $activity['object_id'];
$item['gravity'] = GRAVITY_ACTIVITY;
$item['object-type'] = ACTIVITY_OBJ_NOTE;
/**
* Create an event
*
- * @param array $activity Activity array
+ * @param array $activity Activity array
+ * @param array $item
*/
public static function createEvent($activity, $item)
{
* @brief ActivityPub Receiver Protocol class
*
* To-Do:
- * - Update (Image, Video, Article, Note)
* - Undo Announce
- * - Accept Event
- * - Reject Event
- * - TentativeAccept Even
- * - Undo Accept Event
- * - Undo Reject Event
- * - Undo TentativeAccept Event
*
* Check what this is meant to do:
* - Add
* - Flag
* - Remove
* - Undo Block
- * - Undo Accept Person
*/
class Receiver
{
*/
private static function fetchObjectType($activity, $object_id)
{
-
- $object_type = JsonLD::fetchElement($activity['as:object'], '@type');
- if (!empty($object_type)) {
- return $object_type;
+ if (!empty($activity['as:object'])) {
+ $object_type = JsonLD::fetchElement($activity['as:object'], '@type');
+ if (!empty($object_type)) {
+ return $object_type;
+ }
}
if (Item::exists(['uri' => $object_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) {
$object_type = self::fetchObjectType($activity, $object_id);
// Fetch the content only on activities where this matters
- if (in_array($type, ['as:Create', 'as:Announce'])) {
+ if (in_array($type, ['as:Create', 'as:Update', 'as:Announce'])) {
if ($type == 'as:Announce') {
$trust_source = false;
}
$object_data['object_actor'] = JsonLD::fetchElement($activity['as:object'], 'as:actor');
$object_data['object_object'] = JsonLD::fetchElement($activity['as:object'], 'as:object');
$object_data['object_type'] = JsonLD::fetchElement($activity['as:object'], '@type');
+
+ // An Undo is done on the object of an object, so we need that type as well
+ if ($type == 'as:Undo') {
+ $object_data['object_object_type'] = self::fetchObjectType([], $object_data['object_object']);
+ }
}
$object_data = self::addActivityFields($object_data, $activity);
switch ($type) {
case 'as:Create':
case 'as:Announce':
- ActivityPub\Processor::createItem($object_data);
+ if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
+ ActivityPub\Processor::createItem($object_data);
+ }
break;
case 'as:Like':
- ActivityPub\Processor::likeItem($object_data);
+ if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
+ ActivityPub\Processor::createActivity($object_data, ACTIVITY_LIKE);
+ }
break;
case 'as:Dislike':
- ActivityPub\Processor::dislikeItem($object_data);
+ if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
+ ActivityPub\Processor::createActivity($object_data, ACTIVITY_DISLIKE);
+ }
+ break;
+
+ case 'as:TentativeAccept':
+ if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
+ ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTENDMAYBE);
+ }
break;
case 'as:Update':
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
- /// @todo
+ ActivityPub\Processor::updateItem($object_data);
} elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
ActivityPub\Processor::updatePerson($object_data, $body);
}
break;
case 'as:Follow':
- ActivityPub\Processor::followUser($object_data);
+ if (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
+ ActivityPub\Processor::followUser($object_data);
+ }
break;
case 'as:Accept':
if ($object_data['object_type'] == 'as:Follow') {
ActivityPub\Processor::acceptFollowUser($object_data);
+ } elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
+ ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTEND);
}
break;
case 'as:Reject':
if ($object_data['object_type'] == 'as:Follow') {
ActivityPub\Processor::rejectFollowUser($object_data);
+ } elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
+ ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTENDNO);
}
break;
case 'as:Undo':
- if ($object_data['object_type'] == 'as:Follow') {
+ if (($object_data['object_type'] == 'as:Follow') &&
+ in_array($object_data['object_object_type'], self::ACCOUNT_TYPES)) {
ActivityPub\Processor::undoFollowUser($object_data);
- } elseif (in_array($object_data['object_type'], self::ACTIVITY_TYPES)) {
+ } elseif (($object_data['object_type'] == 'as:Accept') &&
+ in_array($object_data['object_object_type'], self::ACCOUNT_TYPES)) {
+ ActivityPub\Processor::rejectFollowUser($object_data);
+ } elseif (in_array($object_data['object_type'], self::ACTIVITY_TYPES) &&
+ in_array($object_data['object_object_type'], self::CONTENT_TYPES)) {
ActivityPub\Processor::undoActivity($object_data);
}
break;
default:
- logger('Unknown activity: ' . $type, LOGGER_DEBUG);
+ logger('Unknown activity: ' . $type . ' ' . $object_data['object_type'], LOGGER_DEBUG);
break;
}
}
foreach ($activity[$element] as $receiver) {
if ($receiver == $profile['followers'] && !empty($item_profile['followers'])) {
$permissions[$element][] = $item_profile['followers'];
- }
- if (!in_array($receiver, $exclude)) {
+ } elseif (!in_array($receiver, $exclude)) {
$permissions[$element][] = $receiver;
}
}
$data = ['to' => [], 'cc' => [], 'bcc' => []];
- $data = array_merge($data, self::fetchPermissionBlockFromConversation($item));
-
$actor_profile = APContact::getByURL($item['author-link']);
$terms = Term::tagArrayFromItemId($item['id'], TERM_MENTION);
if (!$item['private']) {
+ $data = array_merge($data, self::fetchPermissionBlockFromConversation($item));
+
$data['to'][] = ActivityPub::PUBLIC_COLLECTION;
if (!empty($actor_profile['followers'])) {
$data['cc'][] = $actor_profile['followers'];