X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FWorker%2FNotifier.php;h=ad33c3245d4be9d33e1381cb9d1cb00b40851842;hb=514ec1be6df161df5cb48c033917ac2e94484f0f;hp=6a371861866890736932494b68736f506b001b46;hpb=e4d28629e43f829877336f4207edd304069f9ed8;p=friendica.git diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 6a37186186..ad33c3245d 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -16,9 +16,11 @@ use Friendica\Model\Item; use Friendica\Model\PushSubscriber; use Friendica\Model\User; use Friendica\Network\Probe; +use Friendica\Protocol\ActivityPub; use Friendica\Protocol\Diaspora; use Friendica\Protocol\OStatus; use Friendica\Protocol\Salmon; +use Friendica\Model\Conversation; require_once 'include/dba.php'; require_once 'include/items.php'; @@ -98,6 +100,14 @@ class Notifier foreach ($r as $contact) { Contact::terminateFriendship($user, $contact, true); } + + $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0); + foreach ($inboxes as $inbox) { + logger('Account removal for user ' . $item_id . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); + Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true], + 'APDelivery', Delivery::REMOVAL, '', $inbox, $item_id); + } + return; } elseif ($cmd == Delivery::RELOCATION) { $normal_mode = false; @@ -167,6 +177,8 @@ class Notifier if (!in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION, Delivery::RELOCATION])) { $parent = $items[0]; + self::activityPubDelivery($a, $cmd, $item_id, $uid, $target_item, $parent); + $fields = ['network', 'author-id', 'owner-id']; $condition = ['uri' => $target_item["thr-parent"], 'uid' => $target_item["uid"]]; $thr_parent = Item::selectFirst($fields, $condition); @@ -182,7 +194,7 @@ class Notifier // if $parent['wall'] == 1 we will already have the parent message in our array // and we will relay the whole lot. - $localhost = str_replace('www.','',$a->get_hostname()); + $localhost = str_replace('www.','',$a->getHostName()); if (strpos($localhost,':')) { $localhost = substr($localhost,0,strpos($localhost,':')); } @@ -363,9 +375,9 @@ class Notifier } // It only makes sense to distribute answers to OStatus messages to Friendica and OStatus - but not Diaspora - $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DFRN]; + $networks = [Protocol::OSTATUS, Protocol::DFRN]; } else { - $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA, Protocol::MAIL]; + $networks = [Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA, Protocol::MAIL]; } } else { $public_message = false; @@ -448,7 +460,7 @@ class Notifier } } - $condition = ['network' => [Protocol::DFRN, Protocol::ACTIVITYPUB], 'uid' => $owner['uid'], 'blocked' => false, + $condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false, 'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; $r2 = DBA::toArray(DBA::select('contact', ['id', 'name', 'network'], $condition)); @@ -497,6 +509,41 @@ class Notifier return; } + private static function activityPubDelivery($a, $cmd, $item_id, $uid, $target_item, $parent) + { + $inboxes = []; + + if ($target_item['origin']) { + $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid); + logger('Origin item ' . $item_id . ' with URL ' . $target_item['uri'] . ' will be distributed.', LOGGER_DEBUG); + } elseif (!DBA::exists('conversation', ['item-uri' => $target_item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB])) { + logger('Remote item ' . $item_id . ' with URL ' . $target_item['uri'] . ' is no AP post. It will not be distributed.', LOGGER_DEBUG); + return; + } else { + logger('Remote item ' . $item_id . ' with URL ' . $target_item['uri'] . ' will be distributed.', LOGGER_DEBUG); + } + + if ($parent['origin']) { + $parent_inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid); + $inboxes = array_merge($inboxes, $parent_inboxes); + } + + if (empty($inboxes)) { + logger('No inboxes found for item ' . $item_id . ' with URL ' . $target_item['uri'] . '. It will not be distributed.', LOGGER_DEBUG); + return; + } + + // Fill the item cache + ActivityPub\Transmitter::createCachedActivityFromItem($item_id); + + foreach ($inboxes as $inbox) { + logger('Deliver ' . $item_id .' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); + + Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true], + 'APDelivery', $cmd, $item_id, $inbox, $uid); + } + } + private static function isForumPost($item, $owner) { if (($item['author-id'] == $item['owner-id']) || ($owner['id'] == $item['contact-id']) ||