From 365ed9ed92cc8b1c491a103173175c2e331bdbed Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Thu, 22 Feb 2024 06:55:20 +1100 Subject: [PATCH] add collection support to moderation --- Code/Lib/Activity.php | 4 ++-- Code/Module/Moderate.php | 16 +++++++++++++--- include/items.php | 7 +++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Code/Lib/Activity.php b/Code/Lib/Activity.php index e1b24f0c7..842f1dbfe 100644 --- a/Code/Lib/Activity.php +++ b/Code/Lib/Activity.php @@ -4902,7 +4902,7 @@ class Activity ->setDenyGid($sourceItem['deny_gid']) ->setPrivate($sourceItem['item_private']); } - $result = post_activity_item($item->toArray(), deliver: $deliver, channel: $channel, observer: $channel); + $result = post_activity_item($item->toArray(), deliver: $deliver, channel: $channel, observer: $channel, addAndSync: false); logger('addToCollection: ' . print_r($result, true)); return $result; } @@ -4927,7 +4927,7 @@ class Activity ] ) ); - $result = post_activity_item($item->toArray(), deliver: $deliver, channel: $channel, observer: $channel); + $result = post_activity_item($item->toArray(), deliver: $deliver, channel: $channel, observer: $channel, addAndSync: false); logger('removeFromCollection: ' . print_r($result, true)); return $result; } diff --git a/Code/Module/Moderate.php b/Code/Module/Moderate.php index c373c1022..dd532f249 100644 --- a/Code/Module/Moderate.php +++ b/Code/Module/Moderate.php @@ -3,6 +3,8 @@ namespace Code\Module; use App; +use Code\Lib\Activity; +use Code\Lib\ObjCache; use Code\Web\Controller; use Code\Lib\Libsync; use Code\Daemon\Run; @@ -22,6 +24,8 @@ class Moderate extends Controller return ''; } + $channel = App::get_channel(); + App::set_pager_itemspage(60); $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start'])); @@ -82,7 +86,7 @@ class Moderate extends Controller if ($r) { $item = $r[0]; - + $approval = false; if ($action === 'approve') { q( "update item set item_blocked = 0 where uid = %d and id = %d", @@ -91,8 +95,11 @@ class Moderate extends Controller ); $item['item_blocked'] = 0; - item_update_parent_commented($item); + $raw = ObjCache::Get($item['mid']); + if ($raw) { + $approval = Activity::addToCollection($channel, json_decode($raw, true), $item['parent_mid'], $item, deliver: false); + } notice(t('Comment approved') . EOL); } elseif ($action === 'drop') { drop_item($post_id); @@ -111,7 +118,7 @@ class Moderate extends Controller Libsync::build_sync_packet(local_channel(), ['item' => [encode_item($sync_item[0], true)]]); } if ($action === 'approve') { - if ($item['id'] !== $item['parent']) { + if ((int)$item['id'] !== (int)$item['parent']) { // if this is a group comment, call tag_deliver() to generate the associated // Announce activity so microblog destinations will see it in their home timeline $role = get_pconfig(local_channel(), 'system', 'permissions_role'); @@ -124,6 +131,9 @@ class Moderate extends Controller } } Run::Summon(['Notifier', 'comment-new', $post_id]); + if ($approval) { + Run::Summon(['Notifier', 'comment-new', $approval['item_id']]); + } } goaway(z_root() . '/moderate'); } diff --git a/include/items.php b/include/items.php index e4381c63b..318bee0eb 100644 --- a/include/items.php +++ b/include/items.php @@ -367,7 +367,7 @@ function absolutely_no_comments($item) { * * \e boolean \b success true or false * * \e array \b activity the resulting activity if successful */ -function post_activity_item($arr, $deliver = true, $channel = null, $observer = null) { +function post_activity_item($arr, $deliver = true, $channel = null, $observer = null, $addAndSync = true) { logger('input: ' . print_r($arr,true), LOGGER_DATA); $ret = [ 'success' => false ]; @@ -462,7 +462,7 @@ function post_activity_item($arr, $deliver = true, $channel = null, $observer = return $ret; } - $post = item_store($arr,$deliver); + $post = item_store($arr,$deliver, $addAndSync); $post_id = 0; if($post['success']) { @@ -1939,6 +1939,9 @@ function addToCollectionAndSync($ret) $channel = Channel::from_id($ret['item']['uid']); if ($channel && $channel['channel_hash'] === $ret['item']['owner_xchan']) { $items = [$ret['item']]; + if ((int)$items[0]['item_blocked'] === ITEM_MODERATED) { + return $ret; + } xchan_query($items); $items = fetch_post_tags($items); $sync_items = [];