* @param Profile $other
* @return hook return value
*/
- function onEndUnsubscribe($user, $other)
+ function onEndUnsubscribe($profile, $other)
{
- if ($user instanceof Profile) {
- $profile = $user;
- } else if ($user instanceof User) {
- $profile = $user->getProfile();
+ $user = User::staticGet('id', $profile->id);
+
+ if (empty($user)) {
+ return true;
}
+
$oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
- if ($oprofile) {
- // Notify the remote server of the unsub, if supported.
- $oprofile->notify($profile, ActivityVerb::UNFOLLOW, $oprofile);
-
- // Drop the PuSH subscription if there are no other subscribers.
- $sub = new Subscription();
- $sub->subscribed = $other->id;
- $sub->limit(1);
- if (!$sub->find(true)) {
- common_log(LOG_INFO, "Unsubscribing from now-unused feed $oprofile->feeduri");
- $oprofile->unsubscribe();
- }
+
+ 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($subscriber);
+ $act->object = ActivityObject::fromProfile($other);
+
+ $oprofile->notifyActivity($act);
+
return true;
}
return true;
}
- // We have a local user subscribing to a remote profile; make the
- // magic happen!
+ $act = new Activity();
+
+ $act->verb = ActivityVerb::FOLLOW;
- $oprofile->notify($subscriber, ActivityVerb::FOLLOW, $oprofile);
+ $act->id = TagURI::mint('follow:%d:%d:%s',
+ $subscriber->id,
+ $other->id,
+ common_date_iso8601(time()));
+
+ $act->time = time();
+ $act->title = _("Follow");
+ $act->content = sprintf(_("%s is now following %s."),
+ $subscriber->getBestName(),
+ $other->getBestName());
+
+ $act->actor = ActivityObject::fromProfile($subscriber);
+ $act->object = ActivityObject::fromProfile($other);
+
+ $oprofile->notifyActivity($act);
return true;
}
* @param Notice $notice being favored
* @return hook return value
*/
+
function onEndFavorNotice(Profile $profile, Notice $notice)
{
$user = User::staticGet('id', $profile->id);
$oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
- if ($oprofile) {
- $oprofile->notify($profile, ActivityVerb::FAVORITE, $notice);
+ if (empty($oprofile)) {
+ return true;
}
+ $act = new Activity();
+
+ $act->verb = ActivityVerb::FAVORITE;
+ $act->id = TagURI::mint('favor:%d:%d:%s',
+ $profile->id,
+ $notice->id,
+ common_date_iso8601(time()));
+
+ $act->time = time();
+ $act->title = _("Favor");
+ $act->content = sprintf(_("%s marked notice %s as a favorite."),
+ $profile->getBestName(),
+ $notice->uri);
+
+ $act->actor = ActivityObject::fromProfile($profile);
+ $act->object = ActivityObject::fromNotice($notice);
+
+ $oprofile->notifyActivity($act);
+
return true;
}
* @param Notice $notice being favored
* @return hook return value
*/
+
function onEndDisfavorNotice(Profile $profile, Notice $notice)
{
$user = User::staticGet('id', $profile->id);
$oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
- if ($oprofile) {
- $oprofile->notify($profile, ActivityVerb::UNFAVORITE, $notice);
+ if (empty($oprofile)) {
+ return true;
}
+ $act = new Activity();
+
+ $act->verb = ActivityVerb::UNFAVORITE;
+ $act->id = TagURI::mint('disfavor:%d:%d:%s',
+ $profile->id,
+ $notice->id,
+ common_date_iso8601(time()));
+ $act->time = time();
+ $act->title = _("Disfavor");
+ $act->content = sprintf(_("%s marked notice %s as no longer a favorite."),
+ $profile->getBestName(),
+ $notice->uri);
+
+ $act->actor = ActivityObject::fromProfile($profile);
+ $act->object = ActivityObject::fromNotice($notice);
+
+ $oprofile->notifyActivity($act);
+
return true;
}
}