From fafeea4382e16a16918f8152233ee0a5851cfa95 Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Tue, 10 Jan 2017 07:40:57 +0000
Subject: [PATCH] When commenting too fast, messages weren't delivered to
 Diaspora

---
 include/delivery.php | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/delivery.php b/include/delivery.php
index e9f426464..23fe859b6 100644
--- a/include/delivery.php
+++ b/include/delivery.php
@@ -46,6 +46,7 @@ function delivery_run(&$argv, &$argc){
 
 		$contact_id = intval($argv[$x]);
 
+		/// @todo When switching completely to the worker we won't need this anymore
 		// Some other process may have delivered this item already.
 
 		$r = q("SELECT * FROM `deliverq` WHERE `cmd` = '%s' AND `item` = %d AND `contact` = %d LIMIT 1",
@@ -170,7 +171,10 @@ function delivery_run(&$argv, &$argc){
 					$item['deleted'] = 1;
 			}
 
-			if ((count($items) == 1) && ($items[0]['uri'] === $items[0]['parent-uri'])) {
+			// When commenting too fast after delivery, a post wasn't recognized as top level post.
+			// The count then showed more than one entry. The additional check should help.
+			// The check for the "count" should be superfluous, but I'm not totally sure by now, so we keep it.
+			if ((($items[0]['id'] = $parent_id) OR (count($items) == 1)) AND ($items[0]['uri'] === $items[0]['parent-uri'])) {
 				logger('delivery: top level post');
 				$top_level = true;
 			}