From 2c483c460a2d5c806b9e62097673ad237e6b154a Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 23 Mar 2023 20:11:18 +0000 Subject: initial check in to allow all mentions option --- Zotlabs/Daemon/Notifier.php | 2 -- Zotlabs/Lib/Activity.php | 8 ++--- Zotlabs/Lib/Libzot.php | 67 +++++++++++++++++++++++++------------ Zotlabs/Module/Item.php | 38 ++++++++++++++++++++- Zotlabs/Module/Settings/Privacy.php | 7 +++- include/items.php | 42 ++++++++++++++++++++--- include/taxonomy.php | 9 ++--- view/tpl/settings_privacy.tpl | 3 +- 8 files changed, 136 insertions(+), 40 deletions(-) diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php index de8597081..d5fe7ee6d 100644 --- a/Zotlabs/Daemon/Notifier.php +++ b/Zotlabs/Daemon/Notifier.php @@ -409,8 +409,6 @@ class Notifier { self::$private = false; self::$recipients = collect_recipients($parent_item, self::$private); - // FIXME add any additional recipients such as mentions, etc. - if ($top_level_post) { // remove clones who will receive the post via sync self::$recipients = array_values(array_diff(self::$recipients, [$target_item['owner_xchan']])); diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 226f50636..d4a89d2a4 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2869,7 +2869,7 @@ class Activity { $allowed = false; // TODO: not implemented - // $permit_mentions = intval(PConfig::Get($channel['channel_id'], 'system','permit_all_mentions') && i_am_mentioned($channel,$item)); + $permit_mentions = intval(PConfig::Get($channel['channel_id'], 'system','permit_all_mentions') && i_am_mentioned($channel, $item)); if ($is_child_node) { @@ -2894,7 +2894,7 @@ class Activity { // check permissions against the author, not the sender $allowed = perm_is_allowed($channel['channel_id'], $item['author_xchan'], 'post_comments'); - if ((!$allowed)/* && $permit_mentions*/) { + if ((!$allowed) && $permit_mentions) { if ($p[0]['owner_xchan'] === $channel['channel_hash']) { $allowed = false; } @@ -2946,9 +2946,9 @@ class Activity { $allowed = true; } // TODO: not implemented - /*if ($permit_mentions) { + if ($permit_mentions) { $allowed = true; - }*/ + } } if (tgroup_check($channel['channel_id'], $item) && (!$is_child_node)) { diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 93d8a39c0..406a26910 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1233,7 +1233,6 @@ class Libzot { return; } - if ($has_data) { if (in_array($env['type'], ['activity', 'response'])) { @@ -1386,6 +1385,23 @@ class Libzot { return false; } + static function find_parent_owner_hashes($env, $act) { + $r = []; + $thread_parent = self::find_parent($env, $act); + if ($thread_parent) { + $z = q("select channel_hash as hash from channel left join item on channel.channel_id = item.uid where ( item.thr_parent = '%s' OR item.parent_mid = '%s' ) and channel_hash != '%s'", + dbesc($thread_parent), + dbesc($thread_parent), + dbesc($env['sender']) + ); + if ($z) { + foreach ($z as $zv) { + $r[] = $zv['hash']; + } + } + } + return $r; + } /** * @brief @@ -1466,26 +1482,23 @@ class Libzot { } } } + if ($act->obj['type'] === 'Tombstone') { + // This is a delete. There are no tags to look at - add anyone owning the item. + $parent_owners = self::find_parent_owner_hashes($msg, $act); + if ($parent_owners) { + $r = array_merge($r, $parent_owners); + } + } + } } else { // This is a comment. We need to find any parent with ITEM_UPLINK set. But in fact, let's just return // everybody that stored a copy of the parent. This way we know we're covered. We'll check the // comment permissions when we deliver them. - - $thread_parent = self::find_parent($msg, $act); - - if ($thread_parent) { - $z = q("select channel_hash as hash from channel left join item on channel.channel_id = item.uid where ( item.thr_parent = '%s' OR item.parent_mid = '%s' ) and channel_hash != '%s'", - dbesc($thread_parent), - dbesc($thread_parent), - dbesc($msg['sender']) - ); - if ($z) { - foreach ($z as $zv) { - $r[] = $zv['hash']; - } - } + $parent_owners = self::find_parent_owner_hashes($msg, $act); + if ($parent_owners) { + $r = array_merge($r, $parent_owners); } } @@ -1622,13 +1635,23 @@ class Libzot { if ((!$tag_delivery) && (!$local_public)) { $allowed = (perm_is_allowed($channel['channel_id'], $sender, $perm)); - if ((!$allowed) && $perm === 'post_comments') { - $parent = q("select * from item where mid = '%s' and uid = %d limit 1", - dbesc($arr['parent_mid']), - intval($channel['channel_id']) - ); - if ($parent) { - $allowed = can_comment_on_post($sender, $parent[0]); + $permit_mentions = intval(PConfig::Get($channel['channel_id'], 'system', 'permit_all_mentions') && i_am_mentioned($channel, $arr)); + + if (!$allowed) { + if ($perm === 'post_comments') { + $parent = q("select * from item where mid = '%s' and uid = %d limit 1", + dbesc($arr['parent_mid']), + intval($channel['channel_id']) + ); + if ($parent) { + $allowed = can_comment_on_post($sender, $parent[0]); + if (!$allowed && $permit_mentions) { + $allowed = true; + } + } + + } elseif ($permit_mentions) { + $allowed = true; } } diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 5ca94cd76..b3b040e96 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -1194,12 +1194,15 @@ class Item extends Controller { (($remote_id) ? $remote_id : basename($datarray['mid'])), true); } - if ($orig_post) { $datarray['id'] = $post_id; $x = item_store_update($datarray, $execflag); + if ($x['success']) { + $this->add_listeners($datarray); + } + // We only need edit activities for other federated protocols // which do not support edits natively. While this does federate // edits, it presents a number of issues locally - such as #757 and #758. @@ -1238,6 +1241,10 @@ class Item extends Controller { $post = item_store($datarray, $execflag); + if ($post['success']) { + $this->add_listeners($datarray); + } + $post_id = $post['item_id']; $datarray = $post['item']; @@ -1603,4 +1610,33 @@ class Item extends Controller { } + function add_listeners($item) { + // ONLY public items! + if ($item['item_thread_top'] && !$item['item_private'] && !empty($item['term'])) { + foreach($item['term'] as $t) { + if (empty($t['url']) || $t['ttype'] != TERM_MENTION || $t['otype'] != TERM_OBJ_POST) { + continue; + } + + $listener = q("select hubloc_hash, hubloc_network from hubloc where hubloc_id_url = '%s' and hubloc_deleted = 0 order by hubloc_id desc", + dbesc($t['url']) + ); + + if ($listener) { + $listener = Libzot::zot_record_preferred($listener); + + $c = q("select abook_id from abook where abook_channel = %d and abook_xchan = '%s'", + intval($profile_uid), + dbesc($listener['hubloc_hash']) + ); + + if (!$c) { + ThreadListener::store($item['mid'], $listener['hubloc_hash']); + } + } + } + } + } + + } diff --git a/Zotlabs/Module/Settings/Privacy.php b/Zotlabs/Module/Settings/Privacy.php index 847bb3b8f..65d5b538e 100644 --- a/Zotlabs/Module/Settings/Privacy.php +++ b/Zotlabs/Module/Settings/Privacy.php @@ -22,6 +22,9 @@ class Privacy { $autoperms = (((x($_POST, 'autoperms')) && (intval($_POST['autoperms']) == 1)) ? 1 : 0); set_pconfig(local_channel(), 'system', 'autoperms', $autoperms); + $permit_all_mentions = (((x($_POST, 'permit_all_mentions')) && (intval($_POST['permit_all_mentions']) == 1)) ? 1 : 0); + set_pconfig(local_channel(), 'system', 'permit_all_mentions', $permit_all_mentions); + $role = get_pconfig(local_channel(), 'system', 'permissions_role'); if ($role === 'custom') { @@ -99,6 +102,7 @@ class Privacy { $autoperms = get_pconfig(local_channel(), 'system', 'autoperms'); $index_opt_out = get_pconfig(local_channel(), 'system', 'index_opt_out'); $group_actor = get_pconfig(local_channel(), 'system', 'group_actor'); + $permit_all_mentions = get_pconfig(local_channel(), 'system', 'permit_all_mentions'); $permissions_role = get_pconfig(local_channel(), 'system', 'permissions_role', 'custom'); $permission_limits = ($permissions_role === 'custom'); @@ -119,7 +123,8 @@ class Privacy { ], '$autoperms' => ['autoperms', t('Automatically approve new contacts'), $autoperms, '', [t('No'), t('Yes')]], '$index_opt_out' => ['index_opt_out', t('Opt-out of search engine indexing'), $index_opt_out, '', [t('No'), t('Yes')]], - '$group_actor' => ['group_actor', t('Group actor'), $group_actor, t('Allow this channel to act as a forum'), [t('No'), t('Yes')]] + '$group_actor' => ['group_actor', t('Group actor'), $group_actor, t('Allow this channel to act as a forum'), [t('No'), t('Yes')]], + '$permit_all_mentions' => ['permit_all_mentions', t('Accept all messages which mention you'), $permit_all_mentions, t('This setting bypasses normal permissions'), [t('No'), t('Yes')]], ]); return $o; diff --git a/include/items.php b/include/items.php index b795df90d..a7d07a599 100644 --- a/include/items.php +++ b/include/items.php @@ -143,11 +143,8 @@ function collect_recipients($item, &$private_envelope,$include_groups = true) { } - // Forward to thread listeners and pubstream (sys channel), *unless* there is even - // a remote hint that the item might have some privacy attached. - // This could be (for instance) an ActivityPub DM - // in the middle of a public thread. Unless we can guarantee beyond all doubt that - // this is public, don't allow it to go to thread listeners. + // Forward to thread listeners and pubstream (sys channel), + // *unless* there is even a remote hint that the item might have some privacy attached. if(!intval($item['item_private'])) { $sys = get_sys_channel(); @@ -212,6 +209,7 @@ function collect_recipients($item, &$private_envelope,$include_groups = true) { $recipients[] = $item['owner_xchan']; } + return $recipients; } @@ -3043,6 +3041,40 @@ function tgroup_check($uid, $item) { } + +function i_am_mentioned($channel, $item, $check_groups = false) { + + $link = z_root() . '/channel/' . $channel['channel_address']; + + $body = preg_replace('/\[share(.*?)\[\/share]/','',$item['body']); + + $tagged = false; + $matches = []; + $tagtype = $check_groups ? TERM_FORUM : TERM_MENTION; + $terms = ((isset($item['term'])) ? get_terms_oftype($item['term'], $tagtype) : false); + + if ($terms) { + foreach ($terms as $term) { + if ($link === $term['url']) { + $pattern = '/[!@]!?\[[uz]rl=' . preg_quote($term['url'],'/') . '](.*?)\[\/[uz]rl]/'; + if (preg_match($pattern,$body,$matches)) { + $tagged = true; + } + $pattern = '/\[[uz]rl=' . preg_quote($term['url'],'/') . '][!@](.*?)\[\/[uz]rl]/'; + if (preg_match($pattern,$body,$matches)) { + $tagged = true; + } + } + } + } + $unless = intval(get_pconfig($channel['channel_id'], 'system', 'unless_mention_count', get_config('system', 'unless_mention_count', 20))); + if ($unless && $terms && count($terms) > $unless) { + $tagged = false; + } + return $tagged; +} + + /** * Sourced and tag-delivered posts are re-targetted for delivery to the connections of the channel * receiving the post. This starts the second delivery chain, by resetting permissions and ensuring diff --git a/include/taxonomy.php b/include/taxonomy.php index 671f96c2e..3f6db50d1 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -119,13 +119,14 @@ function store_item_tag($uid,$iid,$otype,$type,$term,$url = '') { } -function get_terms_oftype($arr,$type) { - $ret = array(); - if(! (is_array($arr) && count($arr))) +function get_terms_oftype($arr, $type) { + $ret = []; + + if(!is_array($arr) && count($arr)) return $ret; if(! is_array($type)) - $type = array($type); + $type = [$type]; foreach($type as $t) foreach($arr as $x) diff --git a/view/tpl/settings_privacy.tpl b/view/tpl/settings_privacy.tpl index aff9619c3..77d125e41 100644 --- a/view/tpl/settings_privacy.tpl +++ b/view/tpl/settings_privacy.tpl @@ -8,8 +8,9 @@
- {{include file="field_checkbox.tpl" field=$autoperms}} {{include file="field_checkbox.tpl" field=$index_opt_out}} + {{include file="field_checkbox.tpl" field=$autoperms}} + {{include file="field_checkbox.tpl" field=$permit_all_mentions}} {{if $sec_addon}} {{$sec_addon}} -- cgit v1.2.3 From 70b3c8080ecb3bafea7dd57ec07a410061b26953 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 24 Mar 2023 09:01:06 +0000 Subject: encode object after we have dealt with deleted items and work around a php error --- Zotlabs/Lib/Activity.php | 8 ++++---- Zotlabs/Thumbs/Text.php | 18 +++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index d4a89d2a4..baa27a051 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -419,10 +419,6 @@ class Activity { $objtype = self::activity_obj_mapper($i['obj_type']); } - if (isset($i['obj']) && $i['obj']) { - $ret = Activity::encode_object($i['obj']); - } - if (intval($i['item_deleted'])) { $ret['type'] = 'Tombstone'; $ret['formerType'] = $objtype; @@ -434,6 +430,10 @@ class Activity { return $ret; } + if (isset($i['obj']) && $i['obj']) { + $ret = Activity::encode_object($i['obj']); + } + if (isset($i['obj']) && $i['obj']) { if (is_array($i['obj'])) { $ret = $i['obj']; diff --git a/Zotlabs/Thumbs/Text.php b/Zotlabs/Thumbs/Text.php index 3ee7819bd..31e27d014 100644 --- a/Zotlabs/Thumbs/Text.php +++ b/Zotlabs/Thumbs/Text.php @@ -11,6 +11,10 @@ class Text { function Thumb($attach,$preview_style,$height = 300, $width = 300) { + if (empty($attach['content'])) { + return; + } + $stream = @fopen(dbunescbin($attach['content']),'rb'); if($stream) { $content = trim(stream_get_contents($stream,4096)); @@ -25,13 +29,13 @@ class Text { $colour = imagecolorallocate($image,0,0,0); $border = imagecolorallocate($image,208,208,208); - $x1 = 0; - $y1 = 0; - $x2 = ImageSX($image) - 1; - $y2 = ImageSY($image) - 1; + $x1 = 0; + $y1 = 0; + $x2 = ImageSX($image) - 1; + $y2 = ImageSY($image) - 1; - for($i = 0; $i < 2; $i++) { - ImageRectangle($image, $x1++, $y1++, $x2--, $y2--, $border); + for($i = 0; $i < 2; $i++) { + ImageRectangle($image, $x1++, $y1++, $x2--, $y2--, $border); } foreach($content_a as $l => $t) { @@ -46,4 +50,4 @@ class Text { imagejpeg($image,dbunescbin($attach['content']) . '.thumb'); } } -} \ No newline at end of file +} -- cgit v1.2.3 From 70ca247c88d580870af753315f00e2b105ad21ef Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 24 Mar 2023 09:22:10 +0000 Subject: in fact this can be removed --- Zotlabs/Lib/Activity.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index baa27a051..416aaa0d8 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -430,10 +430,6 @@ class Activity { return $ret; } - if (isset($i['obj']) && $i['obj']) { - $ret = Activity::encode_object($i['obj']); - } - if (isset($i['obj']) && $i['obj']) { if (is_array($i['obj'])) { $ret = $i['obj']; -- cgit v1.2.3 From b3cfeb573a47058f7c2a119829875a5286a078ad Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 29 Mar 2023 21:46:28 +0200 Subject: do not add not_here, anon, token and rss contacts to receivers --- include/items.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/items.php b/include/items.php index a7d07a599..3a2b5efb2 100644 --- a/include/items.php +++ b/include/items.php @@ -112,7 +112,7 @@ function collect_recipients($item, &$private_envelope,$include_groups = true) { if ($hookinfo['recipients']) { $r = $hookinfo['recipients']; } else { - $r = q("select abook_xchan, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 ", + $r = q("select abook_xchan, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 and abook_not_here = 0 and xchan_network not in ('anon', 'token', 'rss')", intval($item['uid']) ); } @@ -209,7 +209,6 @@ function collect_recipients($item, &$private_envelope,$include_groups = true) { $recipients[] = $item['owner_xchan']; } - return $recipients; } -- cgit v1.2.3 From ba71c53bc6565849ec5ad7af759173e92a498858 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 30 Mar 2023 12:08:43 +0000 Subject: ignore deliveries by our own channel which do not origin from the local hub. instead rely on the sync delivery. --- Zotlabs/Daemon/Notifier.php | 1 + Zotlabs/Lib/Libzot.php | 2 +- include/items.php | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php index d5fe7ee6d..4f0538965 100644 --- a/Zotlabs/Daemon/Notifier.php +++ b/Zotlabs/Daemon/Notifier.php @@ -334,6 +334,7 @@ class Notifier { $m = get_iconfig($target_item, 'activitypub', 'signed_data'); // Re-use existing signature unless the activity type changed to a Tombstone, which won't verify. if ($m && (!intval($target_item['item_deleted']))) { + hz_syslog('notifier existing'); self::$encoded_item = json_decode($m, true); } else { diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 406a26910..709c9dc94 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1585,7 +1585,7 @@ class Libzot { * access checks. */ - if ($sender === $channel['channel_hash'] && $arr['author_xchan'] === $channel['channel_hash'] && $arr['mid'] === $arr['parent_mid']) { + if ($sender === $channel['channel_hash'] && $arr['author_xchan'] === $channel['channel_hash'] && !str_starts_with($arr['mid'], z_root())) { $DR->update('self delivery ignored'); $result[] = $DR->get(); continue; diff --git a/include/items.php b/include/items.php index 3a2b5efb2..a9930470c 100644 --- a/include/items.php +++ b/include/items.php @@ -202,7 +202,7 @@ function collect_recipients($item, &$private_envelope,$include_groups = true) { // add ourself just in case we have nomadic clones that need to get a copy. if (!in_array($item['author_xchan'], $recipients)) { - $recipients[] = $item['author_xchan']; + // $recipients[] = $item['author_xchan']; } if($item['owner_xchan'] !== $item['author_xchan'] && !in_array($item['owner_xchan'], $recipients)) { -- cgit v1.2.3 From 92a89ca25800d745b2a9aba5c619e6e453ff5060 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 30 Mar 2023 13:10:47 +0000 Subject: version 8.3.1 --- boot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot.php b/boot.php index 81a41d292..d8349c2e2 100644 --- a/boot.php +++ b/boot.php @@ -60,7 +60,7 @@ require_once('include/bbcode.php'); require_once('include/items.php'); define('PLATFORM_NAME', 'hubzilla'); -define('STD_VERSION', '8.3'); +define('STD_VERSION', '8.3.1'); define('ZOT_REVISION', '6.0'); define('DB_UPDATE_VERSION', 1255); -- cgit v1.2.3 From 24568c0e2f5f8537da7a6bc6a62b5785edf2cb9f Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 30 Mar 2023 13:23:16 +0000 Subject: add some explanation and remove logging --- Zotlabs/Daemon/Notifier.php | 1 - Zotlabs/Lib/Libzot.php | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php index 4f0538965..d5fe7ee6d 100644 --- a/Zotlabs/Daemon/Notifier.php +++ b/Zotlabs/Daemon/Notifier.php @@ -334,7 +334,6 @@ class Notifier { $m = get_iconfig($target_item, 'activitypub', 'signed_data'); // Re-use existing signature unless the activity type changed to a Tombstone, which won't verify. if ($m && (!intval($target_item['item_deleted']))) { - hz_syslog('notifier existing'); self::$encoded_item = json_decode($m, true); } else { diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 709c9dc94..129ac6b56 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1583,6 +1583,11 @@ class Libzot { * There's a chance the current delivery could take place before the cloned copy arrives * hence the item could have the wrong ACL and *could* be used in subsequent deliveries or * access checks. + * + * 30.3.23: block all incoming items from ourselves except if the origin is local. + * This is to prevent multiple relay delivery of items that arrive via sync. + * They have already been relayed at the origin location. + * */ if ($sender === $channel['channel_hash'] && $arr['author_xchan'] === $channel['channel_hash'] && !str_starts_with($arr['mid'], z_root())) { -- cgit v1.2.3 From 5ec721b97823df32dca418bf2b5343b70c584114 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 31 Mar 2023 09:31:28 +0200 Subject: likes not synced between clones --- Zotlabs/Module/Like.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Zotlabs/Module/Like.php b/Zotlabs/Module/Like.php index ef41faedd..2cf792c8d 100644 --- a/Zotlabs/Module/Like.php +++ b/Zotlabs/Module/Like.php @@ -407,12 +407,20 @@ class Like extends Controller { if (activity_match($rr['verb'], $activity)) $multi_undo = false; + $d = q("select * from item where id = %d", + intval($rr['id']) + ); + if ($d) { + xchan_query($d); + $sync_item = fetch_post_tags($d); + Libsync::build_sync_packet($profile_uid, ['item' => [encode_item($sync_item[0], true)]]); + } + // drop_item was not done interactively, so we need to invoke the notifier // in order to push the changes to connections Master::Summon(array('Notifier', 'drop', $rr['id'])); - } if ($interactive) @@ -562,6 +570,15 @@ class Like extends Controller { call_hooks('post_local_end', $arr); + $r = q("select * from item where id = %d", + intval($post_id) + ); + if ($r) { + xchan_query($r); + $sync_item = fetch_post_tags($r); + Libsync::build_sync_packet($profile_uid, ['item' => [encode_item($sync_item[0], true)]]); + } + if ($extended_like) { $r = q("insert into likes (channel_id,liker,likee,iid,i_mid,verb,target_type,target_id,target) values (%d,'%s','%s',%d,'%s','%s','%s','%s','%s')", intval($ch[0]['channel_id']), -- cgit v1.2.3 From 9b93dc51373878d7a0cbce3053e4308e7715b9c1 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 8 Apr 2023 20:18:17 +0000 Subject: split up a potentially long running sql query --- Zotlabs/Lib/Libzot.php | 14 ++++++++++---- include/text.php | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 129ac6b56..97ea1bbfd 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1389,14 +1389,20 @@ class Libzot { $r = []; $thread_parent = self::find_parent($env, $act); if ($thread_parent) { - $z = q("select channel_hash as hash from channel left join item on channel.channel_id = item.uid where ( item.thr_parent = '%s' OR item.parent_mid = '%s' ) and channel_hash != '%s'", + $uids = q("SELECT uid FROM item WHERE thr_parent = '%s' OR parent_mid = '%s'", dbesc($thread_parent), - dbesc($thread_parent), - dbesc($env['sender']) + dbesc($thread_parent) ); + + $uids = ids_to_querystr($uids, 'uid'); + + $z = q("SELECT channel_hash FROM channel WHERE channel_hash != '%s' AND channel_id IN ($uids)", + dbesc($msg['sender']) + ); + if ($z) { foreach ($z as $zv) { - $r[] = $zv['hash']; + $r[] = $zv['channel_hash']; } } } diff --git a/include/text.php b/include/text.php index 705147e93..f1a7f5fbf 100644 --- a/include/text.php +++ b/include/text.php @@ -3322,6 +3322,8 @@ function item_url_replace($channel,&$item,$old,$new,$oldnick = '') { $root_replaced = null; $nick_replaced = null; + // FIXME: ignore anything in a share tag + $item['body'] = str_replace($old, $new, $item['body'], $root_replaced); if($oldnick && ($oldnick !== $channel['channel_address'])) { -- cgit v1.2.3 From 1538107ae45f9b7c09d377083cf969ca81d373c0 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 8 Apr 2023 20:25:31 +0000 Subject: minor queueworker fixes --- Zotlabs/Lib/QueueWorker.php | 6 +++--- Zotlabs/Module/Admin/Queueworker.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php index 696fb79fc..a1c13ef8a 100644 --- a/Zotlabs/Lib/QueueWorker.php +++ b/Zotlabs/Lib/QueueWorker.php @@ -159,7 +159,7 @@ class QueueWorker { //usleep(self::$workersleep); - $workers = dbq("select count(distinct workerq_reservationid) as total from workerq where workerq_reservationid is not null"); + $workers = dbq("select count(*) as total from workerq where workerq_reservationid is not null"); logger("WORKERCOUNT: " . $workers[0]['total'], LOGGER_DEBUG); return intval($workers[0]['total']); @@ -172,7 +172,7 @@ class QueueWorker { $wid = uniqid('', true); - usleep(mt_rand(300000, 1000000)); //Sleep .3 - 1 seconds before creating a new worker. + //usleep(mt_rand(300000, 1000000)); //Sleep .3 - 1 seconds before creating a new worker. $workers = self::GetWorkerCount(); @@ -197,7 +197,7 @@ class QueueWorker { $work = dbq("SELECT workerq_id, workerq_cmd FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1 FOR UPDATE $sql_quirks"); if (!$work) { - self::qcommit(); + self::qrollback(); return false; } diff --git a/Zotlabs/Module/Admin/Queueworker.php b/Zotlabs/Module/Admin/Queueworker.php index 45a09bf04..a4f38d07c 100644 --- a/Zotlabs/Module/Admin/Queueworker.php +++ b/Zotlabs/Module/Admin/Queueworker.php @@ -41,7 +41,7 @@ class Queueworker extends Controller { $content .= "

There are " . $r[0]['total'] . " queue items to be processed.

"; - $r = dbq("select count(distinct workerq_reservationid) as qworkers from workerq where workerq_reservationid is not null"); + $r = dbq("select count(*) as qworkers from workerq where workerq_reservationid is not null"); $content .= "

Active workers: " . $r[0]['qworkers'] . "

"; -- cgit v1.2.3 From 4873f61d6cb494e82d7aef3892c99b81a41cea61 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 9 Apr 2023 18:51:55 +0000 Subject: disable thread listener interface by default and minor fixes --- Zotlabs/Lib/Libzot.php | 18 ++++++++++-------- Zotlabs/Lib/ThreadListener.php | 20 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 97ea1bbfd..a8334595f 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -984,7 +984,7 @@ class Libzot { } elseif (!$ud_flags) { // nothing changed but we still need to update the updates record - q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and not (ud_flags & %d) > 0 ", + q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and (ud_flags & %d) = 0 ", intval(UPDATE_FLAGS_UPDATED), dbesc($address), intval(UPDATE_FLAGS_UPDATED) @@ -1394,15 +1394,17 @@ class Libzot { dbesc($thread_parent) ); - $uids = ids_to_querystr($uids, 'uid'); + if ($uids) { + $uids = ids_to_querystr($uids, 'uid'); - $z = q("SELECT channel_hash FROM channel WHERE channel_hash != '%s' AND channel_id IN ($uids)", - dbesc($msg['sender']) - ); + $z = q("SELECT channel_hash FROM channel WHERE channel_hash != '%s' AND channel_id IN ($uids)", + dbesc($msg['sender']) + ); - if ($z) { - foreach ($z as $zv) { - $r[] = $zv['channel_hash']; + if ($z) { + foreach ($z as $zv) { + $r[] = $zv['channel_hash']; + } } } } diff --git a/Zotlabs/Lib/ThreadListener.php b/Zotlabs/Lib/ThreadListener.php index 308e02255..ef245b1ce 100644 --- a/Zotlabs/Lib/ThreadListener.php +++ b/Zotlabs/Lib/ThreadListener.php @@ -4,18 +4,30 @@ namespace Zotlabs\Lib; class ThreadListener { + public static function isEnabled() { + return Config::Get('system','enable_thread_listener'); + } + static public function store($target_id,$portable_id,$ltype = 0) { + if (!self::isEnabled()) { + return true; + } + $x = self::fetch($target_id,$portable_id,$ltype = 0); - if(! $x) { + if(! $x) { $r = q("insert into listeners ( target_id, portable_id, ltype ) values ( '%s', '%s' , %d ) ", dbesc($target_id), dbesc($portable_id), intval($ltype) ); - } + } } static public function fetch($target_id,$portable_id,$ltype = 0) { + if (!self::isEnabled()) { + return false; + } + $x = q("select * from listeners where target_id = '%s' and portable_id = '%s' and ltype = %d limit 1", dbesc($target_id), dbesc($portable_id), @@ -28,6 +40,10 @@ class ThreadListener { } static public function fetch_by_target($target_id,$ltype = 0) { + if (!self::isEnabled()) { + return []; + } + $x = q("select * from listeners where target_id = '%s' and ltype = %d", dbesc($target_id), intval($ltype) -- cgit v1.2.3