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