From 9d7795824765af61733e8e3a7022cad7404eb57b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 25 Sep 2021 20:42:51 -0400 Subject: [PATCH 1/2] Ensure parent exists before adding reply to elements in OStatus and Feed - Address https://github.com/friendica/friendica/issues/10474#issuecomment-927118628 --- src/Protocol/Feed.php | 36 ++++++++++++++++++++---------------- src/Protocol/OStatus.php | 34 +++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 06e70dba9b..a32b460d5a 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -1146,27 +1146,31 @@ class Feed if ($item['gravity'] != GRAVITY_PARENT) { $parent = Post::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]); - $thrparent = Post::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]); + $thrparent = Post::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner['uid'], 'uri' => $item['thr-parent']]); if (DBA::isResult($thrparent)) { - $mentioned[$thrparent["author-link"]] = $thrparent["author-link"]; - $mentioned[$thrparent["owner-link"]] = $thrparent["owner-link"]; - $parent_plink = $thrparent["plink"]; + $mentioned[$thrparent['author-link']] = $thrparent['author-link']; + $mentioned[$thrparent['owner-link']] = $thrparent['owner-link']; + $parent_plink = $thrparent['plink']; + } elseif (DBA::isResult($parent)) { + $mentioned[$parent['author-link']] = $parent['author-link']; + $mentioned[$parent['owner-link']] = $parent['owner-link']; + $parent_plink = DI::baseUrl() . '/display/' . $parent['guid']; } else { - $mentioned[$parent["author-link"]] = $parent["author-link"]; - $mentioned[$parent["owner-link"]] = $parent["owner-link"]; - $parent_plink = DI::baseUrl()."/display/".$parent["guid"]; + DI::logger()->notice('Missing parent and thr-parent for child item', ['item' => $item]); } - $attributes = [ - "ref" => $item['thr-parent'], - "href" => $parent_plink]; - XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes); + if (isset($parent_plink)) { + $attributes = [ + 'ref' => $item['thr-parent'], + 'href' => $parent_plink]; + XML::addElement($doc, $entry, 'thr:in-reply-to', '', $attributes); - $attributes = [ - "rel" => "related", - "href" => $parent_plink]; - XML::addElement($doc, $entry, "link", "", $attributes); + $attributes = [ + 'rel' => 'related', + 'href' => $parent_plink]; + XML::addElement($doc, $entry, 'link', '', $attributes); + } } // uri-id isn't present for follow entry pseudo-items @@ -1177,7 +1181,7 @@ class Feed foreach ($tags as $tag) { if ($tag['type'] == Tag::HASHTAG) { - XML::addElement($doc, $entry, "category", "", ["term" => $tag['name']]); + XML::addElement($doc, $entry, 'category', '', ['term' => $tag['name']]); } } diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 82dc17679e..5b1f758b2e 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -1931,27 +1931,31 @@ class OStatus if ($item['gravity'] != GRAVITY_PARENT) { $parent = Post::selectFirst(['guid', 'author-link', 'owner-link'], ['id' => $item['parent']]); - $thrparent = Post::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner["uid"], 'uri' => $item['thr-parent']]); + $thrparent = Post::selectFirst(['guid', 'author-link', 'owner-link', 'plink'], ['uid' => $owner['uid'], 'uri' => $item['thr-parent']]); if (DBA::isResult($thrparent)) { - $mentioned[$thrparent["author-link"]] = $thrparent["author-link"]; - $mentioned[$thrparent["owner-link"]] = $thrparent["owner-link"]; - $parent_plink = $thrparent["plink"]; + $mentioned[$thrparent['author-link']] = $thrparent['author-link']; + $mentioned[$thrparent['owner-link']] = $thrparent['owner-link']; + $parent_plink = $thrparent['plink']; + } elseif (DBA::isResult($parent)) { + $mentioned[$parent['author-link']] = $parent['author-link']; + $mentioned[$parent['owner-link']] = $parent['owner-link']; + $parent_plink = DI::baseUrl() . '/display/' . $parent['guid']; } else { - $mentioned[$parent["author-link"]] = $parent["author-link"]; - $mentioned[$parent["owner-link"]] = $parent["owner-link"]; - $parent_plink = DI::baseUrl()."/display/".$parent["guid"]; + DI::logger()->notice('Missing parent and thr-parent for child item', ['item' => $item]); } - $attributes = [ - "ref" => $item['thr-parent'], - "href" => $parent_plink]; - XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes); + if (isset($parent_plink)) { + $attributes = [ + 'ref' => $item['thr-parent'], + 'href' => $parent_plink]; + XML::addElement($doc, $entry, 'thr:in-reply-to', '', $attributes); - $attributes = [ - "rel" => "related", - "href" => $parent_plink]; - XML::addElement($doc, $entry, "link", "", $attributes); + $attributes = [ + 'rel' => 'related', + 'href' => $parent_plink]; + XML::addElement($doc, $entry, 'link', '', $attributes); + } } if (intval($item['parent']) > 0) { From 0bb169b4edc09a99d14fa9105412c114b1bcc6f6 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 25 Sep 2021 20:45:53 -0400 Subject: [PATCH 2/2] Check for reply existence before using its values in Model\Mail - Address https://github.com/friendica/friendica/issues/10474#issuecomment-925263894 --- src/Model/Mail.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Model/Mail.php b/src/Model/Mail.php index 7eaeb09b5e..75515c5df5 100644 --- a/src/Model/Mail.php +++ b/src/Model/Mail.php @@ -74,9 +74,7 @@ class Mail return false; } - if ($msg['reply']) { - $reply = DBA::selectFirst('mail', ['uri', 'uri-id'], ['parent-uri' => $msg['parent-uri'], 'reply' => false]); - + if ($msg['reply'] && DBA::isResult($reply = DBA::selectFirst('mail', ['uri', 'uri-id'], ['parent-uri' => $msg['parent-uri'], 'reply' => false]))) { $msg['thr-parent'] = $reply['uri']; $msg['thr-parent-id'] = $reply['uri-id']; } else {