mirror of
https://github.com/friendica/friendica
synced 2024-12-22 22:00:16 +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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ class Statuses extends BaseApi
|
|||
$item['deny_gid'] = $owner['deny_gid'];
|
||||
} else {
|
||||
$item['allow_cid'] = '';
|
||||
$item['allow_gid'] = [Group::FOLLOWERS];
|
||||
$item['allow_gid'] = '<' . Group::FOLLOWERS . '>';
|
||||
$item['deny_cid'] = '';
|
||||
$item['deny_gid'] = '';
|
||||
}
|
||||
|
@ -183,6 +183,16 @@ class Statuses extends BaseApi
|
|||
}
|
||||
}
|
||||
|
||||
if (!empty($request['scheduled_at'])) {
|
||||
$item['guid'] = Item::guid($item, true);
|
||||
$item['uri'] = Item::newURI($item['uid'], $item['guid']);
|
||||
$id = Post\Delayed::add($item['uri'], $item, PRIORITY_HIGH, false, $request['scheduled_at']);
|
||||
if (empty($id)) {
|
||||
DI::mstdnError()->InternalError();
|
||||
}
|
||||
System::jsonExit(DI::mstdnScheduledStatus()->createFromId($id, $uid)->toArray());
|
||||
}
|
||||
|
||||
$id = Item::insert($item, true);
|
||||
if (!empty($id)) {
|
||||
$item = Post::selectFirst(['uri-id'], ['id' => $id]);
|
||||
|
|
Loading…
Reference in a new issue