From 72c3a62e7f1ba5679b6503d760409d5345f5a4de Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 1 Oct 2018 05:44:56 +0000 Subject: [PATCH] Profile update is now done via APDelivery --- src/Protocol/ActivityPub.php | 20 ++++++++------------ src/Worker/APDelivery.php | 2 ++ src/Worker/Delivery.php | 15 ++++++++------- src/Worker/ProfileUpdate.php | 13 ++++++++++++- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 5bad98eb4c..4c77c8dff9 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -437,7 +437,7 @@ class ActivityPub * * @return array of follower inboxes */ - private static function fetchTargetInboxesforUser($uid) + public static function fetchTargetInboxesforUser($uid) { $inboxes = []; @@ -732,11 +732,12 @@ class ActivityPub } /** - * @brief Transmits a profile change to the followers + * @brief Transmits a profile change to a given inbox * * @param integer $uid User ID + * @param string $inbox Target inbox */ - public static function transmitProfileUpdate($uid) + public static function transmitProfileUpdate($uid, $inbox) { $owner = User::getOwnerDataById($uid); $profile = APContact::getByURL($owner['url']); @@ -750,17 +751,12 @@ class ActivityPub 'to' => [$profile['followers']], 'cc' => []]; - logger('Sending profile update to followers for user ' . $uid, LOGGER_DEBUG); - $signed = LDSignature::sign($data, $owner); - $inboxes = self::fetchTargetInboxesforUser($uid); - - foreach ($inboxes as $inbox) { - logger('Deliver profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); - HTTPSignature::transmit($signed, $inbox, $uid); - } + logger('Deliver profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); + HTTPSignature::transmit($signed, $inbox, $uid); } + /** * @brief Transmits a given activity to a target * @@ -1403,7 +1399,7 @@ class ActivityPub * * @return */ - private static function processObject(&$object) + private static function processObject($object) { if (empty($object['id'])) { return false; diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index 943238a7b4..eb0b3d9b15 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -18,6 +18,8 @@ class APDelivery extends BaseObject if ($cmd == Delivery::MAIL) { } elseif ($cmd == Delivery::SUGGESTION) { } elseif ($cmd == Delivery::RELOCATION) { + } elseif ($cmd == Delivery::PROFILEUPDATE) { + ActivityPub::transmitProfileUpdate($uid, $inbox); } else { $data = ActivityPub::createActivityFromItem($item_id); if (!empty($data)) { diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 3a93d92f7b..3585b39989 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -22,13 +22,14 @@ require_once 'include/items.php'; class Delivery extends BaseObject { - const MAIL = 'mail'; - const SUGGESTION = 'suggest'; - const RELOCATION = 'relocate'; - const DELETION = 'drop'; - const POST = 'wall-new'; - const COMMENT = 'comment-new'; - const REMOVAL = 'removeme'; + const MAIL = 'mail'; + const SUGGESTION = 'suggest'; + const RELOCATION = 'relocate'; + const DELETION = 'drop'; + const POST = 'wall-new'; + const COMMENT = 'comment-new'; + const REMOVAL = 'removeme'; + const PROFILEUPDATE = 'profileupdate'; public static function execute($cmd, $item_id, $contact_id) { diff --git a/src/Worker/ProfileUpdate.php b/src/Worker/ProfileUpdate.php index 9123f77e06..7fab86cbfd 100644 --- a/src/Worker/ProfileUpdate.php +++ b/src/Worker/ProfileUpdate.php @@ -6,8 +6,10 @@ namespace Friendica\Worker; +use Friendica\BaseObject; use Friendica\Protocol\Diaspora; use Friendica\Protocol\ActivityPub; +use Friendica\Core\Worker; class ProfileUpdate { public static function execute($uid = 0) { @@ -15,7 +17,16 @@ class ProfileUpdate { return; } - ActivityPub::transmitProfileUpdate($uid); + $a = BaseObject::getApp(); + + $inboxes = ActivityPub::fetchTargetInboxesforUser($uid); + + foreach ($inboxes as $inbox) { + logger('Profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); + Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true], + 'APDelivery', Delivery::PROFILEUPDATE, '', $inbox, $uid); + } + Diaspora::sendProfile($uid); } }