Added last status
This commit is contained in:
parent
2c7c63a493
commit
ab28fa32aa
|
@ -1088,20 +1088,7 @@ function api_users_show($type)
|
|||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$user_info = DI::twitterUser()->createFromUserId($uid)->toArray();
|
||||
|
||||
$condition = [
|
||||
'author-id'=> $user_info['pid'],
|
||||
'uid' => $uid,
|
||||
'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
|
||||
'private' => [Item::PUBLIC, Item::UNLISTED]
|
||||
];
|
||||
|
||||
$item = Post::selectFirst(['uri-id', 'id'], $condition);
|
||||
if (!empty($item)) {
|
||||
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
|
||||
$user_info['status'] = DI::twitterStatus()->createFromUriId($item['uri-id'], $item['uid'], $include_entities)->toArray();
|
||||
}
|
||||
$user_info = DI::twitterUser()->createFromUserId($uid, false)->toArray();
|
||||
|
||||
// "uid" is only needed for some internal stuff, so remove it from here
|
||||
unset($user_info['uid']);
|
||||
|
@ -1146,7 +1133,7 @@ function api_users_search($type)
|
|||
if (DBA::isResult($contacts)) {
|
||||
$k = 0;
|
||||
foreach ($contacts as $contact) {
|
||||
$user_info = DI::twitterUser()->createFromContactId($contact['id'], $uid)->toArray();
|
||||
$user_info = DI::twitterUser()->createFromContactId($contact['id'], $uid, false)->toArray();
|
||||
|
||||
if ($type == 'xml') {
|
||||
$userlist[$k++ . ':user'] = $user_info;
|
||||
|
@ -1191,7 +1178,7 @@ function api_users_lookup($type)
|
|||
if (!empty($_REQUEST['user_id'])) {
|
||||
foreach (explode(',', $_REQUEST['user_id']) as $cid) {
|
||||
if (!empty($cid) && is_numeric($cid)) {
|
||||
$users[] = DI::twitterUser()->createFromContactId((int)$cid, $uid)->toArray();
|
||||
$users[] = DI::twitterUser()->createFromContactId((int)$cid, $uid, false)->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2088,7 +2075,7 @@ function api_lists_ownerships($type)
|
|||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// params
|
||||
$user_info = DI::twitterUser()->createFromUserId($uid)->toArray();
|
||||
$user_info = DI::twitterUser()->createFromUserId($uid, true)->toArray();
|
||||
|
||||
$groups = DBA::select('group', [], ['deleted' => 0, 'uid' => $uid]);
|
||||
|
||||
|
@ -2253,7 +2240,7 @@ function api_statuses_f($qtype)
|
|||
|
||||
$ret = [];
|
||||
foreach ($r as $cid) {
|
||||
$user = DI::twitterUser()->createFromContactId($cid['id'], $uid)->toArray();
|
||||
$user = DI::twitterUser()->createFromContactId($cid['id'], $uid, false)->toArray();
|
||||
// "uid" is only needed for some internal stuff, so remove it from here
|
||||
unset($user['uid']);
|
||||
|
||||
|
@ -2380,7 +2367,7 @@ function api_direct_messages_new($type)
|
|||
return;
|
||||
}
|
||||
|
||||
$sender = DI::twitterUser()->createFromUserId($uid)->toArray();
|
||||
$sender = DI::twitterUser()->createFromUserId($uid, true)->toArray();
|
||||
|
||||
$cid = BaseApi::getContactIDForSearchterm($_POST['screen_name'] ?? '', $_POST['user_id'] ?? 0, $uid);
|
||||
if (empty($cid)) {
|
||||
|
@ -2406,7 +2393,7 @@ function api_direct_messages_new($type)
|
|||
|
||||
if ($id > -1) {
|
||||
$mail = DBA::selectFirst('mail', [], ['id' => $id]);
|
||||
$ret = api_format_messages($mail, DI::twitterUser()->createFromContactId($cid, $uid)->toArray(), $sender);
|
||||
$ret = api_format_messages($mail, DI::twitterUser()->createFromContactId($cid, $uid, true)->toArray(), $sender);
|
||||
} else {
|
||||
$ret = ["error" => $id];
|
||||
}
|
||||
|
@ -2594,7 +2581,7 @@ function api_direct_messages_box($type, $box, $verbose)
|
|||
unset($_REQUEST['screen_name']);
|
||||
unset($_GET['screen_name']);
|
||||
|
||||
$user_info = DI::twitterUser()->createFromUserId($uid)->toArray();
|
||||
$user_info = DI::twitterUser()->createFromUserId($uid, true)->toArray();
|
||||
|
||||
$profile_url = $user_info["url"];
|
||||
|
||||
|
@ -2640,9 +2627,9 @@ function api_direct_messages_box($type, $box, $verbose)
|
|||
foreach ($r as $item) {
|
||||
if ($box == "inbox" || $item['from-url'] != $profile_url) {
|
||||
$recipient = $user_info;
|
||||
$sender = DI::twitterUser()->createFromContactId($item['contact-id'], $uid)->toArray();
|
||||
$sender = DI::twitterUser()->createFromContactId($item['contact-id'], $uid, true)->toArray();
|
||||
} elseif ($box == "sentbox" || $item['from-url'] == $profile_url) {
|
||||
$recipient = DI::twitterUser()->createFromContactId($item['contact-id'], $uid)->toArray();
|
||||
$recipient = DI::twitterUser()->createFromContactId($item['contact-id'], $uid, true)->toArray();
|
||||
$sender = $user_info;
|
||||
}
|
||||
|
||||
|
@ -3049,7 +3036,7 @@ function api_account_update_profile($type)
|
|||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$api_user = DI::twitterUser()->createFromUserId($uid)->toArray();
|
||||
$api_user = DI::twitterUser()->createFromUserId($uid, true)->toArray();
|
||||
|
||||
if (!empty($_POST['name'])) {
|
||||
DBA::update('profile', ['name' => $_POST['name']], ['uid' => $uid]);
|
||||
|
@ -3113,13 +3100,13 @@ function api_friendica_group_show($type)
|
|||
$user_element = "users";
|
||||
$k = 0;
|
||||
foreach ($members as $member) {
|
||||
$user = DI::twitterUser()->createFromContactId($member['contact-id'], $uid)->toArray();
|
||||
$user = DI::twitterUser()->createFromContactId($member['contact-id'], $uid, true)->toArray();
|
||||
$users[$k++.":user"] = $user;
|
||||
}
|
||||
} else {
|
||||
$user_element = "user";
|
||||
foreach ($members as $member) {
|
||||
$user = DI::twitterUser()->createFromContactId($member['contact-id'], $uid)->toArray();
|
||||
$user = DI::twitterUser()->createFromContactId($member['contact-id'], $uid, true)->toArray();
|
||||
$users[] = $user;
|
||||
}
|
||||
}
|
||||
|
@ -3168,7 +3155,7 @@ function api_lists_destroy($type)
|
|||
'name' => $group['name'],
|
||||
'id' => intval($gid),
|
||||
'id_str' => (string) $gid,
|
||||
'user' => DI::twitterUser()->createFromUserId($uid)->toArray()
|
||||
'user' => DI::twitterUser()->createFromUserId($uid, true)->toArray()
|
||||
];
|
||||
|
||||
return DI::apiResponse()->formatData("lists", $type, ['lists' => $list]);
|
||||
|
@ -3233,7 +3220,7 @@ function api_lists_create($type)
|
|||
'name' => $success['name'],
|
||||
'id' => intval($success['gid']),
|
||||
'id_str' => (string) $success['gid'],
|
||||
'user' => DI::twitterUser()->createFromUserId($uid)->toArray()
|
||||
'user' => DI::twitterUser()->createFromUserId($uid, true)->toArray()
|
||||
];
|
||||
|
||||
return DI::apiResponse()->formatData("lists", $type, ['lists' => $grp]);
|
||||
|
@ -3349,7 +3336,7 @@ function api_lists_update($type)
|
|||
'name' => $name,
|
||||
'id' => intval($gid),
|
||||
'id_str' => (string) $gid,
|
||||
'user' => DI::twitterUser()->createFromUserId($uid)->toArray()
|
||||
'user' => DI::twitterUser()->createFromUserId($uid, true)->toArray()
|
||||
];
|
||||
|
||||
return DI::apiResponse()->formatData("lists", $type, ['lists' => $list]);
|
||||
|
@ -3438,7 +3425,7 @@ function api_friendica_direct_messages_search($type, $box = "")
|
|||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
// params
|
||||
$user_info = DI::twitterUser()->createFromUserId($uid)->toArray();
|
||||
$user_info = DI::twitterUser()->createFromUserId($uid, true)->toArray();
|
||||
$searchstring = $_REQUEST['searchstring'] ?? '';
|
||||
|
||||
// error if no searchstring specified
|
||||
|
@ -3466,9 +3453,9 @@ function api_friendica_direct_messages_search($type, $box = "")
|
|||
foreach ($r as $item) {
|
||||
if ($box == "inbox" || $item['from-url'] != $profile_url) {
|
||||
$recipient = $user_info;
|
||||
$sender = DI::twitterUser()->createFromContactId($item['contact-id'], $uid)->toArray();
|
||||
$sender = DI::twitterUser()->createFromContactId($item['contact-id'], $uid, true)->toArray();
|
||||
} elseif ($box == "sentbox" || $item['from-url'] == $profile_url) {
|
||||
$recipient = DI::twitterUser()->createFromContactId($item['contact-id'], $uid)->toArray();
|
||||
$recipient = DI::twitterUser()->createFromContactId($item['contact-id'], $uid, true)->toArray();
|
||||
$sender = $user_info;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ class Activities extends BaseFactory
|
|||
|
||||
while ($parent_item = Post::fetch($ret)) {
|
||||
// get user data and add it to the array of the activity
|
||||
$user = $this->twitterUser->createFromContactId($parent_item['author-id'], $uid)->toArray();
|
||||
$user = $this->twitterUser->createFromContactId($parent_item['author-id'], $uid, true)->toArray();
|
||||
switch ($parent_item['verb']) {
|
||||
case Activity::LIKE:
|
||||
$activities['like'][] = $user;
|
||||
|
|
|
@ -114,8 +114,8 @@ class Status extends BaseFactory
|
|||
*/
|
||||
private function createFromArray(array $item, $include_entities): \Friendica\Object\Api\Twitter\Status
|
||||
{
|
||||
$author = $this->twitterUser->createFromContactId($item['author-id'], $item['uid']);
|
||||
$owner = $this->twitterUser->createFromContactId($item['owner-id'], $item['uid']);
|
||||
$author = $this->twitterUser->createFromContactId($item['author-id'], $item['uid'], true);
|
||||
$owner = $this->twitterUser->createFromContactId($item['owner-id'], $item['uid'], true);
|
||||
|
||||
$friendica_comments = Post::countPosts(['thr-parent-id' => $item['uri-id'], 'deleted' => false, 'gravity' => GRAVITY_COMMENT]);
|
||||
|
||||
|
@ -169,7 +169,7 @@ class Status extends BaseFactory
|
|||
$retweeted_item = Post::selectFirst(['title', 'body', 'author-id'], ['uri-id' => $item['thr-parent-id'],'uid' => [0, $item['uid']]]);
|
||||
$item['title'] = $retweeted_item['title'] ?? $item['title'];
|
||||
$item['body'] = $retweeted_item['body'] ?? $item['body'];
|
||||
$author = $this->twitterUser->createFromContactId($retweeted_item['author-id'], $item['uid']);
|
||||
$author = $this->twitterUser->createFromContactId($retweeted_item['author-id'], $item['uid'], true);
|
||||
} else {
|
||||
$retweeted = [];
|
||||
}
|
||||
|
|
|
@ -25,9 +25,23 @@ use Friendica\BaseFactory;
|
|||
use Friendica\Model\APContact;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Factory\Api\Twitter\Status;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Post;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class User extends BaseFactory
|
||||
{
|
||||
/** @var Status entity */
|
||||
private $status;
|
||||
|
||||
public function __construct(LoggerInterface $logger, Status $status)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
$this->status = $status;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $contactId
|
||||
* @param int $uid Public contact (=0) or owner user id
|
||||
|
@ -37,7 +51,7 @@ class User extends BaseFactory
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public function createFromContactId(int $contactId, $uid = 0, $skip_status = false, $include_user_entities = true)
|
||||
public function createFromContactId(int $contactId, $uid = 0, $skip_status = true, $include_user_entities = true)
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContactID($contactId, $uid);
|
||||
if (!empty($cdata)) {
|
||||
|
@ -50,12 +64,21 @@ class User extends BaseFactory
|
|||
|
||||
$apcontact = APContact::getByURL($publicContact['url'], false);
|
||||
|
||||
$status = null; // @todo fetch last status
|
||||
$status = null;
|
||||
|
||||
if (!$skip_status) {
|
||||
$post = Post::selectFirstPost(['uri-id'],
|
||||
['author-id' => $publicContact['id'], 'gravity' => [GRAVITY_COMMENT, GRAVITY_PARENT], 'private' => [Item::PUBLIC, Item::UNLISTED]],
|
||||
['order' => ['uri-id' => true]]);
|
||||
if (!empty($post['uri-id'])) {
|
||||
$status = $this->status->createFromUriId($post['uri-id'], $uid)->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
return new \Friendica\Object\Api\Twitter\User($publicContact, $apcontact, $userContact, $status, $include_user_entities);
|
||||
}
|
||||
|
||||
public function createFromUserId(int $uid, $skip_status = false, $include_user_entities = true)
|
||||
public function createFromUserId(int $uid, $skip_status = true, $include_user_entities = true)
|
||||
{
|
||||
return $this->createFromContactId(Contact::getPublicIdByUserId($uid), $uid, $skip_status, $include_user_entities);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue