wip: replies continued

This commit is contained in:
Mike Macgirvin 2024-06-22 13:18:41 +10:00
parent 5872366f79
commit 888010df5c

View file

@ -17,9 +17,9 @@ class Replies extends Controller
public function init() public function init()
{ {
if (ActivityStreams::is_as_request() || Libzot::is_nomad_request()) { if (ActivityStreams::is_as_request() || Libzot::is_nomad_request()) {
$item_id = argv(1); $item_mid = argv(1);
if (!$item_id) { if (!$item_mid) {
http_status_exit(404, 'Not found'); http_status_exit(404, 'Not found');
} }
@ -33,13 +33,13 @@ class Replies extends Controller
$test = q( $test = q(
"select * from item where mid = '%s' $item_normal limit 1", "select * from item where mid = '%s' $item_normal limit 1",
dbesc(z_root() . '/activity/' . $item_id) dbesc(z_root() . '/activity/' . $item_mid)
); );
if (!$test) { if (!$test) {
$test = q( $test = q(
"select * from item where mid = '%s' $item_normal limit 1", "select * from item where mid = '%s' $item_normal limit 1",
dbesc(z_root() . '/item/' . $item_id) dbesc(z_root() . '/item/' . $item_mid)
); );
if (!$test) { if (!$test) {
http_status_exit(404, 'Not found'); http_status_exit(404, 'Not found');
@ -71,7 +71,7 @@ class Replies extends Controller
if ($xchans) { if ($xchans) {
$hashes = ids_to_querystr($xchans, 'xchan_hash', true); $hashes = ids_to_querystr($xchans, 'xchan_hash', true);
$i = q( $i = q(
"select id as item_id, item_private, uid from item where mid = '%s' $item_normal and owner_xchan in ( " . protect_sprintf($hashes) . " ) limit 1", "select item.* id as item_id from item where mid = '%s' $item_normal and owner_xchan in ( " . protect_sprintf($hashes) . " ) limit 1",
dbesc($test[0]['mid']) dbesc($test[0]['mid'])
); );
} }
@ -94,8 +94,8 @@ class Replies extends Controller
if (!$i) { if (!$i) {
$i = q( $i = q(
"select id as item_id, item_private, uid from item where mid = '%s' $item_normal $sql_extra order by item_wall desc limit 1", "select item.*, id as item_id from item where mid = '%s' $item_normal $sql_extra order by item_wall desc limit 1",
dbesc($test[0]['parent_mid']) dbesc($test[0]['mid'])
); );
} }
@ -103,13 +103,13 @@ class Replies extends Controller
http_status_exit(403, 'Forbidden'); http_status_exit(403, 'Forbidden');
} }
$parents_str = ids_to_querystr($i, 'item_id'); xchan_query($i);
$sql_noAdd = ($zot6Hubloc) ? " and verb not in ('Add', 'Remove') " : ''; $sql_noAdd = ($zot6Hubloc) ? " and verb not in ('Add', 'Remove') " : '';
$items = q( $items = q(
"SELECT item.*, item.id AS item_id FROM item WHERE item.parent IN ( %s ) $item_normal $sql_noAdd and item_private = %d and item_deleted = 0 and uid = %d", "SELECT item.*, item.id AS item_id FROM item WHERE item.thr_parent = '%s' $item_normal $sql_noAdd and item_private = %d and item_deleted = 0 and uid = %d",
dbesc($parents_str), dbesc($i[0]['mid']),
intval($i[0]['item_private']), intval($i[0]['item_private']),
intval($i[0]['uid']) intval($i[0]['uid'])
); );
@ -122,31 +122,31 @@ class Replies extends Controller
$items = fetch_post_tags($items); $items = fetch_post_tags($items);
$observer = App::get_observer(); $observer = App::get_observer();
$parent = $items[0]; $parent = $i[0];
$recips = (($parent['owner']['xchan_network'] === 'activitypub') ? get_iconfig($parent['id'], 'activitypub', 'recips', []) : []); $recips = (($parent['owner']['xchan_network'] === 'activitypub') ? get_iconfig($parent['id'], 'activitypub', 'recips', []) : []);
$to = (($recips && array_key_exists('to', $recips) && is_array($recips['to'])) ? $recips['to'] : null); $to = (($recips && array_key_exists('to', $recips) && is_array($recips['to'])) ? $recips['to'] : null);
$nitems = []; $nitems = [];
foreach ($items as $i) { foreach ($items as $item) {
$mids = []; $mids = [];
if (intval($i['item_private'])) { if (intval($item['item_private'])) {
if (!$observer) { if (!$observer) {
continue; continue;
} }
// ignore private reshare, possibly from hubzilla // ignore private reshare, possibly from hubzilla
if ($i['verb'] === 'Announce') { if ($i['verb'] === 'Announce') {
if (!in_array($i['thr_parent'], $mids)) { if (!in_array($item['thr_parent'], $mids)) {
$mids[] = $i['thr_parent']; $mids[] = $item['thr_parent'];
} }
continue; continue;
} }
// also ignore any children of the private reshares // also ignore any children of the private reshares
if (in_array($i['thr_parent'], $mids)) { if (in_array($item['thr_parent'], $mids)) {
continue; continue;
} }
if ($observer['xchan_hash'] !== $i['owner_xchan']) { if ($observer['xchan_hash'] !== $item['owner_xchan']) {
if (empty($to)) { if (empty($to)) {
continue; continue;
} }
@ -155,14 +155,14 @@ class Replies extends Controller
} }
} }
} }
$nitems[] = $i; $nitems[] = $item;
} }
if (!$nitems) { if (!$nitems) {
http_status_exit(404, 'Not found'); http_status_exit(404, 'Not found');
} }
$chan = Channel::from_id($nitems[0]['uid']); $chan = Channel::from_id($i[0]['uid']);
if (!$chan) { if (!$chan) {
http_status_exit(404, 'Not found'); http_status_exit(404, 'Not found');
@ -172,16 +172,16 @@ class Replies extends Controller
http_status_exit(403, 'Forbidden'); http_status_exit(403, 'Forbidden');
} }
$i = ZlibActivity::encode_item_collection($nitems, 'conversation/' . $item_id, 'OrderedCollection', true, z_root() . '/channel/' . $chan['channel_address'], count($nitems)); $i = ZlibActivity::encode_item_collection($nitems, 'replies/' . $item_mid, 'OrderedCollection', true, z_root() . '/channel/' . $chan['channel_address'], count($nitems));
if ($portable_id && (!intval($items[0]['item_private']))) { if ($portable_id && (!intval($items[0]['item_private']))) {
ThreadListener::store(z_root() . '/activity/' . $item_id, $portable_id); ThreadListener::store(z_root() . '/activity/' . $item_mid, $portable_id);
} }
if (!$i) { if (!$i) {
http_status_exit(404, 'Not found'); http_status_exit(404, 'Not found');
} }
$channel = Channel::from_id($items[0]['uid']); $channel = Channel::from_id($i[0]['uid']);
as_return_and_die($i, $channel); as_return_and_die($i, $channel);
} }