Add visibility to user's statuses in Mastodon API
- and remove view count object if not user's status
This commit is contained in:
parent
0b1f67f5b3
commit
97585083d9
|
@ -35,6 +35,7 @@ use Friendica\Model\Verb;
|
|||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Object\Api\Mastodon\Status\FriendicaDeliveryData;
|
||||
use Friendica\Object\Api\Mastodon\Status\FriendicaExtension;
|
||||
use Friendica\Object\Api\Mastodon\Status\FriendicaVisibility;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
use ImagickException;
|
||||
|
@ -100,7 +101,7 @@ class Status extends BaseFactory
|
|||
{
|
||||
$fields = ['uri-id', 'uid', 'author-id', 'causer-id', 'author-uri-id', 'author-link', 'causer-uri-id', 'post-reason', 'starred', 'app', 'title', 'body', 'raw-body', 'content-warning', 'question-id',
|
||||
'created', 'edited', 'commented', 'received', 'changed', 'network', 'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity', 'featured', 'has-media', 'quote-uri-id',
|
||||
'delivery_queue_count', 'delivery_queue_done','delivery_queue_failed'];
|
||||
'delivery_queue_count', 'delivery_queue_done','delivery_queue_failed', 'allow_cid', 'deny_cid', 'allow_gid', 'deny_gid'];
|
||||
$item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
|
||||
if (!$item) {
|
||||
$mail = DBA::selectFirst('mail', ['id'], ['uri-id' => $uriId, 'uid' => $uid]);
|
||||
|
@ -290,8 +291,9 @@ class Status extends BaseFactory
|
|||
$in_reply = [];
|
||||
}
|
||||
|
||||
$delivery_data = new FriendicaDeliveryData($item['delivery_queue_count'], $item['delivery_queue_done'], $item['delivery_queue_failed']);
|
||||
$friendica = new FriendicaExtension($item['title'], $item['changed'], $item['commented'], $item['received'], $counts->dislikes, $delivery_data);
|
||||
$delivery_data = $uid != $item['uid'] ? null : new FriendicaDeliveryData($item['delivery_queue_count'], $item['delivery_queue_done'], $item['delivery_queue_failed']);
|
||||
$visibility_data = $uid != $item['uid'] ? null : new FriendicaVisibility($item['allow_cid'], $item['deny_cid'], $item['allow_gid'], $item['deny_gid']);
|
||||
$friendica = new FriendicaExtension($item['title'], $item['changed'], $item['commented'], $item['received'], $counts->dislikes, $delivery_data, $visibility_data);
|
||||
|
||||
return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts, $userAttributes, $sensitive, $application, $mentions, $tags, $card, $attachments, $in_reply, $reshare, $friendica, $quote, $poll);
|
||||
}
|
||||
|
@ -357,7 +359,7 @@ class Status extends BaseFactory
|
|||
$attachments = [];
|
||||
$in_reply = [];
|
||||
$reshare = [];
|
||||
$friendica = new FriendicaExtension('', null, null, null, 0, new FriendicaDeliveryData(0, 0, 0));
|
||||
$friendica = new FriendicaExtension('', null, null, null, 0, null, null);
|
||||
|
||||
return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts, $userAttributes, $sensitive, $application, $mentions, $tags, $card, $attachments, $in_reply, $reshare, $friendica);
|
||||
}
|
||||
|
|
|
@ -45,14 +45,18 @@ class FriendicaExtension extends BaseDataTransferObject
|
|||
/** @var string|null (Datetime) */
|
||||
protected $received_at;
|
||||
|
||||
/** @var FriendicaDeliveryData */
|
||||
/** @var FriendicaDeliveryData|null */
|
||||
protected $delivery_data;
|
||||
/** @var int */
|
||||
protected $dislikes_count;
|
||||
/**
|
||||
* @var FriendicaVisibility|null
|
||||
*/
|
||||
protected $visibility;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a status count object
|
||||
* Creates a FriendicaExtension object
|
||||
*
|
||||
* @param string $title
|
||||
* @param string|null $changed_at
|
||||
|
@ -60,7 +64,8 @@ class FriendicaExtension extends BaseDataTransferObject
|
|||
* @param string|null $edited_at
|
||||
* @param string|null $received_at
|
||||
* @param int $dislikes_count
|
||||
* @param FriendicaDeliveryData $delivery_data
|
||||
* @param FriendicaDeliveryData|null $delivery_data
|
||||
* @param FriendicaVisibility|null $visibility
|
||||
*/
|
||||
public function __construct(
|
||||
string $title,
|
||||
|
@ -68,7 +73,8 @@ class FriendicaExtension extends BaseDataTransferObject
|
|||
?string $commented_at,
|
||||
?string $received_at,
|
||||
int $dislikes_count,
|
||||
FriendicaDeliveryData $delivery_data
|
||||
?FriendicaDeliveryData $delivery_data,
|
||||
?FriendicaVisibility $visibility
|
||||
) {
|
||||
$this->title = $title;
|
||||
$this->changed_at = $changed_at ? DateTimeFormat::utc($changed_at, DateTimeFormat::JSON) : null;
|
||||
|
@ -76,6 +82,7 @@ class FriendicaExtension extends BaseDataTransferObject
|
|||
$this->received_at = $received_at ? DateTimeFormat::utc($received_at, DateTimeFormat::JSON) : null;
|
||||
$this->delivery_data = $delivery_data;
|
||||
$this->dislikes_count = $dislikes_count;
|
||||
$this->visibility = $visibility;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
51
src/Object/Api/Mastodon/Status/FriendicaVisibility.php
Normal file
51
src/Object/Api/Mastodon/Status/FriendicaVisibility.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @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;
|
||||
|
||||
use Friendica\BaseDataTransferObject;
|
||||
|
||||
/**
|
||||
* Class FriendicaVisibility
|
||||
*
|
||||
* Fields for the user's visibility settings on a post if they own that post
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/entities/status
|
||||
*/
|
||||
class FriendicaVisibility extends BaseDataTransferObject
|
||||
{
|
||||
/** @var string|null */
|
||||
protected $allow_cid;
|
||||
/** @var string|null */
|
||||
protected $deny_cid;
|
||||
/** @var string|null */
|
||||
protected $allow_gid;
|
||||
/** @var string|null */
|
||||
protected $deny_gid;
|
||||
|
||||
public function __construct(?string $allow_cid, ?string $deny_cid, ?string $allow_gid, ?string $deny_gid)
|
||||
{
|
||||
$this->allow_cid = $allow_cid;
|
||||
$this->deny_cid = $deny_cid;
|
||||
$this->allow_gid = $allow_gid;
|
||||
$this->deny_gid = $deny_gid;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue