summaryrefslogtreecommitdiff
path: root/plugins/OStatus/actions/salmon.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/OStatus/actions/salmon.php')
-rw-r--r--plugins/OStatus/actions/salmon.php66
1 files changed, 57 insertions, 9 deletions
diff --git a/plugins/OStatus/actions/salmon.php b/plugins/OStatus/actions/salmon.php
index 2da9db9eb..1ed322ed2 100644
--- a/plugins/OStatus/actions/salmon.php
+++ b/plugins/OStatus/actions/salmon.php
@@ -63,13 +63,17 @@ class SalmonAction extends Action
// XXX: check that document element is Atom entry
// XXX: check the signature
- $this->act = new Activity($dom->documentElement);
+ $entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry');
+ if ($entries && $entries->length) {
+ // @fixme is it legit to have multiple entries?
+ $this->act = new Activity($entries->item(0), $dom->documentElement);
+ }
return true;
}
/**
- * @fixme probably call Ostatus_profile::processFeed
+ * Check the posted activity type and break out to appropriate processing.
*/
function handle($args)
@@ -94,13 +98,19 @@ class SalmonAction extends Action
case ActivityVerb::FRIEND:
$this->handleFollow();
break;
+ case ActivityVerb::UNFOLLOW:
+ $this->handleUnfollow();
+ break;
}
Event::handle('EndHandleSalmon', array($this->user, $this->activity));
}
}
/**
- * @fixme probably call Ostatus_profile::processFeed
+ * We've gotten a post event on the Salmon backchannel, probably a reply.
+ *
+ * @todo validate if we need to handle this post, then call into
+ * ostatus_profile's general incoming-post handling.
*/
function handlePost()
{
@@ -116,43 +126,81 @@ class SalmonAction extends Action
}
$profile = $this->ensureProfile();
+ // @fixme do something with the post
}
/**
- * @fixme probably call Ostatus_profile::processFeed
+ * We've gotten a follow/subscribe notification from a remote user.
+ * Save a subscription relationship for them.
*/
function handleFollow()
{
+ $oprofile = $this->ensureProfile();
+ if ($oprofile) {
+ common_log(LOG_INFO, "Setting up subscription from remote {$oprofile->uri} to local {$this->user->nickname}");
+ $oprofile->subscribeRemoteToLocal($this->user);
+ } else {
+ common_log(LOG_INFO, "Can't set up subscription from remote; missing profile.");
+ }
+ }
+
+ /**
+ * We've gotten an unfollow/unsubscribe notification from a remote user.
+ * Check if we have a subscription relationship for them and kill it.
+ *
+ * @fixme probably catch exceptions on fail?
+ */
+ function handleUnfollow()
+ {
+ $oprofile = $this->ensureProfile();
+ if ($oprofile) {
+ common_log(LOG_INFO, "Canceling subscription from remote {$oprofile->uri} to local {$this->user->nickname}");
+ Subscription::cancel($oprofile->localProfile(), $this->user->getProfile());
+ } else {
+ common_log(LOG_ERR, "Can't cancel subscription from remote, didn't find the profile");
+ }
}
/**
- * @fixme probably call Ostatus_profile::processFeed
+ * Remote user likes one of our posts.
+ * Confirm the post is ours, and save a local favorite event.
*/
function handleFavorite()
{
}
/**
- * @fixme probably call Ostatus_profile::processFeed
+ * Remote user doesn't like one of our posts after all!
+ * Confirm the post is ours, and save a local favorite event.
+ */
+ function handleUnfavorite()
+ {
+ }
+
+ /**
+ * Hmmmm
*/
function handleShare()
{
}
+ /**
+ * @return Ostatus_profile
+ */
function ensureProfile()
{
$actor = $this->act->actor;
common_log(LOG_DEBUG, "Received salmon bit: " . var_export($this->act, true));
if (empty($actor->id)) {
+ common_log(LOG_ERR, "broken actor: " . var_export($actor, true));
throw new Exception("Received a salmon slap from unidentified actor.");
}
- $ostatusProfile = Ostatus_profile::ensureActorProfile($this->act);
- return $oprofile->localProfile();
+ return Ostatus_profile::ensureActorProfile($this->act);
}
/**
- * @fixme anything new in here probably should be merged into Ostatus_profile::ensureActorProfile and friends
+ * @fixme merge into Ostatus_profile::ensureActorProfile and friends
*/
function createProfile()
{