attempt to fix poll updates on contained items

This commit is contained in:
Mike Macgirvin 2024-02-28 14:22:33 +11:00
parent 817b60270b
commit d63a02dbf6
2 changed files with 44 additions and 1 deletions

View file

@ -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');

View file

@ -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.