3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Factory\Api\Twitter;
24 use Friendica\BaseFactory;
25 use Friendica\Content\Text\BBCode;
26 use Friendica\Database\Database;
27 use Friendica\Factory\Api\Twitter\User as TwitterUser;
28 use Friendica\Model\Post;
29 use Friendica\Model\Verb;
30 use Friendica\Network\HTTPException;
31 use Friendica\Protocol\Activity;
33 use Psr\Log\LoggerInterface;
35 class Status extends BaseFactory
39 /** @var TwitterUser */
42 public function __construct(LoggerInterface $logger, Database $dba, TwitterUser $twitteruser)
44 parent::__construct($logger);
46 $this->twitterUser = $twitteruser;
50 * @param int $uriId Uri-ID of the item
51 * @param int $uid Item user
53 * @return \Friendica\Object\Api\Mastodon\Status
54 * @throws HTTPException\InternalServerErrorException
55 * @throws ImagickException|HTTPException\NotFoundException
57 public function createFromUriId(int $uriId, $uid = 0): \Friendica\Object\Api\Twitter\Status
59 $fields = ['id', 'parent', 'uri-id', 'uid', 'author-id', 'author-link', 'author-network', 'owner-id', 'starred', 'app', 'title', 'body', 'raw-body', 'created', 'network',
60 'thr-parent-id', 'parent-author-id', 'parent-author-nick', 'language', 'uri', 'plink', 'private', 'vid', 'gravity'];
61 $item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
63 throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
66 $author = $this->twitterUser->createFromContactId($item['author-id'], $item['uid']);
67 $owner = $this->twitterUser->createFromContactId($item['owner-id'], $item['uid']);
69 $friendica_comments = Post::countPosts(['thr-parent-id' => $item['uri-id'], 'deleted' => false, 'gravity' => GRAVITY_COMMENT]);
73 //$mentions = $this->mstdnMentionFactory->createFromUriId($uriId)->getArrayCopy();
74 //$tags = $this->mstdnTagFactory->createFromUriId($uriId);
75 //$attachments = $this->mstdnAttachementFactory->createFromUriId($uriId);
78 $friendica_activities = [];
80 $shared = BBCode::fetchShareAttributes($item['body']);
81 if (!empty($shared['guid'])) {
82 //$shared_item = Post::selectFirst(['uri-id', 'plink'], ['guid' => $shared['guid']]);
84 //$shared_uri_id = $shared_item['uri-id'] ?? 0;
86 //$mentions = array_merge($mentions, $this->mstdnMentionFactory->createFromUriId($shared_uri_id)->getArrayCopy());
87 //$tags = array_merge($tags, $this->mstdnTagFactory->createFromUriId($shared_uri_id));
88 //$attachments = array_merge($attachments, $this->mstdnAttachementFactory->createFromUriId($shared_uri_id));
91 $friendica_activities = [];
94 if ($item['vid'] == Verb::getID(Activity::ANNOUNCE)) {
95 $retweeted = $this->createFromUriId($item['thr-parent-id'], $uid)->toArray();
96 $retweeted_item = Post::selectFirst(['title', 'body', 'author-id'], ['uri-id' => $item['thr-parent-id'],'uid' => [0, $uid]]);
97 $item['title'] = $retweeted_item['title'] ?? $item['title'];
98 $item['body'] = $retweeted_item['body'] ?? $item['body'];
99 $author = $this->twitterUser->createFromContactId($retweeted_item['author-id'], $item['uid']);
106 return new \Friendica\Object\Api\Twitter\Status($item, $author, $owner, $retweeted, $quoted, $attachments, $geo, $friendica_activities, $entities, $friendica_comments);