Some more cleanup
This commit is contained in:
parent
1efca1b75d
commit
bd6ba98e8d
2 changed files with 57 additions and 66 deletions
|
@ -67,9 +67,9 @@ class Processor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Add attachment data to the item array
|
||||||
*
|
*
|
||||||
*
|
* @param array $attachments
|
||||||
* @param $attachments
|
|
||||||
* @param array $item
|
* @param array $item
|
||||||
*
|
*
|
||||||
* @return item array
|
* @return item array
|
||||||
|
@ -101,10 +101,10 @@ class Processor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Prepares data for a message
|
||||||
*
|
*
|
||||||
*
|
* @param array $activity Activity array
|
||||||
* @param array $activity
|
* @param string $body original source
|
||||||
* @param $body
|
|
||||||
*/
|
*/
|
||||||
public static function createItem($activity, $body)
|
public static function createItem($activity, $body)
|
||||||
{
|
{
|
||||||
|
@ -129,16 +129,16 @@ class Processor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Prepare the item array for a "like"
|
||||||
*
|
*
|
||||||
*
|
* @param array $activity Activity array
|
||||||
* @param array $activity
|
* @param string $body original source
|
||||||
* @param $body
|
|
||||||
*/
|
*/
|
||||||
public static function likeItem($activity, $body)
|
public static function likeItem($activity, $body)
|
||||||
{
|
{
|
||||||
$item = [];
|
$item = [];
|
||||||
$item['verb'] = ACTIVITY_LIKE;
|
$item['verb'] = ACTIVITY_LIKE;
|
||||||
$item['parent-uri'] = JsonLD::fetchElement($activity, 'object');
|
$item['parent-uri'] = $activity['object_id'];
|
||||||
$item['gravity'] = GRAVITY_ACTIVITY;
|
$item['gravity'] = GRAVITY_ACTIVITY;
|
||||||
$item['object-type'] = ACTIVITY_OBJ_NOTE;
|
$item['object-type'] = ACTIVITY_OBJ_NOTE;
|
||||||
|
|
||||||
|
@ -149,27 +149,26 @@ class Processor
|
||||||
* Delete items
|
* Delete items
|
||||||
*
|
*
|
||||||
* @param array $activity
|
* @param array $activity
|
||||||
* @param $body
|
|
||||||
*/
|
*/
|
||||||
public static function deleteItem($activity)
|
public static function deleteItem($activity)
|
||||||
{
|
{
|
||||||
$owner = Contact::getIdForURL($activity['actor']);
|
$owner = Contact::getIdForURL($activity['actor']);
|
||||||
$object = JsonLD::fetchElement($activity, 'object');
|
|
||||||
logger('Deleting item ' . $object . ' from ' . $owner, LOGGER_DEBUG);
|
logger('Deleting item ' . $activity['object_id'] . ' from ' . $owner, LOGGER_DEBUG);
|
||||||
Item::delete(['uri' => $object, 'owner-id' => $owner]);
|
Item::delete(['uri' => $activity['object_id'], 'owner-id' => $owner]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Prepare the item array for a "dislike"
|
||||||
*
|
*
|
||||||
*
|
* @param array $activity Activity array
|
||||||
* @param array $activity
|
* @param string $body original source
|
||||||
* @param $body
|
|
||||||
*/
|
*/
|
||||||
public static function dislikeItem($activity, $body)
|
public static function dislikeItem($activity, $body)
|
||||||
{
|
{
|
||||||
$item = [];
|
$item = [];
|
||||||
$item['verb'] = ACTIVITY_DISLIKE;
|
$item['verb'] = ACTIVITY_DISLIKE;
|
||||||
$item['parent-uri'] = JsonLD::fetchElement($activity, 'object');
|
$item['parent-uri'] = $activity['object_id'];
|
||||||
$item['gravity'] = GRAVITY_ACTIVITY;
|
$item['gravity'] = GRAVITY_ACTIVITY;
|
||||||
$item['object-type'] = ACTIVITY_OBJ_NOTE;
|
$item['object-type'] = ACTIVITY_OBJ_NOTE;
|
||||||
|
|
||||||
|
@ -177,11 +176,11 @@ class Processor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates an item post
|
||||||
*
|
*
|
||||||
*
|
* @param array $activity Activity data
|
||||||
* @param array $activity
|
* @param array $item item array
|
||||||
* @param array $item
|
* @param string $body original source
|
||||||
* @param $body
|
|
||||||
*/
|
*/
|
||||||
private static function postItem($activity, $item, $body)
|
private static function postItem($activity, $item, $body)
|
||||||
{
|
{
|
||||||
|
@ -233,7 +232,7 @@ class Processor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Fetches missing posts
|
||||||
*
|
*
|
||||||
* @param $url
|
* @param $url
|
||||||
* @param $child
|
* @param $child
|
||||||
|
@ -273,8 +272,7 @@ class Processor
|
||||||
*/
|
*/
|
||||||
public static function followUser($activity)
|
public static function followUser($activity)
|
||||||
{
|
{
|
||||||
$actor = JsonLD::fetchElement($activity, 'object');
|
$uid = User::getIdForURL($activity['object_actor']);
|
||||||
$uid = User::getIdForURL($actor);
|
|
||||||
if (empty($uid)) {
|
if (empty($uid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -313,13 +311,12 @@ class Processor
|
||||||
*/
|
*/
|
||||||
public static function updatePerson($activity)
|
public static function updatePerson($activity)
|
||||||
{
|
{
|
||||||
$actor = JsonLD::fetchElement($activity, 'object');
|
if (empty($activity['object_id'])) {
|
||||||
if ($actor) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger('Updating profile for ' . $actor, LOGGER_DEBUG);
|
logger('Updating profile for ' . $activity['object_id'], LOGGER_DEBUG);
|
||||||
APContact::getByURL($actor, true);
|
APContact::getByURL($activity['object_id'], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -329,26 +326,23 @@ class Processor
|
||||||
*/
|
*/
|
||||||
public static function deletePerson($activity)
|
public static function deletePerson($activity)
|
||||||
{
|
{
|
||||||
$id = JsonLD::fetchElement($activity, 'object');
|
if (empty($activity['object_id']) || empty($activity['object_actor'])) {
|
||||||
$actor = JsonLD::fetchElement($activity, 'object', 'as:actor');
|
|
||||||
|
|
||||||
if (empty($id) || empty($actor)) {
|
|
||||||
logger('Empty object id or actor.', LOGGER_DEBUG);
|
logger('Empty object id or actor.', LOGGER_DEBUG);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($id != $actor) {
|
if ($activity['object_id'] != $activity['object_actor']) {
|
||||||
logger('Object id does not match actor.', LOGGER_DEBUG);
|
logger('Object id does not match actor.', LOGGER_DEBUG);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$contacts = DBA::select('contact', ['id'], ['nurl' => normalise_link($id)]);
|
$contacts = DBA::select('contact', ['id'], ['nurl' => normalise_link($activity['object_id'])]);
|
||||||
while ($contact = DBA::fetch($contacts)) {
|
while ($contact = DBA::fetch($contacts)) {
|
||||||
Contact::remove($contact['id']);
|
Contact::remove($contact['id']);
|
||||||
}
|
}
|
||||||
DBA::close($contacts);
|
DBA::close($contacts);
|
||||||
|
|
||||||
logger('Deleted contact ' . $id, LOGGER_DEBUG);
|
logger('Deleted contact ' . $activity['object_id'], LOGGER_DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -358,8 +352,7 @@ class Processor
|
||||||
*/
|
*/
|
||||||
public static function acceptFollowUser($activity)
|
public static function acceptFollowUser($activity)
|
||||||
{
|
{
|
||||||
$actor = JsonLD::fetchElement($activity, 'object', 'as:actor');
|
$uid = User::getIdForURL($activity['object_actor']);
|
||||||
$uid = User::getIdForURL($actor);
|
|
||||||
if (empty($uid)) {
|
if (empty($uid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -391,8 +384,7 @@ class Processor
|
||||||
*/
|
*/
|
||||||
public static function rejectFollowUser($activity)
|
public static function rejectFollowUser($activity)
|
||||||
{
|
{
|
||||||
$actor = JsonLD::fetchElement($activity, 'object', 'as:actor');
|
$uid = User::getIdForURL($activity['object_actor']);
|
||||||
$uid = User::getIdForURL($actor);
|
|
||||||
if (empty($uid)) {
|
if (empty($uid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -420,22 +412,20 @@ class Processor
|
||||||
*/
|
*/
|
||||||
public static function undoActivity($activity)
|
public static function undoActivity($activity)
|
||||||
{
|
{
|
||||||
$activity_url = JsonLD::fetchElement($activity, 'object');
|
if (empty($activity['object_id'])) {
|
||||||
if (empty($activity_url)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$actor = JsonLD::fetchElement($activity, 'object', 'as:actor');
|
if (empty($activity['object_actor'])) {
|
||||||
if (empty($actor)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$author_id = Contact::getIdForURL($actor);
|
$author_id = Contact::getIdForURL($activity['object_actor']);
|
||||||
if (empty($author_id)) {
|
if (empty($author_id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item::delete(['uri' => $activity_url, 'author-id' => $author_id, 'gravity' => GRAVITY_ACTIVITY]);
|
Item::delete(['uri' => $activity['object_id'], 'author-id' => $author_id, 'gravity' => GRAVITY_ACTIVITY]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -445,8 +435,7 @@ class Processor
|
||||||
*/
|
*/
|
||||||
public static function undoFollowUser($activity)
|
public static function undoFollowUser($activity)
|
||||||
{
|
{
|
||||||
$object = JsonLD::fetchElement($activity, 'object', 'as:object');
|
$uid = User::getIdForURL($activity['object_object']);
|
||||||
$uid = User::getIdForURL($object);
|
|
||||||
if (empty($uid)) {
|
if (empty($uid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,26 +112,26 @@ class Receiver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Prepare the object array
|
||||||
*
|
*
|
||||||
* @param array $activity
|
* @param array $activity
|
||||||
* @param integer $uid User ID
|
* @param integer $uid User ID
|
||||||
* @param $trust_source
|
* @param $trust_source
|
||||||
*
|
*
|
||||||
* @return
|
* @return array with object data
|
||||||
*/
|
*/
|
||||||
private static function prepareObjectData($ldactivity, $uid, &$trust_source)
|
private static function prepareObjectData($activity, $uid, &$trust_source)
|
||||||
{
|
{
|
||||||
$actor = JsonLD::fetchElement($ldactivity, 'as:actor');
|
$actor = JsonLD::fetchElement($activity, 'as:actor');
|
||||||
if (empty($actor)) {
|
if (empty($actor)) {
|
||||||
logger('Empty actor', LOGGER_DEBUG);
|
logger('Empty actor', LOGGER_DEBUG);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = JsonLD::fetchElement($ldactivity, '@type');
|
$type = JsonLD::fetchElement($activity, '@type');
|
||||||
|
|
||||||
// Fetch all receivers from to, cc, bto and bcc
|
// Fetch all receivers from to, cc, bto and bcc
|
||||||
$receivers = self::getReceivers($ldactivity, $actor);
|
$receivers = self::getReceivers($activity, $actor);
|
||||||
|
|
||||||
// When it is a delivery to a personal inbox we add that user to the receivers
|
// When it is a delivery to a personal inbox we add that user to the receivers
|
||||||
if (!empty($uid)) {
|
if (!empty($uid)) {
|
||||||
|
@ -142,7 +142,7 @@ class Receiver
|
||||||
|
|
||||||
logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG);
|
logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG);
|
||||||
|
|
||||||
$object_id = JsonLD::fetchElement($ldactivity, 'as:object');
|
$object_id = JsonLD::fetchElement($activity, 'as:object');
|
||||||
if (empty($object_id)) {
|
if (empty($object_id)) {
|
||||||
logger('No object found', LOGGER_DEBUG);
|
logger('No object found', LOGGER_DEBUG);
|
||||||
return [];
|
return [];
|
||||||
|
@ -153,7 +153,7 @@ class Receiver
|
||||||
if ($type == 'as:Announce') {
|
if ($type == 'as:Announce') {
|
||||||
$trust_source = false;
|
$trust_source = false;
|
||||||
}
|
}
|
||||||
$object_data = self::fetchObject($object_id, $ldactivity['as:object'], $trust_source);
|
$object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source);
|
||||||
if (empty($object_data)) {
|
if (empty($object_data)) {
|
||||||
logger("Object data couldn't be processed", LOGGER_DEBUG);
|
logger("Object data couldn't be processed", LOGGER_DEBUG);
|
||||||
return [];
|
return [];
|
||||||
|
@ -163,19 +163,21 @@ class Receiver
|
||||||
} elseif (in_array($type, ['as:Like', 'as:Dislike'])) {
|
} elseif (in_array($type, ['as:Like', 'as:Dislike'])) {
|
||||||
// Create a mostly empty array out of the activity data (instead of the object).
|
// Create a mostly empty array out of the activity data (instead of the object).
|
||||||
// This way we later don't have to check for the existence of ech individual array element.
|
// This way we later don't have to check for the existence of ech individual array element.
|
||||||
$object_data = self::processObject($ldactivity);
|
$object_data = self::processObject($activity);
|
||||||
$object_data['name'] = $type;
|
$object_data['name'] = $type;
|
||||||
$object_data['author'] = JsonLD::fetchElement($ldactivity, 'as:actor');
|
$object_data['author'] = JsonLD::fetchElement($activity, 'as:actor');
|
||||||
$object_data['object'] = $object_id;
|
$object_data['object'] = $object_id;
|
||||||
$object_data['object_type'] = ''; // Since we don't fetch the object, we don't know the type
|
$object_data['object_type'] = ''; // Since we don't fetch the object, we don't know the type
|
||||||
} else {
|
} else {
|
||||||
$object_data = [];
|
$object_data = [];
|
||||||
$object_data['id'] = JsonLD::fetchElement($ldactivity, '@id');
|
$object_data['id'] = JsonLD::fetchElement($activity, '@id');
|
||||||
$object_data['object'] = $ldactivity['as:object'];
|
$object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object');
|
||||||
$object_data['object_type'] = JsonLD::fetchElement($ldactivity, 'as:object', '@type');
|
$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');
|
||||||
}
|
}
|
||||||
|
|
||||||
$object_data = self::addActivityFields($object_data, $ldactivity);
|
$object_data = self::addActivityFields($object_data, $activity);
|
||||||
|
|
||||||
$object_data['type'] = $type;
|
$object_data['type'] = $type;
|
||||||
$object_data['actor'] = $actor;
|
$object_data['actor'] = $actor;
|
||||||
|
@ -194,27 +196,27 @@ class Receiver
|
||||||
* @param integer $uid User ID
|
* @param integer $uid User ID
|
||||||
* @param boolean $trust_source Do we trust the source?
|
* @param boolean $trust_source Do we trust the source?
|
||||||
*/
|
*/
|
||||||
public static function processActivity($ldactivity, $body = '', $uid = null, $trust_source = false)
|
public static function processActivity($activity, $body = '', $uid = null, $trust_source = false)
|
||||||
{
|
{
|
||||||
$type = JsonLD::fetchElement($ldactivity, '@type');
|
$type = JsonLD::fetchElement($activity, '@type');
|
||||||
if (!$type) {
|
if (!$type) {
|
||||||
logger('Empty type', LOGGER_DEBUG);
|
logger('Empty type', LOGGER_DEBUG);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!JsonLD::fetchElement($ldactivity, 'as:object')) {
|
if (!JsonLD::fetchElement($activity, 'as:object')) {
|
||||||
logger('Empty object', LOGGER_DEBUG);
|
logger('Empty object', LOGGER_DEBUG);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!JsonLD::fetchElement($ldactivity, 'as:actor')) {
|
if (!JsonLD::fetchElement($activity, 'as:actor')) {
|
||||||
logger('Empty actor', LOGGER_DEBUG);
|
logger('Empty actor', LOGGER_DEBUG);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// $trust_source is called by reference and is set to true if the content was retrieved successfully
|
// $trust_source is called by reference and is set to true if the content was retrieved successfully
|
||||||
$object_data = self::prepareObjectData($ldactivity, $uid, $trust_source);
|
$object_data = self::prepareObjectData($activity, $uid, $trust_source);
|
||||||
if (empty($object_data)) {
|
if (empty($object_data)) {
|
||||||
logger('No object data found', LOGGER_DEBUG);
|
logger('No object data found', LOGGER_DEBUG);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue