]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/Delivery.php
Missing $a to $this conversion in App
[friendica.git] / src / Worker / Delivery.php
index 32bcdfcc40c137b8cea6d42fa32d11fc5d73c256..e0a5c09c270d48ec72a8379d880a44c6d82c8fcf 100644 (file)
@@ -7,6 +7,7 @@ namespace Friendica\Worker;
 use Friendica\BaseObject;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
+use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
@@ -156,23 +157,23 @@ class Delivery extends BaseObject
 
                // Transmit via Diaspora if the thread had started as Diaspora post
                // This is done since the uri wouldn't match (Diaspora doesn't transmit it)
-               if (isset($parent) && ($parent['network'] == NETWORK_DIASPORA) && ($contact['network'] == NETWORK_DFRN)) {
-                       $contact['network'] = NETWORK_DIASPORA;
+               if (isset($parent) && ($parent['network'] == Protocol::DIASPORA) && ($contact['network'] == Protocol::DFRN)) {
+                       $contact['network'] = Protocol::DIASPORA;
                }
 
                logger("Delivering " . $cmd . " followup=$followup - via network " . $contact['network']);
 
                switch ($contact['network']) {
 
-                       case NETWORK_DFRN:
+                       case Protocol::DFRN:
                                self::deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup);
                                break;
 
-                       case NETWORK_DIASPORA:
+                       case Protocol::DIASPORA:
                                self::deliverDiaspora($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup);
                                break;
 
-                       case NETWORK_OSTATUS:
+                       case Protocol::OSTATUS:
                                // Do not send to otatus if we are not configured to send to public networks
                                if ($owner['prvnets']) {
                                        break;
@@ -185,7 +186,7 @@ class Delivery extends BaseObject
                                // This is done in "notifier.php" (See "url_recipients" and "push_notify")
                                break;
 
-                       case NETWORK_MAIL:
+                       case Protocol::MAIL:
                                self::deliverMail($cmd, $contact, $owner, $target_item);
                                break;
 
@@ -262,29 +263,12 @@ class Delivery extends BaseObject
                                }
                        }
 
-                       // We now have some contact, so we fetch it
-                       $target_importer = DBA::fetchFirst("SELECT *, `name` as `senderName`
-                                                       FROM `contact`
-                                                       WHERE NOT `blocked` AND `id` = ? LIMIT 1",
-                                                       $cid);
-
-                       // This should never fail
-                       if (!DBA::isResult($target_importer)) {
-                               return;
-                       }
-
-                       $user = DBA::selectFirst('user', [], ['uid' => $target_uid]);
-
-                       // This should also never fail
-                       if (!DBA::isResult($user)) {
-                               logger('No user found for uid ' . $target_uid);
+                       $target_importer = DFRN::getImporter($cid, $target_uid);
+                       if (empty($target_importer)) {
+                               // This should never happen
                                return;
                        }
 
-                       $target_importer = array_merge($target_importer, $user);
-
-                       // Set the user id. This is important if this is a public contact
-                       $target_importer['importer_uid']  = $target_uid;
                        DFRN::import($atom, $target_importer);
                        return;
                }
@@ -316,7 +300,7 @@ class Delivery extends BaseObject
 
                if ($deliver_status < 0) {
                        logger('Delivery failed: queuing message ' . $target_item["guid"] );
-                       Queue::add($contact['id'], NETWORK_DFRN, $atom, false, $target_item['guid']);
+                       Queue::add($contact['id'], Protocol::DFRN, $atom, false, $target_item['guid']);
                }
 
                if (($deliver_status >= 200) && ($deliver_status <= 299)) {
@@ -460,25 +444,30 @@ class Delivery extends BaseObject
                        if (($target_item["thr-parent"] != "") && ($target_item["thr-parent"] != $target_item["parent-uri"])) {
                                $headers .= " <".Email::iri2msgid($target_item["thr-parent"]).">";
                        }
+
                        $headers .= "\n";
 
                        if (empty($target_item['title'])) {
                                $condition = ['uri' => $target_item['parent-uri'], 'uid' => $owner['uid']];
                                $title = Item::selectFirst(['title'], $condition);
+
                                if (DBA::isResult($title) && ($title['title'] != '')) {
                                        $subject = $title['title'];
                                } else {
                                        $condition = ['parent-uri' => $target_item['parent-uri'], 'uid' => $owner['uid']];
                                        $title = Item::selectFirst(['title'], $condition);
+
                                        if (DBA::isResult($title) && ($title['title'] != '')) {
                                                $subject = $title['title'];
                                        }
                                }
                        }
+
                        if (strncasecmp($subject, 'RE:', 3)) {
                                $subject = 'Re: ' . $subject;
                        }
                }
+
                Email::send($addr, $subject, $headers, $target_item);
        }
 }