From 6afa091dca980fcd856b781015ee57afa89c9339 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 4 Oct 2015 17:23:11 +0200 Subject: [PATCH] Change some Salmon events and similar Use Profile instead of User and (if we know it) send along the target profile, so a Diaspora plugin can encrypt to the receiver. --- plugins/OStatus/classes/Ostatus_profile.php | 7 ++++--- plugins/OStatus/lib/salmon.php | 8 ++++---- plugins/OStatus/lib/salmonqueuehandler.php | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index 8fc9f6c5f6..dbdbe88523 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -345,7 +345,7 @@ class Ostatus_profile extends Managed_DataObject $xml = $entry->getString(); common_log(LOG_INFO, "Posting to Salmon endpoint $this->salmonuri: $xml"); - Salmon::post($this->salmonuri, $xml, $actor->getUser()); + Salmon::post($this->salmonuri, $xml, $actor); } /** @@ -359,7 +359,7 @@ class Ostatus_profile extends Managed_DataObject public function notifyActivity($entry, Profile $actor) { if ($this->salmonuri) { - return Salmon::post($this->salmonuri, $this->notifyPrepXml($entry), $actor->getUser()); + return Salmon::post($this->salmonuri, $this->notifyPrepXml($entry), $actor, $this->localProfile()); } common_debug(__CLASS__.' error: No salmonuri for Ostatus_profile uri: '.$this->uri); @@ -378,7 +378,8 @@ class Ostatus_profile extends Managed_DataObject if ($this->salmonuri) { $data = array('salmonuri' => $this->salmonuri, 'entry' => $this->notifyPrepXml($entry), - 'actor' => $actor->id); + 'actor' => $actor->getID(), + 'target' => $this->localProfile()->getID()); $qm = QueueManager::get(); return $qm->enqueue($data, 'salmon'); diff --git a/plugins/OStatus/lib/salmon.php b/plugins/OStatus/lib/salmon.php index cdc8e02d77..b964538cbc 100644 --- a/plugins/OStatus/lib/salmon.php +++ b/plugins/OStatus/lib/salmon.php @@ -43,18 +43,18 @@ class Salmon * * @param string $endpoint_uri * @param string $xml string representation of payload - * @param User $user local user profile whose keys we sign with + * @param Profile $user profile whose keys we sign with (must be a local user) * @return boolean success */ - public static function post($endpoint_uri, $xml, User $user, Profile $target=null) + public static function post($endpoint_uri, $xml, Profile $actor, Profile $target=null) { if (empty($endpoint_uri)) { - common_debug('No endpoint URI for Salmon post to '.$user->getUri()); + common_debug('No endpoint URI for Salmon post to '.$actor->getUri()); return false; } try { - $magic_env = MagicEnvelope::signAsUser($xml, $user); + $magic_env = MagicEnvelope::signAsUser($xml, $actor->getUser()); } catch (Exception $e) { common_log(LOG_ERR, "Salmon unable to sign: " . $e->getMessage()); return false; diff --git a/plugins/OStatus/lib/salmonqueuehandler.php b/plugins/OStatus/lib/salmonqueuehandler.php index 334dc14549..fbc03c3954 100644 --- a/plugins/OStatus/lib/salmonqueuehandler.php +++ b/plugins/OStatus/lib/salmonqueuehandler.php @@ -40,8 +40,9 @@ class SalmonQueueHandler extends QueueHandler assert(is_string($data['entry'])); $actor = Profile::getKV($data['actor']); + $target = array_key_exists('target', $data) ? Profile::getKV($data['target']) : null; - Salmon::post($data['salmonuri'], $data['entry'], $actor->getUser()); + Salmon::post($data['salmonuri'], $data['entry'], $actor, $target); // @fixme detect failure and attempt to resend return true; -- 2.39.5