All needed fields are now filled

This commit is contained in:
Michael 2021-07-30 13:22:06 +00:00
parent 93263a820d
commit 929de9081e
5 changed files with 41 additions and 7 deletions

View file

@ -23,6 +23,8 @@ namespace Friendica\Factory\Api\Mastodon;
use Friendica\BaseFactory;
use Friendica\Database\Database;
use Friendica\Model\ItemURI;
use Friendica\Model\Photo;
use Friendica\Model\Post;
use Friendica\Network\HTTPException;
use Psr\Log\LoggerInterface;
@ -57,6 +59,17 @@ class ScheduledStatus extends BaseFactory
throw new HTTPException\NotFoundException('Scheduled status with ID ' . $id . ' not found for user ' . $uid . '.');
}
return new \Friendica\Object\Api\Mastodon\ScheduledStatus($delayed_post, $parameters);
$media_ids = [];
foreach ($parameters['attachments'] as $attachment) {
$media_ids[] = Photo::getIdForName($attachment['url']);
}
if (isset($parameters['item']['thr-parent']) && ($parameters['item']['gravity'] ?? GRAVITY_PARENT != GRAVITY_PARENT)) {
$in_reply_to_id = ItemURI::getIdByURI($parameters['item']['thr-parent']);
} else {
$in_reply_to_id= null;
}
return new \Friendica\Object\Api\Mastodon\ScheduledStatus($delayed_post, $parameters, $media_ids, $in_reply_to_id);
}
}

View file

@ -841,13 +841,28 @@ class Photo
* @throws \Exception
*/
public static function isLocal($name)
{
return (bool)self::getIdForName($name);
}
/**
* Return the id of a local photo
*
* @param string $name Picture link
* @return int
*/
public static function getIdForName($name)
{
$data = self::getResourceData($name);
if (empty($data)) {
return false;
return 0;
}
return DBA::exists('photo', ['resource-id' => $data['guid'], 'scale' => $data['scale']]);
$photo = DBA::selectFirst('photo', ['id'], ['resource-id' => $data['guid'], 'scale' => $data['scale']]);
if (!empty($photo['id'])) {
return $photo['id'];
}
return 0;
}
/**

View file

@ -134,6 +134,12 @@ class Delayed
return [];
}
// Make sure to only publish the attachments in the dedicated array field
if (empty($parameters[3]) && !empty($parameters[0]['attachments'])) {
$parameters[3] = $parameters[0]['attachments'];
unset($parameters[0]['attachments']);
}
return [
'parameters' => $delayed,
'item' => $parameters[0],

View file

@ -72,7 +72,7 @@ class ScheduledStatuses extends BaseApi
$uid = self::getCurrentUserID();
if (isset($parameters['id'])) {
System::jsonExit(DI::mstdnScheduledStatus()->createFromDelayedPostId($parameters['id'], $uid)->toArray());
System::jsonExit(DI::mstdnScheduledStatus()->createFromDelayedPostId($parameters['id'], $uid)->toArray());
}
$request = self::getRequest([

View file

@ -59,7 +59,7 @@ class ScheduledStatus extends BaseDataTransferObject
* @param array $parameters Parameters for the workerqueue entry for the delayed post
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function __construct(array $delayed_post, array $parameters)
public function __construct(array $delayed_post, array $parameters, array $media_ids = null, int $in_reply_to_id = null)
{
$visibility = ['public', 'private', 'unlisted'];
@ -68,14 +68,14 @@ class ScheduledStatus extends BaseDataTransferObject
$this->params = [
'text' => BBCode::convert(BBCode::setMentionsToNicknames($parameters['item']['body'] ?? ''), false, BBCode::API),
'media_ids' => null,
'media_ids' => $media_ids,
'sensitive' => null,
'spoiler_text' => $parameters['item']['title'] ?? '',
'visibility' => $visibility[$parameters['item']['private']],
'scheduled_at' => $this->scheduled_at,
'poll' => null,
'idempotency' => null,
'in_reply_to_id' => null,
'in_reply_to_id' => $in_reply_to_id,
'application_id' => ''
];