summaryrefslogtreecommitdiff
path: root/plugins/OStatus/OStatusPlugin.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2010-02-23 16:02:27 -0500
committerEvan Prodromou <evan@status.net>2010-02-23 16:02:27 -0500
commitb09304a6c4553044983176fb2740206777868378 (patch)
tree612381c27789be05070d4e7ca03d8f05fff58d5e /plugins/OStatus/OStatusPlugin.php
parenta0c255e231a84cf77554cc3c0a095eae7b0ffd9c (diff)
parent90d34b26c66ceb5d37a9c2782356b46361a523cc (diff)
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
Conflicts: plugins/OStatus/OStatusPlugin.php
Diffstat (limited to 'plugins/OStatus/OStatusPlugin.php')
-rw-r--r--plugins/OStatus/OStatusPlugin.php151
1 files changed, 98 insertions, 53 deletions
diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php
index 679857f89..3a9e77c2a 100644
--- a/plugins/OStatus/OStatusPlugin.php
+++ b/plugins/OStatus/OStatusPlugin.php
@@ -252,58 +252,6 @@ class OStatusPlugin extends Plugin
}
/**
- * Notify remote server and garbage collect unused feeds on unsubscribe.
- * @fixme send these operations to background queues
- *
- * @param User $user
- * @param Profile $other
- * @return hook return value
- */
- function onEndUnsubscribe($profile, $other)
- {
- $user = User::staticGet('id', $profile->id);
-
- if (empty($user)) {
- return true;
- }
-
- $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
-
- if (empty($oprofile)) {
- return true;
- }
-
- // Drop the PuSH subscription if there are no other subscribers.
-
- if ($other->subscriberCount() == 0) {
- common_log(LOG_INFO, "Unsubscribing from now-unused feed $oprofile->feeduri");
- $oprofile->unsubscribe();
- }
-
- $act = new Activity();
-
- $act->verb = ActivityVerb::UNFOLLOW;
-
- $act->id = TagURI::mint('unfollow:%d:%d:%s',
- $profile->id,
- $other->id,
- common_date_iso8601(time()));
-
- $act->time = time();
- $act->title = _("Unfollow");
- $act->content = sprintf(_("%s stopped following %s."),
- $profile->getBestName(),
- $other->getBestName());
-
- $act->actor = ActivityObject::fromProfile($profile);
- $act->object = ActivityObject::fromProfile($other);
-
- $oprofile->notifyActivity($act);
-
- return true;
- }
-
- /**
* Make sure necessary tables are filled out.
*/
function onCheckSchema() {
@@ -366,6 +314,50 @@ class OStatusPlugin extends Plugin
}
}
+ /**
+ * When about to subscribe to a remote user, start a server-to-server
+ * PuSH subscription if needed. If we can't establish that, abort.
+ *
+ * @fixme If something else aborts later, we could end up with a stray
+ * PuSH subscription. This is relatively harmless, though.
+ *
+ * @param Profile $subscriber
+ * @param Profile $other
+ *
+ * @return hook return code
+ *
+ * @throws Exception
+ */
+ function onStartSubscribe($subscriber, $other)
+ {
+ $user = User::staticGet('id', $subscriber->id);
+
+ if (empty($user)) {
+ return true;
+ }
+
+ $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
+
+ if (empty($oprofile)) {
+ return true;
+ }
+
+ if (!$oprofile->subscribe()) {
+ throw new Exception(_m('Could not set up remote subscription.'));
+ }
+ }
+
+ /**
+ * Having established a remote subscription, send a notification to the
+ * remote OStatus profile's endpoint.
+ *
+ * @param Profile $subscriber
+ * @param Profile $other
+ *
+ * @return hook return code
+ *
+ * @throws Exception
+ */
function onEndSubscribe($subscriber, $other)
{
$user = User::staticGet('id', $subscriber->id);
@@ -404,6 +396,54 @@ class OStatusPlugin extends Plugin
}
/**
+ * Notify remote server and garbage collect unused feeds on unsubscribe.
+ * @fixme send these operations to background queues
+ *
+ * @param User $user
+ * @param Profile $other
+ * @return hook return value
+ */
+ function onEndUnsubscribe($profile, $other)
+ {
+ $user = User::staticGet('id', $profile->id);
+
+ if (empty($user)) {
+ return true;
+ }
+
+ $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
+
+ if (empty($oprofile)) {
+ return true;
+ }
+
+ // Drop the PuSH subscription if there are no other subscribers.
+ $oprofile->garbageCollect();
+
+ $act = new Activity();
+
+ $act->verb = ActivityVerb::UNFOLLOW;
+
+ $act->id = TagURI::mint('unfollow:%d:%d:%s',
+ $profile->id,
+ $other->id,
+ common_date_iso8601(time()));
+
+ $act->time = time();
+ $act->title = _("Unfollow");
+ $act->content = sprintf(_("%s stopped following %s."),
+ $profile->getBestName(),
+ $other->getBestName());
+
+ $act->actor = ActivityObject::fromProfile($profile);
+ $act->object = ActivityObject::fromProfile($other);
+
+ $oprofile->notifyActivity($act);
+
+ return true;
+ }
+
+ /**
* When one of our local users tries to join a remote group,
* notify the remote server. If the notification is rejected,
* deny the join.
@@ -418,6 +458,10 @@ class OStatusPlugin extends Plugin
{
$oprofile = Ostatus_profile::staticGet('group_id', $group->id);
if ($oprofile) {
+ if (!$oprofile->subscribe()) {
+ throw new Exception(_m('Could not set up remote group membership.'));
+ }
+
$member = Profile::staticGet($user->id);
$act = new Activity();
@@ -439,7 +483,8 @@ class OStatusPlugin extends Plugin
if ($oprofile->notifyActivity($act)) {
return true;
} else {
- throw new ServerException(_m("Failed joining remote group."));
+ $oprofile->garbageCollect();
+ throw new Exception(_m("Failed joining remote group."));
}
}
}