From eec4845cd0dd179020a61e9d3ba4d5b10fe458a2 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 23 Apr 2023 09:23:39 +0000 Subject: [PATCH] add the conversation endpoint and implement paginated fetch for zot requests in mod item --- Zotlabs/Lib/Activity.php | 2 +- Zotlabs/Module/Conversation.php | 188 ++++++++++++++++++++++++++++++++ Zotlabs/Module/Item.php | 100 +++++++---------- Zotlabs/Module/Search.php | 2 +- 4 files changed, 230 insertions(+), 62 deletions(-) create mode 100644 Zotlabs/Module/Conversation.php diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 9bbebbf79..cbefd6fd7 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -289,7 +289,7 @@ class Activity { static function encode_item_collection($items, $id, $type, $total = 0) { - if ($total > 30) { + if ($total > App::$pager['itemspage']) { $ret = [ 'id' => z_root() . '/' . $id, 'type' => $type . 'Page', diff --git a/Zotlabs/Module/Conversation.php b/Zotlabs/Module/Conversation.php new file mode 100644 index 000000000..86ce66caa --- /dev/null +++ b/Zotlabs/Module/Conversation.php @@ -0,0 +1,188 @@ + App::$pager['itemspage']) { + // let mod conversation handle this request + App::$query_string = str_replace('item', 'conversation', App::$query_string); + $i = Activity::paged_collection_init(App::$pager['total'], App::$query_string); + as_return_and_die($i ,$chan); } + else { + $items = q("SELECT item.*, item.id AS item_id FROM item WHERE item.parent = %d $item_normal ORDER BY item.id", + intval($parents_str) + ); - xchan_query($items, true); - $items = fetch_post_tags($items, true); + xchan_query($items, true); + $items = fetch_post_tags($items, true); - if (!$items) - http_status_exit(404, 'Not found'); - - $chan = channelx_by_n($items[0]['uid']); - - if (!$chan) - http_status_exit(404, 'Not found'); - - if (!perm_is_allowed($chan['channel_id'], get_observer_hash(), 'view_stream')) - http_status_exit(403, 'Forbidden'); - - - $i = Activity::encode_item_collection($items, 'conversation/' . $item_id, 'OrderedCollection'); - - if (!$i) - http_status_exit(404, 'Not found'); + $i = Activity::encode_item_collection($items, App::$query_string, 'OrderedCollection', App::$pager['total']); + } if ($portable_id && (!intval($items[0]['item_private']))) { - ThreadListener::store(z_root() . '/item/' . $item_id, $portable_id); + $c = q("select abook_id from abook where abook_channel = %d and abook_xchan = '%s'", + intval($items[0]['uid']), + dbesc($portable_id) + ); + if (!$c) { + ThreadListener::store(z_root() . '/item/' . $item_id, $portable_id); + } } - $x = array_merge(['@context' => [ - ACTIVITYSTREAMS_JSONLD_REV, - 'https://w3id.org/security/v1', - z_root() . ZOT_APSCHEMA_REV - ]], $i); - - $headers = []; - $headers['Content-Type'] = 'application/x-zot+json'; - $x['signature'] = LDSignatures::sign($x, $chan); - $ret = json_encode($x, JSON_UNESCAPED_SLASHES); - $headers['Digest'] = HTTPSig::generate_digest_header($ret); - $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI']; - $h = HTTPSig::create_sig($headers, $chan['channel_prvkey'], channel_url($chan)); - HTTPSig::set_headers($h); - echo $ret; - killme(); - + as_return_and_die($i ,$chan); } if (ActivityStreams::is_as_request()) { @@ -255,23 +251,7 @@ class Item extends Controller { } } - $x = array_merge(['@context' => [ - ACTIVITYSTREAMS_JSONLD_REV, - 'https://w3id.org/security/v1', - z_root() . ZOT_APSCHEMA_REV - ]], $i); - - $headers = []; - $headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'; - $x['signature'] = LDSignatures::sign($x, $chan); - $ret = json_encode($x, JSON_UNESCAPED_SLASHES); - $headers['Date'] = datetime_convert('UTC', 'UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T'); - $headers['Digest'] = HTTPSig::generate_digest_header($ret); - $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI']; - $h = HTTPSig::create_sig($headers, $chan['channel_prvkey'], channel_url($chan)); - HTTPSig::set_headers($h); - echo $ret; - killme(); + as_return_and_die($i ,$chan); } diff --git a/Zotlabs/Module/Search.php b/Zotlabs/Module/Search.php index 6601da29d..eb8f238e9 100644 --- a/Zotlabs/Module/Search.php +++ b/Zotlabs/Module/Search.php @@ -75,7 +75,7 @@ class Search extends Controller { if ($f) { $mid = $f[0]['message_id']; foreach ($f as $m) { - if (strpos($search, $m['message_id']) === 0) { + if (str_starts_with($url, $m['message_id'])) { $mid = $m['message_id']; break; }