From 4bb9263e43ae522cc93644b2109b383c98ba4420 Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Mon, 12 Mar 2018 04:51:27 +0000
Subject: [PATCH] Fix: The acl lookup now works in multi threaded posts as well

---
 include/acl_selectors.php | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/acl_selectors.php b/include/acl_selectors.php
index e69ac36f68..91f9415590 100644
--- a/include/acl_selectors.php
+++ b/include/acl_selectors.php
@@ -406,7 +406,7 @@ function acl_lookup(App $a, $out_type = 'json')
 		$search = $_REQUEST['query'];
 	}
 
-	logger("Searching for ".$search." - type ".$type, LOGGER_DEBUG);
+	logger("Searching for ".$search." - type ".$type." conversation ".$conv_id, LOGGER_DEBUG);
 
 	if ($search != '') {
 		$sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
@@ -613,6 +613,14 @@ function acl_lookup(App $a, $out_type = 'json')
 
 	$items = array_merge($groups, $contacts);
 
+	// At multi threaded posts the conv_id is not the parent of the whole thread
+	if ($conv_id > 0) {
+		$parent_item = dba::selectFirst('item', ['parent'], ['id' => $conv_id]);
+		if (DBM::is_result($parent_item)) {
+			$conv_id = $parent_item['parent'];
+		}
+	}
+
 	if ($conv_id) {
 		/*
 		 * if $conv_id is set, get unknown contacts in thread