]> 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 9dbe0eca0a2e2d0617877bd4dee43fec6751174c..15273762ab3808ec7f446be413998cad84ee05bd 100644 (file)
@@ -20,15 +20,18 @@ use dba;
 
 require_once 'include/items.php';
 
-class Delivery extends BaseObject {
+class Delivery extends BaseObject
+{
        const MAIL =       'mail';
        const SUGGESTION = 'suggest';
        const RELOCATION = 'relocate';
        const DELETION =   'drop';
        const POST =       'wall-new';
        const COMMENT =    'comment-new';
+       const REMOVAL =    'removeme';
 
-       public static function execute($cmd, $item_id, $contact_id) {
+       public static function execute($cmd, $item_id, $contact_id)
+       {
                logger('Invoked: ' . $cmd . ': ' . $item_id . ' to ' . $contact_id, LOGGER_DEBUG);
 
                $top_level = false;
@@ -37,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'];
@@ -56,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) {
@@ -76,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']) {
@@ -197,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;
@@ -268,8 +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) {
-                       $deliver_status = DFRN::transmit($owner, $contact, $atom);
+               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);