Add title to the text/html content for Twitter status object

This commit is contained in:
Philipp 2022-01-01 23:14:52 +01:00
parent 2f13afb4c0
commit 4c77e99f89
No known key found for this signature in database
GPG Key ID: 24A7501396EB5432
3 changed files with 20 additions and 7 deletions

View File

@ -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);
}
}

View File

@ -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();

View File

@ -34,7 +34,7 @@ class StatusTest extends FixtureTest
$status = $statusObj->toArray();
self::assertStringStartsWith('item_title', $status['text']);
self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $status['html']);
self::assertStringStartsWith('<h4>item_title</h4><br>perspiciatis impedit voluptatem', $status['friendica_html']);
}
/**