+ /**
+ * Notify remote user it has got a new people tag
+ * - tag verb is queued
+ * - the subscription is done immediately if not present
+ *
+ * @param Profile_tag $ptag the people tag that was created
+ * @return hook return value
+ * @throws Exception of various kinds, some from $oprofile->subscribe();
+ */
+ function onEndTagProfile($ptag)
+ {
+ $oprofile = Ostatus_profile::getKV('profile_id', $ptag->tagged);
+ if (!$oprofile instanceof Ostatus_profile) {
+ return true;
+ }
+
+ $plist = $ptag->getMeta();
+ if ($plist->private) {
+ return true;
+ }
+
+ $act = new Activity();
+
+ $tagger = $plist->getTagger();
+ $tagged = Profile::getKV('id', $ptag->tagged);
+
+ $act->verb = ActivityVerb::TAG;
+ $act->id = TagURI::mint('tag_profile:%d:%d:%s',
+ $plist->tagger, $plist->id,
+ common_date_iso8601(time()));
+ $act->time = time();
+ // TRANS: Title for listing a remote profile.
+ $act->title = _m('TITLE','List');
+ // TRANS: Success message for remote list addition through OStatus.
+ // TRANS: %1$s is the list creator's name, %2$s is the added list member, %3$s is the list name.
+ $act->content = sprintf(_m('%1$s listed %2$s in the list %3$s.'),
+ $tagger->getBestName(),
+ $tagged->getBestName(),
+ $plist->getBestName());
+
+ $act->actor = ActivityObject::fromProfile($tagger);
+ $act->objects = array(ActivityObject::fromProfile($tagged));
+ $act->target = ActivityObject::fromPeopletag($plist);
+
+ $oprofile->notifyDeferred($act, $tagger);
+
+ // initiate a PuSH subscription for the person being tagged
+ $oprofile->subscribe();
+ return true;
+ }
+
+ /**
+ * Notify remote user that a people tag has been removed
+ * - untag verb is queued
+ * - the subscription is undone immediately if not required
+ * i.e garbageCollect()'d
+ *
+ * @param Profile_tag $ptag the people tag that was deleted
+ * @return hook return value
+ */
+ function onEndUntagProfile($ptag)
+ {
+ $oprofile = Ostatus_profile::getKV('profile_id', $ptag->tagged);
+ if (!$oprofile instanceof Ostatus_profile) {
+ return true;
+ }
+
+ $plist = $ptag->getMeta();
+ if ($plist->private) {
+ return true;
+ }
+
+ $act = new Activity();
+
+ $tagger = $plist->getTagger();
+ $tagged = Profile::getKV('id', $ptag->tagged);
+
+ $act->verb = ActivityVerb::UNTAG;
+ $act->id = TagURI::mint('untag_profile:%d:%d:%s',
+ $plist->tagger, $plist->id,
+ common_date_iso8601(time()));
+ $act->time = time();
+ // TRANS: Title for unlisting a remote profile.
+ $act->title = _m('TITLE','Unlist');
+ // TRANS: Success message for remote list removal through OStatus.
+ // TRANS: %1$s is the list creator's name, %2$s is the removed list member, %3$s is the list name.
+ $act->content = sprintf(_m('%1$s removed %2$s from the list %3$s.'),
+ $tagger->getBestName(),
+ $tagged->getBestName(),
+ $plist->getBestName());
+
+ $act->actor = ActivityObject::fromProfile($tagger);
+ $act->objects = array(ActivityObject::fromProfile($tagged));
+ $act->target = ActivityObject::fromPeopletag($plist);
+
+ $oprofile->notifyDeferred($act, $tagger);
+
+ // unsubscribe to PuSH feed if no more required
+ $oprofile->garbageCollect();
+
+ return true;
+ }
+