]> git.mxchange.org Git - friendica.git/commitdiff
API: Support for reshared items
authorMichael <heluecht@pirati.ca>
Sun, 1 Nov 2020 11:01:57 +0000 (11:01 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 1 Nov 2020 11:01:57 +0000 (11:01 +0000)
src/Factory/Api/Mastodon/Status.php
src/Module/Api/Mastodon/Accounts/Statuses.php
src/Object/Api/Mastodon/Status.php

index 5aac0f80c21a46deac744acb66f76c2987c8e745..cd468a5fbdf0525e6fe4606cd7d785b64ff608c1 100644 (file)
@@ -87,6 +87,15 @@ class Status extends BaseFactory
 
                $attachments = DI::mstdnAttachment()->createFromUriId($uriId);
 
-               return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts, $userAttributes, $sensitive, $application, $mentions, $tags, $card, $attachments);
+               if ($item['vid'] == Verb::getID(Activity::ANNOUNCE)) {
+                       $reshare = $this->createFromUriId($item['thr-parent-id'], $uid)->toArray();
+                       $reshared_item = Item::selectFirst(['title', 'body'], ['uri-id' => $item['thr-parent-id'], 'uid' => $uid]);
+                       $item['title'] = $reshared_item['title'] ?? $item['title'];
+                       $item['body'] = $reshared_item['body'] ?? $item['body'];
+               } else {
+                       $reshare = [];
+               }
+
+               return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts, $userAttributes, $sensitive, $application, $mentions, $tags, $card, $attachments, $reshare);
        }
 }
index 2959739a8cf6820eb28bf7e87c6bbe60954c35b3..9e29e5f24d5033e1a65b0b878e2e6d2909f13238 100644 (file)
@@ -26,7 +26,9 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Item;
+use Friendica\Model\Verb;
 use Friendica\Module\BaseApi;
+use Friendica\Protocol\Activity;
 
 /**
  * @see https://docs.joinmastodon.org/methods/accounts/
@@ -61,8 +63,11 @@ class Statuses extends BaseApi
 
                $params = ['order' => ['uri-id' => true], 'limit' => $limit];
 
-               $condition = ['author-id' => $id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
-                       'private' => Item::PUBLIC, 'uid' => 0, 'network' => Protocol::FEDERATED];
+               $condition = ['author-id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED],
+                       'uid' => 0, 'network' => Protocol::FEDERATED];
+
+               $condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))",
+                       GRAVITY_PARENT, GRAVITY_COMMENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]);
 
                if (!empty($max_id)) {
                        $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $max_id]);
index 1b09a4f01a8652755be78e4eb52540e99a0ab723..d14eb4efa31765abb98f327125ee98244aad25fc 100644 (file)
@@ -97,7 +97,7 @@ class Status extends BaseEntity
         * @param array   $item
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public function __construct(array $item, Account $account, Counts $counts, UserAttributes $userAttributes, bool $sensitive, Application $application, array $mentions, array $tags, Card $card, array $attachments)
+       public function __construct(array $item, Account $account, Counts $counts, UserAttributes $userAttributes, bool $sensitive, Application $application, array $mentions, array $tags, Card $card, array $attachments, array $reblog)
        {
                $this->id         = (string)$item['uri-id'];
                $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::ATOM);
@@ -127,7 +127,7 @@ class Status extends BaseEntity
                $this->bookmarked = $userAttributes->bookmarked;
                $this->pinned = $userAttributes->pinned;
                $this->content = BBCode::convert($item['raw-body'] ?? $item['body'], false);
-               $this->reblog = null; /// @todo
+               $this->reblog = $reblog;
                $this->application = $application->toArray();
                $this->account = $account->toArray();
                $this->media_attachments = $attachments;
@@ -155,6 +155,10 @@ class Status extends BaseEntity
                        unset($status['application']);
                }
 
+               if (empty($status['reblog'])) {
+                       $status['reblog'] = null;
+               }
+
                return $status;
        }
 }