mirror of
https://github.com/friendica/friendica
synced 2025-04-25 06:30:11 +00:00
More data for the Mastodon status class
This commit is contained in:
parent
bd49fe0f99
commit
a643888aeb
9 changed files with 426 additions and 15 deletions
62
src/Object/Api/Mastodon/Card.php
Normal file
62
src/Object/Api/Mastodon/Card.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2020, Friendica
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Object\Api\Mastodon;
|
||||
|
||||
use Friendica\BaseEntity;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Object\Api\Mastodon\Status\Counts;
|
||||
use Friendica\Object\Api\Mastodon\Status\UserAttributes;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
/**
|
||||
* Class Card
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/entities/card
|
||||
*/
|
||||
class Card extends BaseEntity
|
||||
{
|
||||
/** @var string */
|
||||
protected $url;
|
||||
/** @var string */
|
||||
protected $title;
|
||||
/** @var string */
|
||||
protected $description;
|
||||
/** @var string */
|
||||
protected $type;
|
||||
/** @var string */
|
||||
protected $image;
|
||||
|
||||
/**
|
||||
* Creates a status record from an item record.
|
||||
*
|
||||
* @param array $attachment Attachment record
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function __construct(array $attachment)
|
||||
{
|
||||
$this->url = $attachment['url'] ?? '';
|
||||
$this->title = $attachment['title'] ?? '';
|
||||
$this->description = $attachment['description'] ?? '';
|
||||
$this->type = $attachment['type'] ?? '';
|
||||
$this->image = $attachment['image'] ?? '';
|
||||
}
|
||||
}
|
66
src/Object/Api/Mastodon/Mention.php
Normal file
66
src/Object/Api/Mastodon/Mention.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2020, Friendica
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Object\Api\Mastodon;
|
||||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseEntity;
|
||||
|
||||
/**
|
||||
* Class Mention
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/entities/mention
|
||||
*/
|
||||
class Mention extends BaseEntity
|
||||
{
|
||||
/** @var string */
|
||||
protected $id;
|
||||
/** @var string */
|
||||
protected $username;
|
||||
/** @var string */
|
||||
protected $url = null;
|
||||
/** @var string */
|
||||
protected $acct = null;
|
||||
|
||||
/**
|
||||
* Creates a mention record from an tag-view record.
|
||||
*
|
||||
* @param BaseURL $baseUrl
|
||||
* @param array $tag tag-view record
|
||||
* @param array $contact contact table record
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function __construct(BaseURL $baseUrl, array $tag, array $contact)
|
||||
{
|
||||
$this->id = $contact['id'] ?? 0;
|
||||
$this->username = $tag['name'];
|
||||
$this->url = $tag['url'];
|
||||
|
||||
if (!empty($contact)) {
|
||||
$this->acct =
|
||||
strpos($contact['url'], $baseUrl->get() . '/') === 0 ?
|
||||
$contact['nick'] :
|
||||
$contact['addr'];
|
||||
} else {
|
||||
$this->acct = '';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ namespace Friendica\Object\Api\Mastodon;
|
|||
use Friendica\BaseEntity;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Object\Api\Mastodon\Status\Counts;
|
||||
use Friendica\Object\Api\Mastodon\Status\UserAttributes;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
/**
|
||||
|
@ -96,7 +97,7 @@ class Status extends BaseEntity
|
|||
* @param array $item
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function __construct(array $item, Account $account, Counts $counts)
|
||||
public function __construct(array $item, Account $account, Counts $counts, UserAttributes $userAttributes, bool $sensitive, Application $application, array $mentions, array $tags, Card $card)
|
||||
{
|
||||
$this->id = (string)$item['uri-id'];
|
||||
$this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::ATOM);
|
||||
|
@ -106,32 +107,34 @@ class Status extends BaseEntity
|
|||
$this->in_reply_to_account_id = (string)$item['parent-author-id'];
|
||||
}
|
||||
|
||||
$this->sensitive = false;
|
||||
$this->sensitive = $sensitive;
|
||||
$this->spoiler_text = $item['title'];
|
||||
|
||||
$visibility = ['public', 'private', 'unlisted'];
|
||||
$this->visibility = $visibility[$item['private']];
|
||||
|
||||
$this->language = null;
|
||||
$languages = json_decode($item['language'], true);
|
||||
$this->language = is_array($languages) ? array_key_first($languages) : null;
|
||||
|
||||
$this->uri = $item['uri'];
|
||||
$this->url = $item['plink'] ?? null;
|
||||
$this->replies_count = $counts->replies;
|
||||
$this->reblogs_count = $counts->reblogs;
|
||||
$this->favourites_count = $counts->favourites;
|
||||
$this->favourited = false;
|
||||
$this->reblogged = false;
|
||||
$this->muted = false;
|
||||
$this->bookmarked = false;
|
||||
$this->pinned = false;
|
||||
$this->favourited = $userAttributes->favourited;
|
||||
$this->reblogged = $userAttributes->reblogged;
|
||||
$this->muted = $userAttributes->muted;
|
||||
$this->bookmarked = $userAttributes->bookmarked;
|
||||
$this->pinned = $userAttributes->pinned;
|
||||
$this->content = BBCode::convert($item['body'], false);
|
||||
$this->reblog = null;
|
||||
$this->application = null;
|
||||
$this->reblog = null; /// @todo
|
||||
$this->application = $application->toArray();
|
||||
$this->account = $account->toArray();
|
||||
$this->media_attachments = [];
|
||||
$this->mentions = [];
|
||||
$this->tags = [];
|
||||
$this->media_attachments = []; /// @todo
|
||||
$this->mentions = $mentions;
|
||||
$this->tags = $tags;
|
||||
$this->emojis = [];
|
||||
$this->card = null;
|
||||
$this->card = $card->toArray();
|
||||
$this->poll = null;
|
||||
}
|
||||
}
|
||||
|
|
64
src/Object/Api/Mastodon/Status/UserAttributes.php
Normal file
64
src/Object/Api/Mastodon/Status/UserAttributes.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2020, Friendica
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Object\Api\Mastodon\Status;
|
||||
|
||||
/**
|
||||
* Class UserAttributes
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/entities/status
|
||||
*/
|
||||
class UserAttributes
|
||||
{
|
||||
/** @var bool */
|
||||
protected $favourited;
|
||||
/** @var bool */
|
||||
protected $reblogged;
|
||||
/** @var bool */
|
||||
protected $muted;
|
||||
/** @var bool */
|
||||
protected $bookmarked;
|
||||
/** @var bool */
|
||||
protected $pinned;
|
||||
|
||||
/**
|
||||
* Creates a authorized user attributes object
|
||||
*
|
||||
* @param bool $favourited
|
||||
* @param bool $reblogged
|
||||
* @param bool $muted
|
||||
* @param bool $bookmarked
|
||||
* @param bool $pinned
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function __construct(bool $favourited, bool $reblogged, bool $muted, bool $bookmarked, bool $pinned)
|
||||
{
|
||||
$this->favourited = $favourited;
|
||||
$this->reblogged = $reblogged;
|
||||
$this->muted = $muted;
|
||||
$this->bookmarked = $bookmarked;
|
||||
$this->pinned = $pinned;
|
||||
}
|
||||
|
||||
public function __get($name) {
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
51
src/Object/Api/Mastodon/Tag.php
Normal file
51
src/Object/Api/Mastodon/Tag.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2020, Friendica
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Object\Api\Mastodon;
|
||||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseEntity;
|
||||
|
||||
/**
|
||||
* Class Tag
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/entities/tag
|
||||
*/
|
||||
class Tag extends BaseEntity
|
||||
{
|
||||
/** @var string */
|
||||
protected $name;
|
||||
/** @var string */
|
||||
protected $url = null;
|
||||
|
||||
/**
|
||||
* Creates a hashtag record from an tag-view record.
|
||||
*
|
||||
* @param BaseURL $baseUrl
|
||||
* @param array $tag tag-view record
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function __construct(BaseURL $baseUrl, array $tag)
|
||||
{
|
||||
$this->name = $tag['name'];
|
||||
$this->url = $baseUrl . '/search?tag=' . urlencode($tag['name']);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue