2019-10-23 02:05:11 +02:00
|
|
|
<?php
|
2020-02-09 15:45:36 +01:00
|
|
|
/**
|
2023-01-01 15:36:24 +01:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2020-02-09 15:45:36 +01:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-10-23 02:05:11 +02:00
|
|
|
|
|
|
|
namespace Friendica\Protocol;
|
|
|
|
|
2019-10-25 00:34:46 +02:00
|
|
|
use Friendica\Protocol\ActivityNamespace;
|
2019-10-24 00:25:43 +02:00
|
|
|
|
2019-10-23 02:05:11 +02:00
|
|
|
/**
|
2019-10-25 00:10:20 +02:00
|
|
|
* Base class for the Activity Verbs
|
2019-10-23 02:05:11 +02:00
|
|
|
*/
|
|
|
|
final class Activity
|
|
|
|
{
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Indicates that the actor marked the object as an item of special interest.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const LIKE = ActivityNamespace::ACTIVITY_SCHEMA . 'like';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Dislike a message ("I don't like the post")
|
|
|
|
*
|
|
|
|
* @see http://purl.org/macgirvin/dfrn/1.0/dislike
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const DISLIKE = ActivityNamespace::DFRN . '/dislike';
|
2019-10-25 00:10:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attend an event
|
|
|
|
*
|
|
|
|
* @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attend
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const ATTEND = ActivityNamespace::ZOT . '/activity/attendyes';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Don't attend an event
|
|
|
|
*
|
|
|
|
* @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendno
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const ATTENDNO = ActivityNamespace::ZOT . '/activity/attendno';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Attend maybe an event
|
|
|
|
*
|
|
|
|
* @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendmaybe
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const ATTENDMAYBE = ActivityNamespace::ZOT . '/activity/attendmaybe';
|
2019-10-25 00:10:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates the creation of a friendship that is reciprocated by the object.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const FRIEND = ActivityNamespace::ACTIVITY_SCHEMA . 'make-friend';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Indicates the creation of a friendship that has not yet been reciprocated by the object.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const REQ_FRIEND = ActivityNamespace::ACTIVITY_SCHEMA . 'request-friend';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Indicates that the actor has removed the object from the collection of friends.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const UNFRIEND = ActivityNamespace::ACTIVITY_SCHEMA . 'remove-friend';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Indicates that the actor began following the activity of the object.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const FOLLOW = ActivityNamespace::ACTIVITY_SCHEMA . 'follow';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Indicates that the actor has stopped following the object.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const UNFOLLOW = ActivityNamespace::ACTIVITY_SCHEMA . 'stop-following';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Indicates that the actor has become a member of the object.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const JOIN = ActivityNamespace::ACTIVITY_SCHEMA . 'join';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Implementors SHOULD use verbs such as post where the actor is adding new items to a collection or similar.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const POST = ActivityNamespace::ACTIVITY_SCHEMA . 'post';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* The "update" verb indicates that the actor has modified the object.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const UPDATE = ActivityNamespace::ACTIVITY_SCHEMA . 'update';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Indicates that the actor has identified the presence of a target inside another object.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const TAG = ActivityNamespace::ACTIVITY_SCHEMA . 'tag';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Indicates that the actor marked the object as an item of special interest.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const FAVORITE = ActivityNamespace::ACTIVITY_SCHEMA . 'favorite';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Indicates that the actor has removed the object from the collection of favorited items.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const UNFAVORITE = ActivityNamespace::ACTIVITY_SCHEMA . 'unfavorite';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Indicates that the actor has called out the object to readers.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const SHARE = ActivityNamespace::ACTIVITY_SCHEMA . 'share';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Indicates that the actor has deleted the object.
|
|
|
|
*
|
|
|
|
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const DELETE = ActivityNamespace::ACTIVITY_SCHEMA . 'delete';
|
2019-10-25 00:10:20 +02:00
|
|
|
/**
|
|
|
|
* Indicates that the actor is calling the target's attention the object.
|
|
|
|
*
|
|
|
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-announce
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-10-25 00:32:35 +02:00
|
|
|
const ANNOUNCE = ActivityNamespace::ACTIVITY2 . 'Announce';
|
2022-12-26 09:41:40 +01:00
|
|
|
/**
|
|
|
|
* Indicates that the actor has read the object.
|
|
|
|
*
|
|
|
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-read
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-02-20 09:54:27 +01:00
|
|
|
const READ = ActivityNamespace::ACTIVITY2 . 'Read';
|
|
|
|
/**
|
|
|
|
* Indicates that the actor has listened to the object.
|
|
|
|
*
|
|
|
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-listen
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const LISTEN = ActivityNamespace::ACTIVITY2 . 'Listen';
|
2022-04-04 18:03:53 +02:00
|
|
|
/**
|
2023-02-20 07:41:28 +01:00
|
|
|
* Indicates that the actor has viewed the object.
|
2022-04-04 18:03:53 +02:00
|
|
|
*
|
2023-02-20 07:41:28 +01:00
|
|
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-view
|
2022-04-04 18:03:53 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
2023-02-20 09:54:27 +01:00
|
|
|
const VIEW = ActivityNamespace::ACTIVITY2 . 'View';
|
2023-02-20 07:41:28 +01:00
|
|
|
|
|
|
|
const O_UNFOLLOW = ActivityNamespace::OSTATUS . '/unfollow';
|
|
|
|
const O_UNFAVOURITE = ActivityNamespace::OSTATUS . '/unfavorite';
|
2022-04-04 18:03:53 +02:00
|
|
|
|
2022-04-05 09:48:38 +02:00
|
|
|
/**
|
2023-02-20 07:41:28 +01:00
|
|
|
* React to a post via an emoji
|
2022-04-05 09:48:38 +02:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-02-20 07:41:28 +01:00
|
|
|
const EMOJIREACT = ActivityNamespace::LITEPUB . '/emojireact';
|
2022-04-05 09:48:38 +02:00
|
|
|
|
2019-10-24 00:25:43 +02:00
|
|
|
/**
|
|
|
|
* likes (etc.) can apply to other things besides posts. Check if they are post children,
|
|
|
|
* in which case we handle them specially
|
|
|
|
*
|
|
|
|
* Hidden activities, which doesn't need to be shown
|
|
|
|
*/
|
|
|
|
const HIDDEN_ACTIVITIES = [
|
2022-04-04 18:03:53 +02:00
|
|
|
self::LIKE, self::DISLIKE,
|
|
|
|
self::ATTEND, self::ATTENDNO, self::ATTENDMAYBE,
|
|
|
|
self::FOLLOW,
|
|
|
|
self::ANNOUNCE,
|
|
|
|
self::EMOJIREACT,
|
2022-04-05 09:48:38 +02:00
|
|
|
self::VIEW,
|
2022-12-26 09:41:40 +01:00
|
|
|
self::READ,
|
2019-10-24 00:25:43 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given activity is a hidden activity
|
|
|
|
*
|
|
|
|
* @param string $activity The current activity
|
|
|
|
*
|
|
|
|
* @return bool True, if the activity is hidden
|
|
|
|
*/
|
2022-06-16 14:59:29 +02:00
|
|
|
public function isHidden(string $activity): bool
|
2019-10-24 00:25:43 +02:00
|
|
|
{
|
|
|
|
foreach (self::HIDDEN_ACTIVITIES as $hiddenActivity) {
|
|
|
|
if ($this->match($activity, $hiddenActivity)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-23 02:05:11 +02:00
|
|
|
/**
|
|
|
|
* Compare activity uri. Knows about activity namespace.
|
|
|
|
*
|
|
|
|
* @param string $haystack
|
|
|
|
* @param string $needle
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2022-06-16 14:59:29 +02:00
|
|
|
public function match(string $haystack, string $needle): bool
|
2019-10-24 00:25:43 +02:00
|
|
|
{
|
2019-10-23 02:05:11 +02:00
|
|
|
return (($haystack === $needle) ||
|
|
|
|
((basename($needle) === $haystack) &&
|
2019-10-25 00:32:35 +02:00
|
|
|
strstr($needle, ActivityNamespace::ACTIVITY_SCHEMA)));
|
2019-10-23 02:05:11 +02:00
|
|
|
}
|
|
|
|
}
|