From 4c77e99f8907b8dc22312f4fd9f5b85cdae2611b Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 1 Jan 2022 23:14:52 +0100 Subject: [PATCH] Add title to the text/html content for Twitter status object --- src/Factory/Api/Twitter/Status.php | 18 ++++++++++++++++-- src/Object/Api/Twitter/Status.php | 7 +++---- tests/src/Factory/Api/Twitter/StatusTest.php | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Factory/Api/Twitter/Status.php b/src/Factory/Api/Twitter/Status.php index 2db1cf1355..57547b0a35 100644 --- a/src/Factory/Api/Twitter/Status.php +++ b/src/Factory/Api/Twitter/Status.php @@ -119,7 +119,21 @@ class Status extends BaseFactory $friendica_comments = Post::countPosts(['thr-parent-id' => $item['uri-id'], 'deleted' => false, 'gravity' => GRAVITY_COMMENT]); - $text = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']); + $text = ''; + + // Add the title to text / html if set + if (!empty($item['title'])) { + $text .= $item['title'] . ' '; + + $title = sprintf("[h4]%s[/h4]\n", $item['title']); + $statusnetHtml = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($title . $item['raw-body'] ?? $item['body']), BBCode::API); + $friendicaHtml = BBCode::convertForUriId($item['uri-id'], $title . $item['body'], BBCode::EXTERNAL); + } else { + $statusnetHtml = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::API); + $friendicaHtml = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::EXTERNAL); + } + + $text .= Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']); $text = trim(HTML::toPlaintext(BBCode::convertForUriId($item['uri-id'], $text, BBCode::API), 0)); @@ -190,6 +204,6 @@ class Status extends BaseFactory $entities = []; } - return new \Friendica\Object\Api\Twitter\Status($text, $item, $author, $owner, $retweeted, $quoted, $geo, $friendica_activities, $entities, $attachments, $friendica_comments, $liked); + return new \Friendica\Object\Api\Twitter\Status($text, $statusnetHtml, $friendicaHtml, $item, $author, $owner, $retweeted, $quoted, $geo, $friendica_activities, $entities, $attachments, $friendica_comments, $liked); } } diff --git a/src/Object/Api/Twitter/Status.php b/src/Object/Api/Twitter/Status.php index ed52deedb8..86ff6b6afd 100644 --- a/src/Object/Api/Twitter/Status.php +++ b/src/Object/Api/Twitter/Status.php @@ -23,7 +23,6 @@ namespace Friendica\Object\Api\Twitter; use Friendica\BaseDataTransferObject; use Friendica\Content\ContactSelector; -use Friendica\Content\Text\BBCode; use Friendica\Model\Item; use Friendica\Util\DateTimeFormat; @@ -99,7 +98,7 @@ class Status extends BaseDataTransferObject * @param array $item * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function __construct(string $text, array $item, User $author, User $owner, array $retweeted, array $quoted, array $geo, array $friendica_activities, array $entities, array $attachments, int $friendica_comments, bool $liked) + public function __construct(string $text, string $statusnetHtml, string $friendicaHtml, array $item, User $author, User $owner, array $retweeted, array $quoted, array $geo, array $friendica_activities, array $entities, array $attachments, int $friendica_comments, bool $liked) { $this->id = (int)$item['id']; $this->id_str = (string)$item['id']; @@ -117,8 +116,8 @@ class Status extends BaseDataTransferObject $this->text = $text; $this->friendica_title = $item['title']; - $this->statusnet_html = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::API); - $this->friendica_html = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::EXTERNAL); + $this->statusnet_html = $statusnetHtml; + $this->friendica_html = $friendicaHtml; $this->user = $author->toArray(); $this->friendica_author = $author->toArray(); $this->friendica_owner = $owner->toArray(); diff --git a/tests/src/Factory/Api/Twitter/StatusTest.php b/tests/src/Factory/Api/Twitter/StatusTest.php index 61dcb0a9cb..1073867ee2 100644 --- a/tests/src/Factory/Api/Twitter/StatusTest.php +++ b/tests/src/Factory/Api/Twitter/StatusTest.php @@ -34,7 +34,7 @@ class StatusTest extends FixtureTest $status = $statusObj->toArray(); self::assertStringStartsWith('item_title', $status['text']); - self::assertStringStartsWith('

item_title


perspiciatis impedit voluptatem', $status['html']); + self::assertStringStartsWith('

item_title


perspiciatis impedit voluptatem', $status['friendica_html']); } /**