{
$item = [];
$item['verb'] = ACTIVITY_LIKE;
- $item['parent-uri'] = $activity['object'];
+ $item['parent-uri'] = JsonLD::fetchElement($activity, 'object');
$item['gravity'] = GRAVITY_ACTIVITY;
$item['object-type'] = ACTIVITY_OBJ_NOTE;
public static function deleteItem($activity)
{
$owner = Contact::getIdForURL($activity['owner']);
- $object = JsonLD::fetchElement($activity, 'object', 'id');
+ $object = JsonLD::fetchElement($activity, 'object');
logger('Deleting item ' . $object . ' from ' . $owner, LOGGER_DEBUG);
Item::delete(['uri' => $object, 'owner-id' => $owner]);
}
{
$item = [];
$item['verb'] = ACTIVITY_DISLIKE;
- $item['parent-uri'] = $activity['object'];
+ $item['parent-uri'] = JsonLD::fetchElement($activity, 'object');
$item['gravity'] = GRAVITY_ACTIVITY;
$item['object-type'] = ACTIVITY_OBJ_NOTE;
$activity['published'] = $object['published'];
$activity['type'] = 'Create';
- ActivityPub\Receiver::processActivity($activity);
+ $ldactivity = JsonLD::compact($activity);
+ ActivityPub\Receiver::processActivity($activity, $ldactivity);
logger('Activity ' . $url . ' had been fetched and processed.');
}
*/
public static function followUser($activity)
{
- $actor = JsonLD::fetchElement($activity, 'object', 'id');
+ $actor = JsonLD::fetchElement($activity, 'object');
$uid = User::getIdForURL($actor);
if (empty($uid)) {
return;
*/
public static function updatePerson($activity)
{
- if (empty($activity['object']['id'])) {
+ $actor = JsonLD::fetchElement($activity, 'object');
+ if ($actor) {
return;
}
- logger('Updating profile for ' . $activity['object']['id'], LOGGER_DEBUG);
- APContact::getByURL($activity['object']['id'], true);
+ logger('Updating profile for ' . $actor, LOGGER_DEBUG);
+ APContact::getByURL($actor, true);
}
/**
*/
public static function deletePerson($activity)
{
- if (empty($activity['object']['id']) || empty($activity['object']['actor'])) {
+ $id = JsonLD::fetchElement($activity, 'object');
+ $actor = JsonLD::fetchElement($activity, 'object', 'as:actor');
+
+ if (empty($id) || empty($actor)) {
logger('Empty object id or actor.', LOGGER_DEBUG);
return;
}
- if ($activity['object']['id'] != $activity['object']['actor']) {
+ if ($id != $actor) {
logger('Object id does not match actor.', LOGGER_DEBUG);
return;
}
- $contacts = DBA::select('contact', ['id'], ['nurl' => normalise_link($activity['object']['id'])]);
+ $contacts = DBA::select('contact', ['id'], ['nurl' => normalise_link($id)]);
while ($contact = DBA::fetch($contacts)) {
- Contact::remove($contact["id"]);
+ Contact::remove($contact['id']);
}
DBA::close($contacts);
- logger('Deleted contact ' . $activity['object']['id'], LOGGER_DEBUG);
+ logger('Deleted contact ' . $id, LOGGER_DEBUG);
}
/**
*/
public static function acceptFollowUser($activity)
{
- $actor = JsonLD::fetchElement($activity, 'object', 'actor');
+ $actor = JsonLD::fetchElement($activity, 'object', 'as:actor');
$uid = User::getIdForURL($actor);
if (empty($uid)) {
return;
*/
public static function rejectFollowUser($activity)
{
- $actor = JsonLD::fetchElement($activity, 'object', 'actor');
+ $actor = JsonLD::fetchElement($activity, 'object', 'as:actor');
$uid = User::getIdForURL($actor);
if (empty($uid)) {
return;
*/
public static function undoActivity($activity)
{
- $activity_url = JsonLD::fetchElement($activity, 'object', 'id');
+ $activity_url = JsonLD::fetchElement($activity, 'object');
if (empty($activity_url)) {
return;
}
- $actor = JsonLD::fetchElement($activity, 'object', 'actor');
+ $actor = JsonLD::fetchElement($activity, 'object', 'as:actor');
if (empty($actor)) {
return;
}
*/
public static function undoFollowUser($activity)
{
- $object = JsonLD::fetchElement($activity, 'object', 'object');
+ $object = JsonLD::fetchElement($activity, 'object', 'as:object');
$uid = User::getIdForURL($object);
if (empty($uid)) {
return;
// Fetch the content only on activities where this matters
if (in_array($type, ['as:Create', 'as:Announce'])) {
- $object_data = self::fetchObject($object_id, $activity['object'], $ldactivity['as:object'], $trust_source);
+ $object_data = self::fetchObject($object_id, $ldactivity['as:object'], $trust_source);
if (empty($object_data)) {
logger("Object data couldn't be processed", LOGGER_DEBUG);
return [];
} else {
$object_data = [];
$object_data['id'] = JsonLD::fetchElement($ldactivity, '@id');
- $object_data['object'] = $activity['object'];
+ $object_data['object'] = $ldactivity['as:object'];
$object_data['object_type'] = JsonLD::fetchElement($ldactivity, 'as:object', '@type');
}
$object_data = self::addActivityFields($object_data, $activity);
- $object_data['type'] = $activity['type'];
+ $object_data['type'] = $type;
$object_data['owner'] = $actor;
$object_data['receiver'] = array_merge(defaults($object_data, 'receiver', []), $receivers);
*
* @return array with object data
*/
- private static function fetchObject($object_id, $object = [], $ldobject = [], $trust_source = false)
+ private static function fetchObject($object_id, $object = [], $trust_source = false)
{
- if (!$trust_source || is_string($object)) {
+ if (!$trust_source || empty($object)) {
$data = ActivityPub::fetchContent($object_id);
- if (empty($data)) {
- logger('Empty content for ' . $object_id . ', check if content is available locally.', LOGGER_DEBUG);
- $data = $object_id;
- } else {
- $ldobject = JsonLD::compact($data);
+ if (!empty($data)) {
+ $object = JsonLD::compact($data);
logger('Fetched content for ' . $object_id, LOGGER_DEBUG);
+ } else {
+ logger('Empty content for ' . $object_id . ', check if content is available locally.', LOGGER_DEBUG);
+
+ $item = Item::selectFirst([], ['uri' => $object_id]);
+ if (!DBA::isResult($item)) {
+ logger('Object with url ' . $object_id . ' was not found locally.', LOGGER_DEBUG);
+ return false;
+ }
+ logger('Using already stored item for url ' . $object_id, LOGGER_DEBUG);
+ $data = ActivityPub\Transmitter::createNote($item);
+ $object = JsonLD::compact($data);
}
} else {
logger('Using original object for url ' . $object_id, LOGGER_DEBUG);
- $data = $object;
}
- if (is_string($data)) {
- $item = Item::selectFirst([], ['uri' => $data]);
- if (!DBA::isResult($item)) {
- logger('Object with url ' . $data . ' was not found locally.', LOGGER_DEBUG);
- return false;
- }
- logger('Using already stored item for url ' . $object_id, LOGGER_DEBUG);
- $data = ActivityPub\Transmitter::createNote($item);
- $ldobject = JsonLD::compact($data);
- }
+ $type = JsonLD::fetchElement($object, '@type');
- if (empty($data['type'])) {
+ if (empty($type)) {
logger('Empty type', LOGGER_DEBUG);
return false;
}
- if (in_array($data['type'], ActivityPub::CONTENT_TYPES)) {
- return self::processObject($ldobject);
+ if (in_array($type, self::CONTENT_TYPES)) {
+ return self::processObject($object);
}
- if ($data['type'] == 'Announce') {
- if (empty($data['object'])) {
+ if ($type == 'as:Announce') {
+ $object_id = JsonLD::fetchElement($object, 'object');
+ if (empty($object_id)) {
return false;
}
- return self::fetchObject($data['object']);
+ return self::fetchObject($object_id);
}
- logger('Unhandled object type: ' . $data['type'], LOGGER_DEBUG);
+ logger('Unhandled object type: ' . $type, LOGGER_DEBUG);
}
/**
private static function processTags($tags)
{
$taglist = [];
+
foreach ($tags as $tag) {
+ if (empty($tag)) {
+ continue;
+ }
+
$taglist[] = ['type' => str_replace('as:', '', JsonLD::fetchElement($tag, '@type')),
'href' => JsonLD::fetchElement($tag, 'as:href'),
'name' => JsonLD::fetchElement($tag, 'as:name')];
private static function processAttachments($attachments)
{
$attachlist = [];
+
foreach ($attachments as $attachment) {
+ if (empty($attachment)) {
+ continue;
+ }
+
$attachlist[] = ['type' => str_replace('as:', '', JsonLD::fetchElement($attachment, '@type')),
'mediaType' => JsonLD::fetchElement($attachment, 'as:mediaType'),
'name' => JsonLD::fetchElement($attachment, 'as:name'),