3 * @copyright Copyright (C) 2010-2023, 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\Model\APContact;
26 use Friendica\Model\Contact;
27 use Friendica\Network\HTTPException;
28 use Friendica\Factory\Api\Twitter\Status;
29 use Friendica\Model\Item;
30 use Friendica\Model\Post;
31 use Psr\Log\LoggerInterface;
33 class User extends BaseFactory
35 /** @var Status entity */
38 public function __construct(LoggerInterface $logger, Status $status)
40 parent::__construct($logger);
41 $this->status = $status;
46 * @param int $contactId
47 * @param int $uid Public contact (=0) or owner user id
48 * @param bool $skip_status
49 * @param bool $include_user_entities
51 * @return \Friendica\Object\Api\Twitter\User
52 * @throws HTTPException\InternalServerErrorException
53 * @throws \ImagickException
55 public function createFromContactId(int $contactId, int $uid = 0, bool $skip_status = true, bool $include_user_entities = true): \Friendica\Object\Api\Twitter\User
57 $cdata = Contact::getPublicAndUserContactID($contactId, $uid);
59 $publicContact = Contact::getById($cdata['public']);
60 $userContact = Contact::getById($cdata['user']);
62 $publicContact = Contact::getById($contactId);
66 $apcontact = APContact::getByURL($publicContact['url'], false);
71 $post = Post::selectFirstPost(['uri-id'],
72 ['author-id' => $publicContact['id'], 'gravity' => [Item::GRAVITY_COMMENT, Item::GRAVITY_PARENT], 'private' => [Item::PUBLIC, Item::UNLISTED]],
73 ['order' => ['uri-id' => true]]);
74 if (!empty($post['uri-id'])) {
75 $status = $this->status->createFromUriId($post['uri-id'], $uid)->toArray();
79 return new \Friendica\Object\Api\Twitter\User($publicContact, $apcontact, $userContact, $status, $include_user_entities);
83 * @param int $uid Public contact (=0) or owner user id
84 * @param bool $skip_status
85 * @param bool $include_user_entities
87 * @return \Friendica\Object\Api\Twitter\User
89 public function createFromUserId(int $uid, bool $skip_status = true, bool $include_user_entities = true): \Friendica\Object\Api\Twitter\User
91 return $this->createFromContactId(Contact::getPublicIdByUserId($uid), $uid, $skip_status, $include_user_entities);