. */ /** * @package OStatusPlugin */ if (!defined('STATUSNET')) { exit(1); } class PeopletagsalmonAction extends SalmonAction { var $peopletag = null; function prepare($args) { parent::prepare($args); $id = $this->trimmed('id'); if (!$id) { $this->clientError(_m('No ID.')); } $this->peopletag = Profile_list::staticGet('id', $id); if (empty($this->peopletag)) { $this->clientError(_m('No such list.')); } $oprofile = Ostatus_profile::staticGet('peopletag_id', $id); if (!empty($oprofile)) { $this->clientError(_m('Cannot accept remote posts for a remote list.')); } return true; } /** * We've gotten a follow/subscribe notification from a remote user. * Save a subscription relationship for them. */ /** * Postel's law: consider a "follow" notification as a "join". */ function handleFollow() { $this->handleSubscribe(); } /** * Postel's law: consider an "unfollow" notification as a "unsubscribe". */ function handleUnfollow() { $this->handleUnsubscribe(); } /** * A remote user subscribed. * @fixme move permission checks and event call into common code, * currently we're doing the main logic in joingroup action * and so have to repeat it here. */ function handleSubscribe() { $oprofile = $this->ensureProfile(); if (!$oprofile) { $this->clientError(_m('Cannot read profile to set up profile tag subscription.')); } if ($oprofile->isGroup()) { $this->clientError(_m('Groups cannot subscribe to lists.')); } common_log(LOG_INFO, "Remote profile {$oprofile->uri} subscribing to local peopletag ".$this->peopletag->getBestName()); $profile = $oprofile->localProfile(); if ($this->peopletag->hasSubscriber($profile)) { // Already a member; we'll take it silently to aid in resolving // inconsistencies on the other side. return true; } // should we block those whom the tagger has blocked from listening to // his own updates? try { Profile_tag_subscription::add($this->peopletag, $profile); } catch (Exception $e) { $this->serverError(sprintf(_m('Could not subscribe remote user %1$s to list %2$s.'), $oprofile->uri, $this->peopletag->getBestName())); } } /** * A remote user unsubscribed from our peopletag. */ function handleUnsubscribe() { $oprofile = $this->ensureProfile(); if (!$oprofile) { $this->clientError(_m('Cannot read profile to cancel list membership.')); } if ($oprofile->isGroup()) { $this->clientError(_m('Groups cannot subscribe to lists.')); } common_log(LOG_INFO, "Remote profile {$oprofile->uri} unsubscribing from local peopletag ".$this->peopletag->getBestName()); $profile = $oprofile->localProfile(); try { Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $profile->id); } catch (Exception $e) { $this->serverError(sprintf(_m('Could not remove remote user %1$s from list %2$s.'), $oprofile->uri, $this->peopletag->getBestName())); return; } } }