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.
This commit is contained in:
Mikael Nordfeldth 2015-10-04 17:23:11 +02:00
parent f4ed171397
commit 6afa091dca
3 changed files with 10 additions and 8 deletions

View File

@ -345,7 +345,7 @@ class Ostatus_profile extends Managed_DataObject
$xml = $entry->getString(); $xml = $entry->getString();
common_log(LOG_INFO, "Posting to Salmon endpoint $this->salmonuri: $xml"); 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) public function notifyActivity($entry, Profile $actor)
{ {
if ($this->salmonuri) { 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); 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) { if ($this->salmonuri) {
$data = array('salmonuri' => $this->salmonuri, $data = array('salmonuri' => $this->salmonuri,
'entry' => $this->notifyPrepXml($entry), 'entry' => $this->notifyPrepXml($entry),
'actor' => $actor->id); 'actor' => $actor->getID(),
'target' => $this->localProfile()->getID());
$qm = QueueManager::get(); $qm = QueueManager::get();
return $qm->enqueue($data, 'salmon'); return $qm->enqueue($data, 'salmon');

View File

@ -43,18 +43,18 @@ class Salmon
* *
* @param string $endpoint_uri * @param string $endpoint_uri
* @param string $xml string representation of payload * @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 * @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)) { 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; return false;
} }
try { try {
$magic_env = MagicEnvelope::signAsUser($xml, $user); $magic_env = MagicEnvelope::signAsUser($xml, $actor->getUser());
} catch (Exception $e) { } catch (Exception $e) {
common_log(LOG_ERR, "Salmon unable to sign: " . $e->getMessage()); common_log(LOG_ERR, "Salmon unable to sign: " . $e->getMessage());
return false; return false;

View File

@ -40,8 +40,9 @@ class SalmonQueueHandler extends QueueHandler
assert(is_string($data['entry'])); assert(is_string($data['entry']));
$actor = Profile::getKV($data['actor']); $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 // @fixme detect failure and attempt to resend
return true; return true;