add collection support to moderation

This commit is contained in:
Mike Macgirvin 2024-02-22 06:55:20 +11:00
parent 90fa6df7a4
commit 365ed9ed92
3 changed files with 20 additions and 7 deletions

View file

@ -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;
}

View file

@ -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');
}

View file

@ -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 = [];