+ /**
+ * When one of our local users tries to subscribe to a remote peopletag,
+ * notify the remote server. If the notification is rejected,
+ * deny the subscription.
+ *
+ * @param Profile_list $peopletag
+ * @param User $user
+ *
+ * @return mixed hook return value
+ */
+
+ function onStartSubscribePeopletag($peopletag, $user)
+ {
+ $oprofile = Ostatus_profile::staticGet('peopletag_id', $peopletag->id);
+ if ($oprofile) {
+ if (!$oprofile->subscribe()) {
+ throw new Exception(_m('Could not set up remote peopletag subscription.'));
+ }
+
+ $sub = $user->getProfile();
+ $tagger = Profile::staticGet($peopletag->tagger);
+
+ $act = new Activity();
+ $act->id = TagURI::mint('subscribe_peopletag:%d:%d:%s',
+ $sub->id,
+ $peopletag->id,
+ common_date_iso8601(time()));
+
+ $act->actor = ActivityObject::fromProfile($sub);
+ $act->verb = ActivityVerb::FOLLOW;
+ $act->object = $oprofile->asActivityObject();
+
+ $act->time = time();
+ $act->title = _m("Follow list");
+ $act->content = sprintf(_m("%s is now following people tagged %s by %s."),
+ $sub->getBestName(),
+ $oprofile->getBestName(),
+ $tagger->getBestName());
+
+ if ($oprofile->notifyActivity($act, $sub)) {
+ return true;
+ } else {
+ $oprofile->garbageCollect();
+ throw new Exception(_m("Failed subscribing to remote peopletag."));
+ }
+ }
+ }
+
+ /**
+ * When one of our local users unsubscribes to a remote peopletag, notify the remote
+ * server.
+ *
+ * @param Profile_list $peopletag
+ * @param User $user
+ *
+ * @return mixed hook return value
+ */
+
+ function onEndUnsubscribePeopletag($peopletag, $user)
+ {
+ $oprofile = Ostatus_profile::staticGet('peopletag_id', $peopletag->id);
+ if ($oprofile) {
+ // Drop the PuSH subscription if there are no other subscribers.
+ $oprofile->garbageCollect();
+
+ $sub = Profile::staticGet($user->id);
+ $tagger = Profile::staticGet($peopletag->tagger);
+
+ $act = new Activity();
+ $act->id = TagURI::mint('unsubscribe_peopletag:%d:%d:%s',
+ $sub->id,
+ $peopletag->id,
+ common_date_iso8601(time()));
+
+ $act->actor = ActivityObject::fromProfile($member);
+ $act->verb = ActivityVerb::UNFOLLOW;
+ $act->object = $oprofile->asActivityObject();
+
+ $act->time = time();
+ $act->title = _m("Unfollow peopletag");
+ $act->content = sprintf(_m("%s stopped following the list %s by %s."),
+ $sub->getBestName(),
+ $oprofile->getBestName(),
+ $tagger->getBestName());
+
+ $oprofile->notifyActivity($act, $user);
+ }
+ }
+