mirror of
https://github.com/friendica/friendica
synced 2025-04-27 14:30:11 +00:00
Scheduled posts can now be created
This commit is contained in:
parent
4137a6250b
commit
bb37c41bd7
2 changed files with 75 additions and 2 deletions
|
@ -21,7 +21,9 @@
|
|||
|
||||
namespace Friendica\Module\Api\Mastodon;
|
||||
|
||||
use Friendica\App\Router;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
|
@ -30,6 +32,36 @@ use Friendica\Module\BaseApi;
|
|||
*/
|
||||
class ScheduledStatuses extends BaseApi
|
||||
{
|
||||
public static function put(array $parameters = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
self::unsupported(Router::PUT);
|
||||
}
|
||||
|
||||
public static function delete(array $parameters = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($parameters['id'])) {
|
||||
DI::mstdnError()->UnprocessableEntity();
|
||||
}
|
||||
|
||||
$condtion = ['id' => $parameters['id'], 'uid' => $uid];
|
||||
$post = DBA::selectFirst('delayed-post', ['id'], $condtion);
|
||||
if (empty($post['id'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
if (!DBA::delete('delayed-post', $condtion)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
System::jsonExit([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
|
@ -50,6 +82,37 @@ class ScheduledStatuses extends BaseApi
|
|||
'min_id' => 0, // Return results immediately newer than ID
|
||||
]);
|
||||
|
||||
System::jsonExit([]);
|
||||
$params = ['order' => ['id' => true], 'limit' => $request['limit']];
|
||||
|
||||
$condition = ["`uid` = ? AND NOT `wid` IS NULL", $uid];
|
||||
|
||||
if (!empty($request['max_id'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $request['max_id']]);
|
||||
}
|
||||
|
||||
if (!empty($request['since_id'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['since_id']]);
|
||||
}
|
||||
|
||||
if (!empty($request['min_id'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['min_id']]);
|
||||
$params['order'] = ['uri-id'];
|
||||
}
|
||||
|
||||
$posts = DBA::select('delayed-post', ['id'], $condition, $params);
|
||||
|
||||
$statuses = [];
|
||||
while ($post = DBA::fetch($posts)) {
|
||||
self::setBoundaries($post['id']);
|
||||
$statuses[] = DI::mstdnScheduledStatus()->createFromId($post['id'], $uid);
|
||||
}
|
||||
DBA::close($posts);
|
||||
|
||||
if (!empty($request['min_id'])) {
|
||||
array_reverse($statuses);
|
||||
}
|
||||
|
||||
self::setLinkHeader();
|
||||
System::jsonExit($statuses);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue