From d63a02dbf636b88d7a6f7b91fe9814ebc6c13d17 Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Wed, 28 Feb 2024 14:22:33 +1100 Subject: [PATCH] attempt to fix poll updates on contained items --- Code/Lib/Activity.php | 4 ++++ include/items.php | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Code/Lib/Activity.php b/Code/Lib/Activity.php index b1d8eeb2b..7c9758296 100644 --- a/Code/Lib/Activity.php +++ b/Code/Lib/Activity.php @@ -2891,6 +2891,10 @@ class Activity intval($item['id']) ); Run::Summon(['Notifier', 'edit_post', $item['id']]); + $related = find_related($item); + if ($related) { + Run::Summon(['Notifier', 'edit_post', $related['id']]); + } return true; } logger('update poll was not stored'); diff --git a/include/items.php b/include/items.php index 295b9e47d..99efee1f0 100644 --- a/include/items.php +++ b/include/items.php @@ -3691,7 +3691,7 @@ function drop_related($item, $stage = DROPITEM_NORMAL, $force = false, $uid = 0, { $allRelated = q("select * from item where parent_mid = '%s' and uid = %d", dbesc($item['parent_mid']), - intval($item['id']) + intval($item['uid']) ); if (! $allRelated) { return; @@ -3723,6 +3723,45 @@ function drop_related($item, $stage = DROPITEM_NORMAL, $force = false, $uid = 0, } } } + + +function find_related($item) +{ + $allRelated = q("select * from item where parent_mid = '%s' and uid = %d", + dbesc($item['parent_mid']), + intval($item['uid']) + ); + if (! $allRelated) { + return false; + } + if ($item['verb'] === 'Add' && $item['tgt_type'] === 'Collection') { + $thisItem = json_decode($item['obj'],true); + if (is_array($thisItem)) { + $targetMid = $thisItem['object']['id']; + } + if (!$targetMid) { + return false; + } + foreach ($allRelated as $related) { + if ($related['mid'] === $targetMid) { + return $related; + } + } + } + else { + foreach ($allRelated as $related) { + if ($related['verb'] === 'Add' && str_contains($related['tgt_type'], 'Collection')) { + $thisItem = json_decode($related['obj'], true); + if (is_array($thisItem) && $thisItem['object']['id'] === $item['mid']) { + return $related; + } + } + } + } + return false; +} + + /** * @warning This function does not check for permission and does not send * notifications and does not check recursion.