<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\BaseDataTransferObject;
use Friendica\Content\Text\BBCode;
+use Friendica\Model\Item;
use Friendica\Object\Api\Mastodon\Status\Counts;
+use Friendica\Object\Api\Mastodon\Status\FriendicaExtension;
use Friendica\Object\Api\Mastodon\Status\UserAttributes;
use Friendica\Util\DateTimeFormat;
protected $created_at;
/** @var string|null */
protected $in_reply_to_id = null;
+ /** @var Status|null - Fedilab extension, see issue https://github.com/friendica/friendica/issues/12672 */
+ protected $in_reply_to_status = null;
/** @var string|null */
protected $in_reply_to_account_id = null;
/** @var bool */
protected $content;
/** @var Status|null */
protected $reblog = null;
+ /** @var Status|null - Akkoma extension, see issue https://github.com/friendica/friendica/issues/12603 */
+ protected $quote = null;
/** @var Application */
protected $application = null;
/** @var Account */
protected $card = null;
/** @var Poll|null */
protected $poll = null;
+ /** @var FriendicaExtension */
+ protected $friendica;
/**
* Creates a status record from an item record.
* @param array $item
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public function __construct(array $item, Account $account, Counts $counts, UserAttributes $userAttributes, bool $sensitive, Application $application, array $mentions, array $tags, Card $card, array $attachments, array $reblog)
+ public function __construct(array $item, Account $account, Counts $counts, UserAttributes $userAttributes, bool $sensitive, Application $application, array $mentions, array $tags, Card $card, array $attachments, array $in_reply, array $reblog, FriendicaExtension $friendica, array $quote = null, array $poll = null)
{
$this->id = (string)$item['uri-id'];
$this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::JSON);
- if ($item['gravity'] == GRAVITY_COMMENT) {
+ if ($item['gravity'] == Item::GRAVITY_COMMENT) {
$this->in_reply_to_id = (string)$item['thr-parent-id'];
+ $this->in_reply_to_status = $in_reply;
$this->in_reply_to_account_id = (string)$item['parent-author-id'];
}
- $this->sensitive = $sensitive;
- $this->spoiler_text = $item['title'];
+ $this->sensitive = $sensitive;
+ $this->spoiler_text = $item['title'] ?: $item['content-warning'] ?: '';
$visibility = ['public', 'private', 'unlisted'];
$this->visibility = $visibility[$item['private']];
- $languages = json_decode($item['language'], true);
+ $languages = json_decode($item['language'] ?? '', true);
if (is_array($languages)) {
reset($languages);
$this->language = key($languages);
$this->muted = $userAttributes->muted;
$this->bookmarked = $userAttributes->bookmarked;
$this->pinned = $userAttributes->pinned;
- $this->content = BBCode::convertForUriId($item['uri-id'], ($item['raw-body'] ?? $item['body']), BBCode::EXTERNAL);
+ $this->content = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::MASTODON_API);
$this->reblog = $reblog;
+ $this->quote = $quote;
$this->application = $application->toArray();
$this->account = $account->toArray();
$this->media_attachments = $attachments;
$this->tags = $tags;
$this->emojis = [];
$this->card = $card->toArray() ?: null;
- $this->poll = null;
+ $this->poll = $poll;
+ $this->friendica = $friendica;
+ }
+
+ /**
+ * Returns the current created_at DateTime as an integer timestamp
+ * @return int
+ * @throws \Exception
+ */
+ public function createdAtTimestamp(): int
+ {
+ $result = strtotime($this->created_at);
+ if (!$result) {
+ throw new \Exception('Unknown date-time format');
+ }
+
+ return $result;
}
/**
$status['reblog'] = null;
}
+ if (empty($status['quote'])) {
+ $status['quote'] = null;
+ }
+
+ if (empty($status['in_reply_to_status'])) {
+ $status['in_reply_to_status'] = null;
+ }
+
return $status;
}
}