+ // delivery loop
+ while ($contact = DBA::fetch($delivery_contacts_stmt)) {
+ if (Config::get('debug', 'total_ap_delivery') && ($contact['network'] == Protocol::DFRN) && !empty(APContact::getByURL($contact['url'], false))) {
+ Logger::log('Skipping contact ' . $contact['url'] . ' since it will be delivered via AP', Logger::DEBUG);
+ continue;
+ }
+
+ // Don't deliver to Diaspora if it already had been done as batch delivery
+ if (($contact['network'] == Protocol::DIASPORA) && $batch_delivery) {
+ Logger::log('Already delivered id ' . $target_id . ' via batch to ' . json_encode($contact), Logger::DEBUG);
+ continue;
+ }
+
+ // Don't deliver to folks who have already been delivered to
+ if (in_array($contact['id'], $conversants)) {
+ Logger::log('Already delivered id ' . $target_id. ' to ' . json_encode($contact), Logger::DEBUG);
+ continue;
+ }
+
+ $delivery_queue_count++;
+
+ Logger::log('Delivery of item ' . $target_id . ' to ' . json_encode($contact), Logger::DEBUG);
+
+ // Ensure that posts with our own protocol arrives before Diaspora posts arrive.
+ // Situation is that sometimes Friendica servers receive Friendica posts over the Diaspora protocol first.
+ // The conversion in Markdown reduces the formatting, so these posts should arrive after the Friendica posts.
+ if ($contact['network'] == Protocol::DIASPORA) {
+ $deliver_options = ['priority' => $a->queue['priority'], 'dont_fork' => true];
+ } else {
+ $deliver_options = ['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true];
+ }
+ Worker::add($deliver_options, 'Delivery', $cmd, $target_id, (int)$contact['id']);
+ }
+ DBA::close($delivery_contacts_stmt);
+
+
+ $url_recipients = array_filter($url_recipients);
+ // send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts
+ // They are especially used for notifications to OStatus users that don't follow us.
+ if (!Config::get('system', 'dfrn_only') && count($url_recipients) && ($public_message || $push_notify) && !empty($target_item)) {
+ $delivery_queue_count += count($url_recipients);
+ $slap = OStatus::salmon($target_item, $owner);
+ foreach ($url_recipients as $url) {
+ Logger::log('Salmon delivery of item ' . $target_id . ' to ' . $url);
+ /// @TODO Redeliver/queue these items on failure, though there is no contact record
+ Salmon::slapper($owner, $url, $slap);
+ ItemDeliveryData::incrementQueueDone($target_id);
+ }
+ }
+