use notifyActivity() for notifications in OStatusPlugin

This commit is contained in:
Evan Prodromou 2010-02-21 10:53:32 -05:00
parent 4e90bd34e9
commit df7c6b37c8
1 changed files with 99 additions and 25 deletions

View File

@ -251,27 +251,47 @@ class OStatusPlugin extends Plugin
* @param Profile $other * @param Profile $other
* @return hook return value * @return hook return value
*/ */
function onEndUnsubscribe($user, $other) function onEndUnsubscribe($profile, $other)
{ {
if ($user instanceof Profile) { $user = User::staticGet('id', $profile->id);
$profile = $user;
} else if ($user instanceof User) { if (empty($user)) {
$profile = $user->getProfile(); return true;
} }
$oprofile = Ostatus_profile::staticGet('profile_id', $other->id); $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
if ($oprofile) {
// Notify the remote server of the unsub, if supported. if (empty($oprofile)) {
$oprofile->notify($profile, ActivityVerb::UNFOLLOW, $oprofile); return true;
}
// Drop the PuSH subscription if there are no other subscribers. // Drop the PuSH subscription if there are no other subscribers.
$sub = new Subscription();
$sub->subscribed = $other->id; if ($other->subscriberCount() == 0) {
$sub->limit(1);
if (!$sub->find(true)) {
common_log(LOG_INFO, "Unsubscribing from now-unused feed $oprofile->feeduri"); common_log(LOG_INFO, "Unsubscribing from now-unused feed $oprofile->feeduri");
$oprofile->unsubscribe(); $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;
} }
@ -350,10 +370,25 @@ class OStatusPlugin extends Plugin
return true; return true;
} }
// We have a local user subscribing to a remote profile; make the $act = new Activity();
// magic happen!
$oprofile->notify($subscriber, ActivityVerb::FOLLOW, $oprofile); $act->verb = ActivityVerb::FOLLOW;
$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; return true;
} }
@ -365,6 +400,7 @@ class OStatusPlugin extends Plugin
* @param Notice $notice being favored * @param Notice $notice being favored
* @return hook return value * @return hook return value
*/ */
function onEndFavorNotice(Profile $profile, Notice $notice) function onEndFavorNotice(Profile $profile, Notice $notice)
{ {
$user = User::staticGet('id', $profile->id); $user = User::staticGet('id', $profile->id);
@ -375,10 +411,29 @@ class OStatusPlugin extends Plugin
$oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id); $oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
if ($oprofile) { if (empty($oprofile)) {
$oprofile->notify($profile, ActivityVerb::FAVORITE, $notice); 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; return true;
} }
@ -389,6 +444,7 @@ class OStatusPlugin extends Plugin
* @param Notice $notice being favored * @param Notice $notice being favored
* @return hook return value * @return hook return value
*/ */
function onEndDisfavorNotice(Profile $profile, Notice $notice) function onEndDisfavorNotice(Profile $profile, Notice $notice)
{ {
$user = User::staticGet('id', $profile->id); $user = User::staticGet('id', $profile->id);
@ -399,10 +455,28 @@ class OStatusPlugin extends Plugin
$oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id); $oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
if ($oprofile) { if (empty($oprofile)) {
$oprofile->notify($profile, ActivityVerb::UNFAVORITE, $notice); 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; return true;
} }
} }