From c437dac3a0aee6c82835703779a5cd6eb5e3e65e Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Wed, 25 Apr 2018 21:55:24 +0000
Subject: [PATCH] Delivery to non followers

---
 src/Worker/Delivery.php | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php
index e8c21fb38d..efeabae584 100644
--- a/src/Worker/Delivery.php
+++ b/src/Worker/Delivery.php
@@ -168,11 +168,6 @@ class Delivery {
 
 		$deliver_status = 0;
 
-		// Transmit via Diaspora if not possible via Friendica
-		if (($item['uid'] == 0) && ($contact['network'] == NETWORK_DFRN)) {
-			$contact['network'] = NETWORK_DIASPORA;
-		}
-
 		logger("Delivering " . $cmd . " followup=$followup - network ".$contact['network']);
 
 		switch ($contact['network']) {
@@ -301,10 +296,14 @@ class Delivery {
 			return;
 		}
 
-		if (!Queue::wasDelayed($contact['id'])) {
+		if ($items[0]['uid'] == 0) {
+			$deliver_status = DFRN::transmit($owner, $contact, $atom);
+			if ($deliver_status < 200) {
+				// Transmit via Diaspora if not possible via Friendica
+				self::deliverDiaspora($cmd, $contact, $owner, $target_item, $public_message, $top_level, $followup, false);
+				return;
+			}
 			$deliver_status = DFRN::deliver($owner, $contact, $atom);
-		} else {
-			$deliver_status = -1;
 		}
 
 		logger('notifier: dfrn_delivery to '.$contact["url"].' with guid '.$target_item["guid"].' returns '.$deliver_status);
@@ -377,6 +376,8 @@ class Delivery {
 
 	private static function deliverMail($cmd, $contact, $owner, $target_item)
 	{
+		global $a;
+
 		if (Config::get('system','dfrn_only')) {
 			return;
 		}
@@ -402,7 +403,7 @@ class Delivery {
 			$reply_to = $mailacct['reply_to'];
 		}
 
-		$subject  = (($target_item['title']) ? Email::encodeHeader($target_item['title'], 'UTF-8') : L10n::t("\x28no subject\x29"));
+		$subject  = ($target_item['title'] ? Email::encodeHeader($target_item['title'], 'UTF-8') : L10n::t("\x28no subject\x29"));
 
 		// only expose our real email address to true friends
 
@@ -445,7 +446,7 @@ class Delivery {
 				$subject = 'Re: ' . $subject;
 			}
 		}
-		Email::send($addr, $subject, $headers, $it);
+		Email::send($addr, $subject, $headers, $target_item);
 	}
 
 	private static function getItemContact($item, $contacts)
-- 
2.39.5