]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/actions/peopletagsalmon.php
Merge branch 'master' into social-master
[quix0rs-gnu-social.git] / plugins / OStatus / actions / peopletagsalmon.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 /**
21  * @package OStatusPlugin
22  */
23
24 if (!defined('GNUSOCIAL')) { exit(1); }
25
26 class PeopletagsalmonAction extends SalmonAction
27 {
28     var $peopletag = null;
29
30     protected function prepare(array $args=array())
31     {
32         parent::prepare($args);
33
34         $id = $this->trimmed('id');
35
36         if (!$id) {
37             // TRANS: Client error displayed trying to perform an action without providing an ID.
38             $this->clientError(_m('No ID.'));
39         }
40
41         $this->peopletag = Profile_list::getKV('id', $id);
42
43         if (!$this->peopletag instanceof Profile_list) {
44             // TRANS: Client error displayed when referring to a non-existing list.
45             $this->clientError(_m('No such list.'));
46         }
47
48         $this->target = $this->peopletag;
49
50         $remote_list = Ostatus_profile::getKV('peopletag_id', $id);
51
52         if ($remote_list instanceof Ostatus_profile) {
53             // TRANS: Client error displayed when trying to send a message to a remote list.
54             $this->clientError(_m('Cannot accept remote posts for a remote list.'));
55         }
56
57         return true;
58     }
59
60     /**
61      * We've gotten a follow/subscribe notification from a remote user.
62      * Save a subscription relationship for them.
63      */
64
65     /**
66      * Postel's law: consider a "follow" notification as a "join".
67      */
68     function handleFollow()
69     {
70         $this->handleSubscribe();
71     }
72
73     /**
74      * Postel's law: consider an "unfollow" notification as a "unsubscribe".
75      */
76     function handleUnfollow()
77     {
78         $this->handleUnsubscribe();
79     }
80
81     /**
82      * A remote user subscribed.
83      * @fixme move permission checks and event call into common code,
84      *        currently we're doing the main logic in joingroup action
85      *        and so have to repeat it here.
86      */
87     function handleSubscribe()
88     {
89         if ($this->oprofile->isGroup()) {
90             // TRANS: Client error displayed when trying to subscribe a group to a list.
91             $this->clientError(_m('Groups cannot subscribe to lists.'));
92         }
93
94         common_log(LOG_INFO, sprintf('Remote profile %s subscribing to local peopletag %s', $this->oprofile->getUri(), $this->peopletag->getBestName()));
95         if ($this->peopletag->hasSubscriber($this->actor)) {
96             // Already a member; we'll take it silently to aid in resolving
97             // inconsistencies on the other side.
98             return true;
99         }
100
101         // should we block those whom the tagger has blocked from listening to
102         // his own updates?
103
104         try {
105             Profile_tag_subscription::add($this->peopletag, $this->actor);
106         } catch (Exception $e) {
107             // TRANS: Server error displayed when subscribing a remote user to a list fails.
108             // TRANS: %1$s is a profile URI, %2$s is a list name.
109             $this->serverError(sprintf(_m('Could not subscribe remote user %1$s to list %2$s.'),
110                                        $this->oprofile->getUri(), $this->peopletag->getBestName()));
111         }
112     }
113
114     /**
115      * A remote user unsubscribed from our list.
116      *
117      * @return void
118      * @throws Exception through clientError and serverError
119      */
120     function handleUnsubscribe()
121     {
122         if ($this->oprofile->isGroup()) {
123             // TRANS: Client error displayed when trying to unsubscribe a group from a list.
124             $this->clientError(_m('Groups cannot subscribe to lists.'));
125         }
126
127         common_log(LOG_INFO, sprintf('Remote profile %s unsubscribing from local peopletag %s', $this->oprofile->getUri(), $this->peopletag->getBestName()));
128         try {
129             Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $this->actor->id);
130         } catch (Exception $e) {
131             // TRANS: Client error displayed when trying to unsubscribe a remote user from a list fails.
132             // TRANS: %1$s is a profile URL, %2$s is a list name.
133             $this->serverError(sprintf(_m('Could not unsubscribe remote user %1$s from list %2$s.'),
134                                        $this->oprofile->getUri(), $this->peopletag->getBestName()));
135         }
136     }
137 }