From 5f2e80849753928ee30e8420750b6218c64b4e25 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 7 Feb 2024 15:37:20 +0000 Subject: add uuid to dreport for internal use and and fix issues with conversation fetches --- Zotlabs/Lib/DReport.php | 52 +++++++++++++++++++++++-------------------- Zotlabs/Lib/Libzot.php | 56 +++++++++++++++++++++++++++-------------------- Zotlabs/Module/Search.php | 8 +++---- 3 files changed, 64 insertions(+), 52 deletions(-) diff --git a/Zotlabs/Lib/DReport.php b/Zotlabs/Lib/DReport.php index f4f098d19..71e39a9d7 100644 --- a/Zotlabs/Lib/DReport.php +++ b/Zotlabs/Lib/DReport.php @@ -8,22 +8,24 @@ class DReport { private $recipient; private $name; private $message_id; + private $message_uuid; private $status; private $date; - function __construct($location,$sender,$recipient,$message_id,$status = 'deliver') { - $this->location = $location; - $this->sender = $sender; - $this->recipient = $recipient; - $this->name = EMPTY_STR; - $this->message_id = $message_id; - $this->status = $status; - $this->date = datetime_convert(); + function __construct($location, $sender, $recipient, $message_id, $message_uuid = '', $status = 'deliver') { + $this->location = $location; + $this->sender = $sender; + $this->recipient = $recipient; + $this->name = EMPTY_STR; + $this->message_id = $message_id; + $this->message_uuid = $message_uuid; + $this->status = $status; + $this->date = datetime_convert(); } function update($status) { - $this->status = $status; - $this->date = datetime_convert(); + $this->status = $status; + $this->date = datetime_convert(); } function set_name($name) { @@ -36,24 +38,26 @@ class DReport { function set($arr) { - $this->location = $arr['location']; - $this->sender = $arr['sender']; - $this->recipient = $arr['recipient']; - $this->name = $arr['name']; - $this->message_id = $arr['message_id']; - $this->status = $arr['status']; - $this->date = $arr['date']; + $this->location = $arr['location']; + $this->sender = $arr['sender']; + $this->recipient = $arr['recipient']; + $this->name = $arr['name']; + $this->message_id = $arr['message_id']; + $this->message_uuid = $arr['message_uuid'] ?? ''; + $this->status = $arr['status']; + $this->date = $arr['date']; } function get() { return array( - 'location' => $this->location, - 'sender' => $this->sender, - 'recipient' => $this->recipient, - 'name' => $this->name, - 'message_id' => $this->message_id, - 'status' => $this->status, - 'date' => $this->date + 'location' => $this->location, + 'sender' => $this->sender, + 'recipient' => $this->recipient, + 'name' => $this->name, + 'message_id' => $this->message_id, + 'message_uuid' => $this->message_uuid, + 'status' => $this->status, + 'date' => $this->date ); } diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 70ca2d84b..002ccedfc 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1302,6 +1302,8 @@ class Libzot { $relay = (($env['type'] === 'response') ? true : false); $result = self::process_delivery($env['sender'], $AS, $item, $deliveries, $relay, false, $message_request); + + Activity::init_background_fetch($env['sender']); } elseif ($env['type'] === 'sync') { // $item = get_channelsync_elements($data); @@ -1323,8 +1325,6 @@ class Libzot { $return = array_merge($return, $result); } - Activity::init_background_fetch(); - return $return; } @@ -1533,7 +1533,7 @@ class Libzot { $local_public = $public; $item_result = null; - $DR = new DReport(z_root(), $sender, $d, $arr['mid']); + $DR = new DReport(z_root(), $sender, $d, $arr['mid'], $arr['uuid']); $channel = channelx_by_hash($d); @@ -1671,7 +1671,7 @@ class Libzot { // the top level post is unlikely to be imported and // this is just an exercise in futility. - if ($relay || $request || $local_public || !perm_is_allowed($channel['channel_id'], $sender, 'send_stream')) { + if ($relay || $request || (!$local_public && !perm_is_allowed($channel['channel_id'], $sender, 'send_stream'))) { continue; } @@ -1755,7 +1755,7 @@ class Libzot { } if (!$tag_delivery && !$local_public) { - $allowed = (perm_is_allowed($channel['channel_id'], $sender, $perm)); + $allowed = perm_is_allowed($channel['channel_id'], $sender, $perm); $permit_mentions = intval(PConfig::Get($channel['channel_id'], 'system', 'permit_all_mentions') && i_am_mentioned($channel, $arr)); @@ -1789,18 +1789,17 @@ class Libzot { if ($request) { // Conversation fetches (e.g. $request == true) take place for - // a) new comments on expired posts - // b) if we received an announce - + // a) new comments on expired posts + // b) manual import of posts via search (in this case force will be true) + // c) import of conversations from friends of friends (those will currently only be accepted in the public stream) - // over-ride normal connection permissions for hyperdrive (friend-of-friend) conversations - // (if hyperdrive is enabled) and repeated posts by a friend. - // If $allowed is already true, this is probably the conversation of a direct friend or a - // conversation fetch for a new comment on an expired post + // If it is a toplevel post check permissions for the item author instead of the sender (we might want to remove this if we want friend of friend posts in the network stream). // Comments of all these activities are allowed and will only be rejected (later) if the parent // doesn't exist. if ($perm === 'send_stream') { + $allowed = perm_is_allowed($channel['channel_id'], $arr['author_xchan'], $perm); + if ($force) { $allowed = true; } @@ -2000,11 +1999,14 @@ class Libzot { $ret = []; - $signer = q("select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6' order by hubloc_id desc limit 1", dbesc($a['signature']['signer']) ); + $signer_hash = $signer[0]['hubloc_hash'] ?? $a['signature']['signer']; + $conv_owner = $signer_hash; + + $i = 0; foreach ($items as $activity) { @@ -2018,14 +2020,14 @@ class Libzot { } if (!$AS->is_valid()) { - logger('FOF Activity rejected: ' . print_r($activity, true)); + logger('Fetched activity rejected: ' . print_r($activity, true)); continue; } // logger($AS->debug()); if(empty($AS->actor['id'])) { - logger('No actor id: ' . print_r($AS, true)); + logger('Fetched activity no actor id: ' . print_r($AS, true)); continue; } @@ -2038,7 +2040,7 @@ class Libzot { $r = self::zot_record_preferred($r); } if (!$r) { - logger('FOF Activity: no actor'); + logger('Fetched activity: no actor'); continue; } } @@ -2053,7 +2055,7 @@ class Libzot { $ro = self::zot_record_preferred($ro); } if (!$ro) { - logger('FOF Activity: no obj actor'); + logger('Fetched activity: no obj actor'); continue; } } @@ -2068,13 +2070,17 @@ class Libzot { $arr['author_xchan'] = $r['hubloc_hash']; - if ($signer) { - $arr['owner_xchan'] = $signer[0]['hubloc_hash']; - } - else { - $arr['owner_xchan'] = $a['signature']['signer']; + if ($i === 0) { + // Set the author of the toplevel post as conv_owner + $conv_owner = $r['hubloc_hash']; } + $arr['owner_xchan'] = $conv_owner; + $arr['source_xchan'] = $signer_hash; + + // WARNING: the presence of both source_xchan and non-zero item_uplink here will cause a delivery loop + $arr['item_uplink'] = 0; + if (isset($AS->meta['hubloc']) || $arr['author_xchan'] === $arr['owner_xchan']) { $arr['item_verified'] = true; } @@ -2087,13 +2093,15 @@ class Libzot { } } - logger('FOF Activity received: ' . print_r($arr, true), LOGGER_DATA, LOG_DEBUG); - logger('FOF Activity recipient: ' . $channel['channel_hash'], LOGGER_DATA, LOG_DEBUG); + logger('Fetched activity received: ' . print_r($arr, true), LOGGER_DATA, LOG_DEBUG); + logger('Fetched activity recipient: ' . $channel['channel_hash'], LOGGER_DATA, LOG_DEBUG); $result = self::process_delivery($arr['owner_xchan'], $AS, $arr, [$channel['channel_hash']], false, false, true, $force); if ($result) { $ret = array_merge($ret, $result); } + + $i++; } return $ret; diff --git a/Zotlabs/Module/Search.php b/Zotlabs/Module/Search.php index 335dcc6e7..9511c0389 100644 --- a/Zotlabs/Module/Search.php +++ b/Zotlabs/Module/Search.php @@ -73,15 +73,15 @@ class Search extends Controller { $f = Libzot::fetch_conversation(App::get_channel(), punify($url), true); if ($f) { - $mid = $f[0]['message_id']; + $uuid = $f[0]['message_uuid']; foreach ($f as $m) { - if (basename($url) === $m['message_id']) { - $mid = $m['message_id']; + if ($url === $m['message_id']) { + $uuid = $m['message_uuid']; break; } } - goaway(z_root() . '/hq/' . $mid); + goaway(z_root() . '/hq/' . $uuid); } else { // try other fetch providers (e.g. diaspora, pubcrawl) -- cgit v1.2.3