]> git.mxchange.org Git - friendica.git/blob - src/Protocol/Activity.php
Merge pull request #9772 from annando/deliver-via-ap
[friendica.git] / src / Protocol / Activity.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Protocol;
23
24 use Friendica\Protocol\ActivityNamespace;
25
26 /**
27  * Base class for the Activity Verbs
28  */
29 final class Activity
30 {
31         /**
32          * Indicates that the actor marked the object as an item of special interest.
33          *
34          * @see http://activitystrea.ms/head/activity-schema.html#verbs
35          * @var string
36          */
37         const LIKE = ActivityNamespace::ACTIVITY_SCHEMA . 'like';
38         /**
39          * Dislike a message ("I don't like the post")
40          *
41          * @see http://purl.org/macgirvin/dfrn/1.0/dislike
42          * @var string
43          */
44         const DISLIKE = ActivityNamespace::DFRN . '/dislike';
45
46         /**
47          * Attend an event
48          *
49          * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attend
50          * @var string
51          */
52         const ATTEND      = ActivityNamespace::ZOT . '/activity/attendyes';
53         /**
54          * Don't attend an event
55          *
56          * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendno
57          * @var string
58          */
59         const ATTENDNO    = ActivityNamespace::ZOT . '/activity/attendno';
60         /**
61          * Attend maybe an event
62          *
63          * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendmaybe
64          * @var string
65          */
66         const ATTENDMAYBE = ActivityNamespace::ZOT . '/activity/attendmaybe';
67
68         /**
69          * Indicates the creation of a friendship that is reciprocated by the object.
70          *
71          * @see http://activitystrea.ms/head/activity-schema.html#verbs
72          * @var string
73          */
74         const FRIEND      = ActivityNamespace::ACTIVITY_SCHEMA . 'make-friend';
75         /**
76          * Indicates the creation of a friendship that has not yet been reciprocated by the object.
77          *
78          * @see http://activitystrea.ms/head/activity-schema.html#verbs
79          * @var string
80          */
81         const REQ_FRIEND = ActivityNamespace::ACTIVITY_SCHEMA . 'request-friend';
82         /**
83          * Indicates that the actor has removed the object from the collection of friends.
84          *
85          * @see http://activitystrea.ms/head/activity-schema.html#verbs
86          * @var string
87          */
88         const UNFRIEND   = ActivityNamespace::ACTIVITY_SCHEMA . 'remove-friend';
89         /**
90          * Indicates that the actor began following the activity of the object.
91          *
92          * @see http://activitystrea.ms/head/activity-schema.html#verbs
93          * @var string
94          */
95         const FOLLOW     = ActivityNamespace::ACTIVITY_SCHEMA . 'follow';
96         /**
97          * Indicates that the actor has stopped following the object.
98          *
99          * @see http://activitystrea.ms/head/activity-schema.html#verbs
100          * @var string
101          */
102         const UNFOLLOW   = ActivityNamespace::ACTIVITY_SCHEMA . 'stop-following';
103         /**
104          * Indicates that the actor has become a member of the object.
105          *
106          * @see http://activitystrea.ms/head/activity-schema.html#verbs
107          * @var string
108          */
109         const JOIN       = ActivityNamespace::ACTIVITY_SCHEMA . 'join';
110         /**
111          * Implementors SHOULD use verbs such as post where the actor is adding new items to a collection or similar.
112          *
113          * @see http://activitystrea.ms/head/activity-schema.html#verbs
114          * @var string
115          */
116         const POST       = ActivityNamespace::ACTIVITY_SCHEMA . 'post';
117         /**
118          * The "update" verb indicates that the actor has modified the object.
119          *
120          * @see http://activitystrea.ms/head/activity-schema.html#verbs
121          * @var string
122          */
123         const UPDATE     = ActivityNamespace::ACTIVITY_SCHEMA . 'update';
124         /**
125          * Indicates that the actor has identified the presence of a target inside another object.
126          *
127          * @see http://activitystrea.ms/head/activity-schema.html#verbs
128          * @var string
129          */
130         const TAG        = ActivityNamespace::ACTIVITY_SCHEMA . 'tag';
131         /**
132          * Indicates that the actor marked the object as an item of special interest.
133          *
134          * @see http://activitystrea.ms/head/activity-schema.html#verbs
135          * @var string
136          */
137         const FAVORITE   = ActivityNamespace::ACTIVITY_SCHEMA . 'favorite';
138         /**
139          * Indicates that the actor has removed the object from the collection of favorited items.
140          *
141          * @see http://activitystrea.ms/head/activity-schema.html#verbs
142          * @var string
143          */
144         const UNFAVORITE = ActivityNamespace::ACTIVITY_SCHEMA . 'unfavorite';
145         /**
146          * Indicates that the actor has called out the object to readers.
147          *
148          * @see http://activitystrea.ms/head/activity-schema.html#verbs
149          * @var string
150          */
151         const SHARE      = ActivityNamespace::ACTIVITY_SCHEMA . 'share';
152         /**
153          * Indicates that the actor has deleted the object.
154          *
155          * @see http://activitystrea.ms/head/activity-schema.html#verbs
156          * @var string
157          */
158         const DELETE     = ActivityNamespace::ACTIVITY_SCHEMA . 'delete';
159         /**
160          * Indicates that the actor is calling the target's attention the object.
161          *
162          * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-announce
163          * @var string
164          */
165         const ANNOUNCE   = ActivityNamespace::ACTIVITY2 . 'Announce';
166
167         /**
168          * Pokes an user.
169          *
170          * @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_poke
171          * @var string
172          */
173         const POKE       = ActivityNamespace::ZOT . '/activity/poke';
174
175
176         const O_UNFOLLOW    = ActivityNamespace::OSTATUS . '/unfollow';
177         const O_UNFAVOURITE = ActivityNamespace::OSTATUS . '/unfavorite';
178
179         /**
180          * likes (etc.) can apply to other things besides posts. Check if they are post children,
181          * in which case we handle them specially
182          *
183          * Hidden activities, which doesn't need to be shown
184          */
185         const HIDDEN_ACTIVITIES = [
186                 Activity::LIKE, Activity::DISLIKE,
187                 Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE,
188                 Activity::FOLLOW,
189                 Activity::ANNOUNCE,
190         ];
191
192         /**
193          * Checks if the given activity is a hidden activity
194          *
195          * @param string $activity The current activity
196          *
197          * @return bool True, if the activity is hidden
198          */
199         public function isHidden(string $activity)
200         {
201                 foreach (self::HIDDEN_ACTIVITIES as $hiddenActivity) {
202                         if ($this->match($activity, $hiddenActivity)) {
203                                 return true;
204                         }
205                 }
206
207                 return false;
208         }
209
210         /**
211          * Compare activity uri. Knows about activity namespace.
212          *
213          * @param string $haystack
214          * @param string $needle
215          *
216          * @return boolean
217          */
218         public function match(string $haystack, string $needle)
219         {
220                 return (($haystack === $needle) ||
221                         ((basename($needle) === $haystack) &&
222                          strstr($needle, ActivityNamespace::ACTIVITY_SCHEMA)));
223         }
224 }