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;
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);
}
}
* @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;
}
/**
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],
$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([
* @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'];
$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' => ''
];