Merge pull request #12921 from HankG/add-visibility-data-to-mastodon-status
Add visibility to user's statuses in Mastodon API
This commit is contained in:
commit
a63dc7a3d8
|
@ -28,6 +28,7 @@ use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\Logger;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
|
use Friendica\DI;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Model\Tag as TagModel;
|
use Friendica\Model\Tag as TagModel;
|
||||||
|
@ -35,6 +36,7 @@ use Friendica\Model\Verb;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Object\Api\Mastodon\Status\FriendicaDeliveryData;
|
use Friendica\Object\Api\Mastodon\Status\FriendicaDeliveryData;
|
||||||
use Friendica\Object\Api\Mastodon\Status\FriendicaExtension;
|
use Friendica\Object\Api\Mastodon\Status\FriendicaExtension;
|
||||||
|
use Friendica\Object\Api\Mastodon\Status\FriendicaVisibility;
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
use ImagickException;
|
use ImagickException;
|
||||||
|
@ -100,7 +102,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',
|
$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',
|
'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]]);
|
$item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
|
||||||
if (!$item) {
|
if (!$item) {
|
||||||
$mail = DBA::selectFirst('mail', ['id'], ['uri-id' => $uriId, 'uid' => $uid]);
|
$mail = DBA::selectFirst('mail', ['id'], ['uri-id' => $uriId, 'uid' => $uid]);
|
||||||
|
@ -290,8 +292,10 @@ class Status extends BaseFactory
|
||||||
$in_reply = [];
|
$in_reply = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$delivery_data = new FriendicaDeliveryData($item['delivery_queue_count'], $item['delivery_queue_done'], $item['delivery_queue_failed']);
|
$aclFormatter = DI::aclFormatter();
|
||||||
$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($aclFormatter->expand($item['allow_cid']), $aclFormatter->expand($item['deny_cid']), $aclFormatter->expand($item['allow_gid']), $aclFormatter->expand($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);
|
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 +361,7 @@ class Status extends BaseFactory
|
||||||
$attachments = [];
|
$attachments = [];
|
||||||
$in_reply = [];
|
$in_reply = [];
|
||||||
$reshare = [];
|
$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);
|
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) */
|
/** @var string|null (Datetime) */
|
||||||
protected $received_at;
|
protected $received_at;
|
||||||
|
|
||||||
/** @var FriendicaDeliveryData */
|
/** @var FriendicaDeliveryData|null */
|
||||||
protected $delivery_data;
|
protected $delivery_data;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $dislikes_count;
|
protected $dislikes_count;
|
||||||
|
/**
|
||||||
|
* @var FriendicaVisibility|null
|
||||||
|
*/
|
||||||
|
protected $visibility;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a status count object
|
* Creates a FriendicaExtension object
|
||||||
*
|
*
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @param string|null $changed_at
|
* @param string|null $changed_at
|
||||||
|
@ -60,7 +64,8 @@ class FriendicaExtension extends BaseDataTransferObject
|
||||||
* @param string|null $edited_at
|
* @param string|null $edited_at
|
||||||
* @param string|null $received_at
|
* @param string|null $received_at
|
||||||
* @param int $dislikes_count
|
* @param int $dislikes_count
|
||||||
* @param FriendicaDeliveryData $delivery_data
|
* @param FriendicaDeliveryData|null $delivery_data
|
||||||
|
* @param FriendicaVisibility|null $visibility
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $title,
|
string $title,
|
||||||
|
@ -68,7 +73,8 @@ class FriendicaExtension extends BaseDataTransferObject
|
||||||
?string $commented_at,
|
?string $commented_at,
|
||||||
?string $received_at,
|
?string $received_at,
|
||||||
int $dislikes_count,
|
int $dislikes_count,
|
||||||
FriendicaDeliveryData $delivery_data
|
?FriendicaDeliveryData $delivery_data,
|
||||||
|
?FriendicaVisibility $visibility
|
||||||
) {
|
) {
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
$this->changed_at = $changed_at ? DateTimeFormat::utc($changed_at, DateTimeFormat::JSON) : null;
|
$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->received_at = $received_at ? DateTimeFormat::utc($received_at, DateTimeFormat::JSON) : null;
|
||||||
$this->delivery_data = $delivery_data;
|
$this->delivery_data = $delivery_data;
|
||||||
$this->dislikes_count = $dislikes_count;
|
$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 array */
|
||||||
|
protected $allow_cid;
|
||||||
|
/** @var array */
|
||||||
|
protected $deny_cid;
|
||||||
|
/** @var array */
|
||||||
|
protected $allow_gid;
|
||||||
|
/** @var array */
|
||||||
|
protected $deny_gid;
|
||||||
|
|
||||||
|
public function __construct(array $allow_cid, array $deny_cid, array $allow_gid, array $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