Add account_id filter for mastodon posts retrieval

This commit is contained in:
Bofh 2022-12-28 23:48:50 +01:00
parent 37313a4e9d
commit c398b2b1d6
1 changed files with 14 additions and 7 deletions

View File

@ -7,6 +7,7 @@ $_ = function() {
$start = arg('*get.start', null, 'valid_mastodon_account_id');
$limit = arg('i:get.limit', $MAX_LIMIT);
$local = arg('set:get.local');
$account_id = arg('get.account_id', null, 'valid_mastodon_account_id');
if ($limit > $MAX_LIMIT)
$limit = $MAX_LIMIT;
@ -20,17 +21,22 @@ SELECT '.$fields.', reblog_of_id
FROM statuses AS s
{innerJoinAccounts}
WHERE
{accountId}
{isLocal}
s.id >= '.$start.'
ORDER BY id ASC LIMIT '.$limit.'
';
if ($local) {
if ($local)
$sql_all = str_replace('{isLocal}', 'a.domain IS NULL AND', $sql_all);
else $sql_all = str_replace('{isLocal}', '', $sql_all);
if ($local || $account_id !== null)
$sql_all = str_replace('{innerJoinAccounts}', 'INNER JOIN accounts AS a ON a.id = s.account_id', $sql_all);
} else {
$sql_all = str_replace('{isLocal}', '', $sql_all);
$sql_all = str_replace('{innerJoinAccounts}', '', $sql_all);
}
else $sql_all = str_replace('{innerJoinAccounts}', '', $sql_all);
if ($account_id !== null)
$sql_all = str_replace('{accountId}', "a.id = $account_id AND", $sql_all);
else $sql_all = str_replace('{accountId}', '', $sql_all);
$objects = $pg->fetch_all($sql_all);
foreach ($objects as &$object) {
@ -42,9 +48,10 @@ ORDER BY id ASC LIMIT '.$limit.'
$delay = 0;
$next_start = null;
if (count($objects) > 0) {
$delay = $pg->fetch('SELECT COUNT(1) FROM statuses WHERE id > '.$objects[count($objects)-1]['id']);
$objects = array_reverse($objects);
$delay = $pg->fetch('SELECT COUNT(1) FROM statuses WHERE id > '.$objects[0]['id']);
$delay = intval($delay['count']);
$next_start = $objects[count($objects)-1]['id'];
$next_start = $objects[0]['id'];
}
if ($delay > $limit)
$delay = ['total' => $delay, 'ticks' => intval($delay / $limit)];