mirror of
https://github.com/friendica/friendica
synced 2025-04-26 17:50:11 +00:00
Move activity_match() to Protocol\Activity::match()
- With tests
This commit is contained in:
parent
9e94e8b48c
commit
52c42491c4
9 changed files with 135 additions and 37 deletions
23
src/Protocol/Activity.php
Normal file
23
src/Protocol/Activity.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Protocol;
|
||||
|
||||
/**
|
||||
* Base class for the Activity namespace
|
||||
*/
|
||||
final class Activity
|
||||
{
|
||||
/**
|
||||
* Compare activity uri. Knows about activity namespace.
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string $needle
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function match(string $haystack, string $needle) {
|
||||
return (($haystack === $needle) ||
|
||||
((basename($needle) === $haystack) &&
|
||||
strstr($needle, NAMESPACE_ACTIVITY_SCHEMA)));
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@ use DOMDocument;
|
|||
use DOMXPath;
|
||||
use Friendica\App;
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Content\OEmbed;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Content\Text\HTML;
|
||||
|
@ -2180,24 +2181,27 @@ class DFRN
|
|||
// The functions below are partly used by ostatus.php as well - where we have this variable
|
||||
$contact = Contact::selectFirst([], ['id' => $importer['id']]);
|
||||
|
||||
/** @var Activity $activity */
|
||||
$activity = BaseObject::getClass(Activity::class);
|
||||
|
||||
// Big question: Do we need these functions? They were part of the "consume_feed" function.
|
||||
// This function once was responsible for DFRN and OStatus.
|
||||
if (activity_match($item["verb"], ACTIVITY_FOLLOW)) {
|
||||
if ($activity->match($item["verb"], ACTIVITY_FOLLOW)) {
|
||||
Logger::log("New follower");
|
||||
Contact::addRelationship($importer, $contact, $item);
|
||||
return false;
|
||||
}
|
||||
if (activity_match($item["verb"], ACTIVITY_UNFOLLOW)) {
|
||||
if ($activity->match($item["verb"], ACTIVITY_UNFOLLOW)) {
|
||||
Logger::log("Lost follower");
|
||||
Contact::removeFollower($importer, $contact, $item);
|
||||
return false;
|
||||
}
|
||||
if (activity_match($item["verb"], ACTIVITY_REQ_FRIEND)) {
|
||||
if ($activity->match($item["verb"], ACTIVITY_REQ_FRIEND)) {
|
||||
Logger::log("New friend request");
|
||||
Contact::addRelationship($importer, $contact, $item, true);
|
||||
return false;
|
||||
}
|
||||
if (activity_match($item["verb"], ACTIVITY_UNFRIEND)) {
|
||||
if ($activity->match($item["verb"], ACTIVITY_UNFRIEND)) {
|
||||
Logger::log("Lost sharer");
|
||||
Contact::removeSharer($importer, $contact, $item);
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue