+
+ /**
+ * @param int $self_user_id
+ * @param int $priority The priority the Notifier queue item was created with
+ * @param string $created The date the Notifier queue item was created on
+ * @return bool
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ private static function notifySelfRemoval($self_user_id, $priority, $created)
+ {
+ $owner = User::getOwnerDataById($self_user_id);
+ if (!$owner) {
+ return false;
+ }
+
+ $contacts_stmt = DBA::select('contact', [], ['self' => false, 'uid' => $self_user_id]);
+ if (!DBA::isResult($contacts_stmt)) {
+ return false;
+ }
+
+ while($contact = DBA::fetch($contacts_stmt)) {
+ Contact::terminateFriendship($owner, $contact, true);
+ }
+ DBA::close($contacts_stmt);
+
+ $inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0);
+ foreach ($inboxes as $inbox) {
+ Logger::log('Account removal for user ' . $self_user_id . ' to ' . $inbox .' via ActivityPub', Logger::DEBUG);
+ Worker::add(['priority' => PRIORITY_NEGLIGIBLE, 'created' => $created, 'dont_fork' => true],
+ 'APDelivery', Delivery::REMOVAL, '', $inbox, $self_user_id);
+ }
+
+ return true;
+ }
+
+ /**
+ * @param string $cmd
+ * @param array $target_item
+ * @param array $parent
+ * @param int $priority The priority the Notifier queue item was created with
+ * @param string $created The date the Notifier queue item was created on
+ * @return int The number of delivery tasks created
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ private static function activityPubDelivery($cmd, array $target_item, array $parent, $priority, $created)
+ {
+ $inboxes = [];
+
+ $uid = $target_item['contact-uid'] ?: $target_item['uid'];
+
+ if ($target_item['origin']) {
+ $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid);
+ Logger::log('Origin item ' . $target_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::log('Remote item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' is no AP post. It will not be distributed.', Logger::DEBUG);
+ return 0;
+ } elseif ($parent['origin']) {
+ // Remote items are transmitted via the personal inboxes.
+ // Doing so ensures that the dedicated receiver will get the message.
+ $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid, true, $target_item['id']);
+ Logger::log('Remote item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.', Logger::DEBUG);
+ }
+
+ if (empty($inboxes)) {
+ Logger::log('No inboxes found for item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . '. It will not be distributed.', Logger::DEBUG);
+ return 0;
+ }
+
+ // Fill the item cache
+ ActivityPub\Transmitter::createCachedActivityFromItem($target_item['id'], true);
+
+ foreach ($inboxes as $inbox) {
+ Logger::log('Deliver ' . $target_item['id'] .' to ' . $inbox .' via ActivityPub', Logger::DEBUG);
+
+ Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true],
+ 'APDelivery', $cmd, $target_item['id'], $inbox, $uid);
+ }
+
+ return count($inboxes);
+ }
+
+ private static function isForumPost(array $item, array $owner)
+ {
+ if (($item['author-id'] == $item['owner-id']) ||
+ ($owner['id'] == $item['contact-id']) ||
+ ($item['uri'] != $item['parent-uri'])) {
+ return false;
+ }
+
+ return self::isForum($item['contact-id']);
+ }
+
+ private static function isForum($contactid)
+ {
+ $fields = ['forum', 'prv'];
+ $condition = ['id' => $contactid];
+ $contact = DBA::selectFirst('contact', $fields, $condition);
+ if (!DBA::isResult($contact)) {
+ // Should never happen
+ return false;
+ }
+
+ // Is it a forum?
+ return ($contact['forum'] || $contact['prv']);
+ }