diff --git a/Code/Lib/Activity.php b/Code/Lib/Activity.php index 42c1555fa..cb9664fd5 100644 --- a/Code/Lib/Activity.php +++ b/Code/Lib/Activity.php @@ -2889,6 +2889,7 @@ class Activity } logger('updated_poll: ' . print_r($o, true), LOGGER_DATA); + // A change was made locally if ($response && $answer_found && !$foundPrevious) { // undo moderation if it was applied. q( @@ -2897,34 +2898,31 @@ class Activity dbesc(datetime_convert()), intval($pollItem['id']) ); - $i = q("select * from item where id = %d", - intval($pollItem['id']) - ); - xchan_query($i, true); - $items = fetch_post_tags($i); - $pollItem = array_shift($items); - $pollItem['obj'] = json_decode($pollItem['obj'],true); - $pollItem['target'] = json_decode($pollItem['target'], true); - $pollItem['attach'] = json_decode($pollItem['attach'], true); - - Run::Summon(['Notifier', 'edit_post', $pollItem['id']]); - $related = find_related($pollItem); - // logger('related: ' . print_r($related,true), LOGGER_DATA); - if ($related) { - // Update the object in the collection activity and the timestamp - $newObj = array_merge(Activity::ap_context(), Activity::encode_activity($pollItem)); - $newObj['proof'] = (new JcsEddsa2022())->sign($newObj, $channel); - $r = q("update item set obj = '%s', edited = '%s' where id = %d", - dbesc(json_encode($newObj)), - dbesc(datetime_convert()), - intval($related['id']) - ); - Run::Summon(['Notifier', 'edit_post', $related['id']]); - } - return true; } - logger('update poll was not stored'); - return false; + $i = q("select * from item where id = %d", + intval($pollItem['id']) + ); + xchan_query($i, true); + $items = fetch_post_tags($i); + $pollItem = array_shift($items); + $pollItem['obj'] = json_decode($pollItem['obj'],true); + $pollItem['target'] = json_decode($pollItem['target'], true); + $pollItem['attach'] = json_decode($pollItem['attach'], true); + + Run::Summon(['Notifier', 'edit_post', $pollItem['id']]); + $related = find_related($pollItem); + if ($related) { + // Update the object in the collection activity and the timestamp + $newObj = array_merge(Activity::ap_context(), Activity::encode_activity($pollItem)); + $newObj['proof'] = (new JcsEddsa2022())->sign($newObj, $channel); + $r = q("update item set obj = '%s', edited = '%s' where id = %d", + dbesc(json_encode($newObj)), + dbesc(datetime_convert()), + intval($related['id']) + ); + Run::Summon(['Notifier', 'edit_post', $related['id']]); + } + return true; } public static function findInContext($context, $str) @@ -3074,13 +3072,6 @@ class Activity return false; } - if (!(array_key_exists('created', $item) && $item['created'])) { - $item['created'] = datetime_convert(); - } - if (!(array_key_exists('edited', $item) && $item['edited'])) { - $item['edited'] = $item['created']; - } - /** * Set item 'replyto' to the attributedTo field of a target Collection or alternatively to @@ -3269,6 +3260,15 @@ class Activity } } + // Set default date and time if no date fields were found (including within response activities). + + if (!(array_key_exists('created', $item) && $item['created'])) { + $item['created'] = datetime_convert(); + } + if (!(array_key_exists('edited', $item) && $item['edited'])) { + $item['edited'] = $item['created']; + } + $item['comment_policy'] = 'authenticated'; if ($item['mid'] === $item['parent_mid']) { @@ -3751,13 +3751,14 @@ class Activity if ($act->objprop('directMessage')) { $item['item_private'] = 2; } - - set_iconfig($item, 'activitypub', 'recips', $act->raw_recips); - if (array_key_exists('directMessage', $act->data) && intval($act->data['directMessage'])) { $item['item_private'] = 2; } + // Store the ActivityStreams recipient list in iconfig in case we need it again. Because we probably will. + set_iconfig($item, 'activitypub', 'recips', $act->raw_recips); + + // Restrict html caching to ActivityPub senders. // Zot has dynamic content and this library is used by both. @@ -3779,6 +3780,7 @@ class Activity } } + // Add quoted posts if ($item['term']) { foreach ($item['term'] as $t) { if ($t['ttype'] === TERM_QUOTED && self::share_not_in_body($item['body'])) { diff --git a/Code/Lib/Enotify.php b/Code/Lib/Enotify.php index 28a37db49..a26270573 100644 --- a/Code/Lib/Enotify.php +++ b/Code/Lib/Enotify.php @@ -176,17 +176,22 @@ class Enotify $action = t('commented on'); } + if (!empty($params['item']) && $params['item']['verb'] === 'Answer') { + pop_lang(); + return; + } + if (array_key_exists('item', $params) && in_array($params['item']['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) { if (!($vnotify & VNOTIFY_LIKE)) { pop_lang(); return; } - if (activity_match($params['verb'], ACTIVITY_LIKE)) { + if (activity_match($params['item']['verb'], ACTIVITY_LIKE)) { $action = t('liked'); } - if (activity_match($params['verb'], ACTIVITY_DISLIKE)) { + if (activity_match($params['item']['verb'], ACTIVITY_DISLIKE)) { $action = t('disliked'); } } @@ -844,6 +849,12 @@ class Enotify localize_item($item); + // Don't provide visual notifications for poll responses or collection operations. + + if (in_array($item['verb'], ['Answer', 'Add', 'Remove'])) { + return []; + } + if ($item['shortlocalize']) { $itemem_text = $item['shortlocalize']; } elseif ($item['localize']) { diff --git a/Code/Lib/Libzot.php b/Code/Lib/Libzot.php index b0d5f0d34..26fea5fe6 100644 --- a/Code/Lib/Libzot.php +++ b/Code/Lib/Libzot.php @@ -1605,13 +1605,13 @@ class Libzot * @param ActivityStreams object $act * @param array $msg_arr * @param array $deliveries - * @param bool $relay + * @param bool $isGoingUpstream * @param bool $public (optional) default false * @param bool $request (optional) default false - message was fetched, not posted * @return array|false|void */ - public static function process_delivery($sender, $act, $msg_arr, $deliveries, $relay, $public = false, $request = false, $isCollectionOperation = false) + public static function process_delivery($sender, $act, $msg_arr, $deliveries, $isGoingUpstream, $public = false, $request = false, $isCollectionOperation = false) { $result = []; @@ -1665,8 +1665,10 @@ class Libzot } $DR->set_name($channel['channel_name'] . ' <' . Channel::get_webfinger($channel) . '>'); + + $conversationOperation = $isCollectionOperation && in_array($arr['target'], 'attributedTo'); - if (str_contains($arr['tgt_type'], 'Collection') && !$relay && !$isCollectionOperation) { + if (str_contains($arr['tgt_type'], 'Collection') && !$isGoingUpstream && !$conversationOperation) { $DR->update('not a collection activity'); $result[] = $DR->get(); continue; @@ -1715,7 +1717,7 @@ class Libzot // for comments travelling upstream. Wait and catch them on the way down. // They may have been blocked by the owner. - if (intval($channel['channel_system']) && (!$arr['item_private']) && (!$relay)) { + if (intval($channel['channel_system']) && (!$arr['item_private']) && (!$isGoingUpstream)) { $local_public = true; $public_stream_mode = (int) Config::Get('system', 'public_stream_mode', PUBLIC_STREAM_NONE); @@ -1773,7 +1775,7 @@ class Libzot $perm = 'send_stream'; if ($arr['mid'] !== $arr['parent_mid']) { - if ($relay) { + if ($isGoingUpstream) { $perm = 'post_comments'; } } @@ -1871,7 +1873,7 @@ class Libzot } if ($arr['mid'] !== $arr['parent_mid']) { - if ((perm_is_allowed($channel['channel_id'], $sender, 'moderated') || $allowed === 'moderated') && $relay) { + if ((perm_is_allowed($channel['channel_id'], $sender, 'moderated') || $allowed === 'moderated') && $isGoingUpstream) { $arr['item_blocked'] = ITEM_MODERATED; } @@ -1914,7 +1916,7 @@ class Libzot // this is just an exercise in futility. if ( - (!$relay) && (!$request) && (!$local_public) + (!$isGoingUpstream) && (!$request) && (!$local_public) && perm_is_allowed($channel['channel_id'], $sender, 'send_stream') && perm_is_allowed($channel['channel_id'], $sender, 'hyperdrive') ) { @@ -1974,11 +1976,11 @@ class Libzot $arr['aid'] = $channel['channel_account_id']; $arr['uid'] = $channel['channel_id']; - $item_id = self::delete_imported_item($sender, $act, $arr, $channel['channel_id'], $relay); + $item_id = self::delete_imported_item($sender, $act, $arr, $channel['channel_id'], $isGoingUpstream); $DR->update(($item_id) ? 'deleted' : 'delete_failed'); $result[] = $DR->get(); - if ($relay && $item_id) { + if ($isGoingUpstream && $item_id) { logger('process_delivery: invoking relay'); Run::Summon(['Notifier', 'relay', intval($item_id)]); $DR->update('relayed'); @@ -2034,7 +2036,7 @@ class Libzot $DR->update('updated'); $result[] = $DR->get(); } - if ($relay && $channel['channel_hash'] === $item_result['item']['owner_xchan'] && $item_result['item']['verb'] !== 'Add' && !$isCollectionOperation) { + if ($isGoingUpstream && $channel['channel_hash'] === $item_result['item']['owner_xchan'] && $item_result['item']['verb'] !== 'Add' && !$isCollectionOperation) { $approval = Activity::addToCollection($channel, $act->data, $item_result['item']['parent_mid'], $item_result['item'], deliver: false); } @@ -2108,7 +2110,7 @@ class Libzot //logger('owner_xchan: ' . $item_result['item']['owner_xchan']); //logger('verb: ' . $arr['verb']); - if ($relay && $channel['channel_hash'] === $item_result['item']['owner_xchan'] && $item_result['item']['verb'] !== 'Add' && !$isCollectionOperation) { + if ($isGoingUpstream && $channel['channel_hash'] === $item_result['item']['owner_xchan'] && $item_result['item']['verb'] !== 'Add' && !$isCollectionOperation) { $approval = Activity::addToCollection($channel, $act->data, $item_result['item']['parent_mid'], $item_result['item'], deliver: false); } $parr = [ @@ -2140,7 +2142,7 @@ class Libzot retain_item($stored['item']['parent']); } - if ($relay && $item_id) { + if ($isGoingUpstream && $item_id) { logger('Invoking relay'); Run::Summon(['Notifier', 'relay', intval($item_id)]); if (!empty($approval) && $approval['item_id']) {