3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @package OStatusPlugin
24 if (!defined('STATUSNET')) {
28 class PeopletagsalmonAction extends SalmonAction
30 var $peopletag = null;
32 function prepare($args)
34 parent::prepare($args);
36 $id = $this->trimmed('id');
39 $this->clientError(_m('No ID.'));
42 $this->peopletag = Profile_list::staticGet('id', $id);
44 if (empty($this->peopletag)) {
45 $this->clientError(_m('No such list.'));
48 $oprofile = Ostatus_profile::staticGet('peopletag_id', $id);
50 if (!empty($oprofile)) {
51 $this->clientError(_m('Cannot accept remote posts for a remote list.'));
58 * We've gotten a follow/subscribe notification from a remote user.
59 * Save a subscription relationship for them.
63 * Postel's law: consider a "follow" notification as a "join".
65 function handleFollow()
67 $this->handleSubscribe();
71 * Postel's law: consider an "unfollow" notification as a "unsubscribe".
73 function handleUnfollow()
75 $this->handleUnsubscribe();
79 * A remote user subscribed.
80 * @fixme move permission checks and event call into common code,
81 * currently we're doing the main logic in joingroup action
82 * and so have to repeat it here.
85 function handleSubscribe()
87 $oprofile = $this->ensureProfile();
89 $this->clientError(_m('Cannot read profile to set up profile tag subscription.'));
91 if ($oprofile->isGroup()) {
92 $this->clientError(_m('Groups cannot subscribe to lists.'));
95 common_log(LOG_INFO, "Remote profile {$oprofile->uri} subscribing to local peopletag ".$this->peopletag->getBestName());
96 $profile = $oprofile->localProfile();
98 if ($this->peopletag->hasSubscriber($profile)) {
99 // Already a member; we'll take it silently to aid in resolving
100 // inconsistencies on the other side.
104 // should we block those whom the tagger has blocked from listening to
108 Profile_tag_subscription::add($this->peopletag, $profile);
109 } catch (Exception $e) {
110 $this->serverError(sprintf(_m('Could not subscribe remote user %1$s to list %2$s.'),
111 $oprofile->uri, $this->peopletag->getBestName()));
116 * A remote user unsubscribed from our peopletag.
119 function handleUnsubscribe()
121 $oprofile = $this->ensureProfile();
123 $this->clientError(_m('Cannot read profile to cancel list membership.'));
125 if ($oprofile->isGroup()) {
126 $this->clientError(_m('Groups cannot subscribe to lists.'));
129 common_log(LOG_INFO, "Remote profile {$oprofile->uri} unsubscribing from local peopletag ".$this->peopletag->getBestName());
130 $profile = $oprofile->localProfile();
133 Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $profile->id);
135 } catch (Exception $e) {
136 $this->serverError(sprintf(_m('Could not remove remote user %1$s from list %2$s.'),
137 $oprofile->uri, $this->peopletag->getBestName()));