]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/Delivery.php
New item functions are now used in the delivery process as well
[friendica.git] / src / Worker / Delivery.php
index f874e5f23024069200f284e6fa7edff11655073c..15273762ab3808ec7f446be413998cad84ee05bd 100644 (file)
@@ -28,6 +28,7 @@ class Delivery extends BaseObject
        const DELETION =   'drop';
        const POST =       'wall-new';
        const COMMENT =    'comment-new';
+       const REMOVAL =    'removeme';
 
        public static function execute($cmd, $item_id, $contact_id)
        {
@@ -39,13 +40,13 @@ class Delivery extends BaseObject
 
                if ($cmd == self::MAIL) {
                        $target_item = dba::selectFirst('mail', [], ['id' => $item_id]);
-                       if (!DBM::is_result($message)) {
+                       if (!DBM::is_result($target_item)) {
                                return;
                        }
                        $uid = $target_item['uid'];
                } elseif ($cmd == self::SUGGESTION) {
                        $target_item = dba::selectFirst('fsuggest', [], ['id' => $item_id]);
-                       if (!DBM::is_result($message)) {
+                       if (!DBM::is_result($target_item)) {
                                return;
                        }
                        $uid = $target_item['uid'];
@@ -58,14 +59,10 @@ class Delivery extends BaseObject
                        }
                        $parent_id = intval($item['parent']);
 
-                       $itemdata = dba::p("SELECT `item`.*, `contact`.`uid` AS `cuid`,
-                                                       `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer`
-                                               FROM `item`
-                                               INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
-                                               LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
-                                               WHERE `item`.`id` IN (?, ?) AND `visible` AND NOT `moderated`
-                                               ORDER BY `item`.`id`",
-                                       $item_id, $parent_id);
+                       $condition = ['id' => [$item_id, $parent_id], 'visible' => true, 'moderated' => false];
+                       $params = ['order' => ['id']];
+                       $itemdata = Item::select([], $condition, $params);
+
                        $items = [];
                        while ($item = dba::fetch($itemdata)) {
                                if ($item['id'] == $parent_id) {
@@ -78,7 +75,7 @@ class Delivery extends BaseObject
                        }
                        dba::close($itemdata);
 
-                       $uid = $target_item['cuid'];
+                       $uid = $target_item['contact-uid'];
 
                        // avoid race condition with deleting entries
                        if ($items[0]['deleted']) {
@@ -199,7 +196,7 @@ class Delivery extends BaseObject
         */
        private static function deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup)
        {
-               logger('Deliver ' . $target_item["guid"] . ' via DFRN to ' . $contact['addr']);
+               logger('Deliver ' . $target_item["guid"] . ' via DFRN to ' . (empty($contact['addr']) ? $contact['url'] : $contact['addr']));
 
                if ($cmd == self::MAIL) {
                        $item = $target_item;
@@ -270,11 +267,18 @@ class Delivery extends BaseObject
 
                // We don't have a relationship with contacts on a public post.
                // Se we transmit with the new method and via Diaspora as a fallback
-               if ($items[0]['uid'] == 0) {
+               if (($items[0]['uid'] == 0) || ($contact['uid'] == 0)) {
                        // Transmit in public if it's a relay post
                        $public_dfrn = ($contact['contact-type'] == ACCOUNT_TYPE_RELAY);
 
                        $deliver_status = DFRN::transmit($owner, $contact, $atom, $public_dfrn);
+
+                       // We never spool failed relay deliveries
+                       if ($public_dfrn) {
+                               logger('Relay delivery to ' . $contact["url"] . ' with guid ' . $target_item["guid"] . ' returns ' . $deliver_status);
+                               return;
+                       }
+
                        if (($deliver_status < 200) || ($deliver_status > 299)) {
                                // Transmit via Diaspora if not possible via Friendica
                                self::deliverDiaspora($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup);