From 6ead246ce256ddee88d8108f6e169208f22cc52b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 4 Jul 2020 15:33:35 -0400 Subject: [PATCH 1/2] Account for falsy values for $forum_contact in mod/item - Rare condition can make it false - Simplify notification sending condition --- mod/item.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mod/item.php b/mod/item.php index e56e4c68d9..08a565e069 100644 --- a/mod/item.php +++ b/mod/item.php @@ -423,7 +423,7 @@ function item_post(App $a) { $original_contact_id = $contact_id; - if (!$toplevel_item_id && count($forum_contact) && ($private_forum || $only_to_forum)) { + if (!$toplevel_item_id && !empty($forum_contact) && ($private_forum || $only_to_forum)) { // we tagged a forum in a top level post. Now we change the post $private = $private_forum; @@ -745,8 +745,8 @@ function item_post(App $a) { FileTag::updatePconfig($uid, $categories_old, $categories_new, 'category'); // These notifications are sent if someone else is commenting other your wall - if ($toplevel_item_id) { - if ($contact_record != $author) { + if ($contact_record != $author) { + if ($toplevel_item_id) { notification([ 'type' => Type::COMMENT, 'notify_flags' => $user['notify-flags'], @@ -764,9 +764,7 @@ function item_post(App $a) { 'parent' => $toplevel_item_id, 'parent_uri' => $toplevel_item['uri'] ]); - } - } else { - if (($contact_record != $author) && !count($forum_contact)) { + } elseif (empty($forum_contact)) { notification([ 'type' => Type::WALL, 'notify_flags' => $user['notify-flags'], From 416f6c8c10626db62cc8e0c270f96d7081305543 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 4 Jul 2020 15:33:54 -0400 Subject: [PATCH 2/2] Ensure $contact_record is an array in mod/item --- mod/item.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mod/item.php b/mod/item.php index 08a565e069..6a3fd1896b 100644 --- a/mod/item.php +++ b/mod/item.php @@ -367,9 +367,9 @@ function item_post(App $a) { // get contact info for owner if ($profile_uid == local_user() || $allow_comment) { - $contact_record = $author; + $contact_record = $author ?: []; } else { - $contact_record = DBA::selectFirst('contact', [], ['uid' => $profile_uid, 'self' => true]); + $contact_record = DBA::selectFirst('contact', [], ['uid' => $profile_uid, 'self' => true]) ?: []; } // Look for any tags and linkify them @@ -564,9 +564,9 @@ function item_post(App $a) { $datarray['gravity'] = $gravity; $datarray['network'] = $network; $datarray['contact-id'] = $contact_id; - $datarray['owner-name'] = $contact_record['name']; - $datarray['owner-link'] = $contact_record['url']; - $datarray['owner-avatar'] = $contact_record['thumb']; + $datarray['owner-name'] = $contact_record['name'] ?? ''; + $datarray['owner-link'] = $contact_record['url'] ?? ''; + $datarray['owner-avatar'] = $contact_record['thumb'] ?? ''; $datarray['owner-id'] = Contact::getIdForURL($datarray['owner-link']); $datarray['author-name'] = $author['name']; $datarray['author-link'] = $author['url'];