mirror of
https://github.com/friendica/friendica
synced 2025-04-26 18:30:11 +00:00
Implement friendships/incoming and users/lookup APIs
This commit is contained in:
parent
7a6706b0f7
commit
e11190b4cf
2 changed files with 73 additions and 6 deletions
|
@ -1485,6 +1485,31 @@ function api_users_search($type)
|
|||
/// @TODO move to top of file or somewhere better
|
||||
api_register_func('api/users/search', 'api_users_search');
|
||||
|
||||
/**
|
||||
* Return user objects
|
||||
*
|
||||
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-lookup
|
||||
*
|
||||
* @param string $type Return format: json or xml
|
||||
*
|
||||
* @return array|string
|
||||
* @throws UnauthorizedException
|
||||
*/
|
||||
function api_users_lookup($type)
|
||||
{
|
||||
$users = array();
|
||||
foreach (explode(',', $_REQUEST['user_id']) as $id) {
|
||||
if (!empty($id)) {
|
||||
$users[] = api_get_user(get_app(), $id);
|
||||
}
|
||||
}
|
||||
|
||||
return api_format_data("users", $type, array('users' => $users));
|
||||
}
|
||||
|
||||
/// @TODO move to top of file or somewhere better
|
||||
api_register_func('api/users/lookup', 'api_users_lookup', true);
|
||||
|
||||
/**
|
||||
* Returns statuses that match a specified query.
|
||||
*
|
||||
|
@ -3115,9 +3140,11 @@ function api_statuses_f($qtype)
|
|||
}
|
||||
|
||||
if ($qtype == 'blocks') {
|
||||
$sql_blocked = 'AND `blocked`';
|
||||
$sql_filter = 'AND `blocked` AND NOT `pending`';
|
||||
} elseif ($qtype == 'incoming') {
|
||||
$sql_filter = 'AND `pending`';
|
||||
} else {
|
||||
$sql_blocked = 'AND NOT `blocked`';
|
||||
$sql_filter = 'AND (NOT `blocked` OR `pending`)';
|
||||
}
|
||||
|
||||
$r = q(
|
||||
|
@ -3125,8 +3152,7 @@ function api_statuses_f($qtype)
|
|||
FROM `contact`
|
||||
WHERE `uid` = %d
|
||||
AND NOT `self`
|
||||
$sql_blocked
|
||||
AND NOT `pending`
|
||||
$sql_filter
|
||||
$sql_extra
|
||||
ORDER BY `nick`
|
||||
LIMIT %d, %d",
|
||||
|
@ -3211,6 +3237,34 @@ function api_blocks_list($type)
|
|||
/// @TODO move to top of file or somewhere better
|
||||
api_register_func('api/blocks/list', 'api_blocks_list', true);
|
||||
|
||||
/**
|
||||
* Returns the list of pending users IDs
|
||||
*
|
||||
* @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friendships-incoming
|
||||
*
|
||||
* @param string $type Either "json" or "xml"
|
||||
*
|
||||
* @return boolean|string|array
|
||||
* @throws UnauthorizedException
|
||||
*/
|
||||
function api_friendships_incoming($type)
|
||||
{
|
||||
$data = api_statuses_f('incoming');
|
||||
if ($data === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$ids = array();
|
||||
foreach ($data['user'] as $user) {
|
||||
$ids[] = $user['id'];
|
||||
}
|
||||
|
||||
return api_format_data("ids", $type, array('id' => $ids));
|
||||
}
|
||||
|
||||
/// @TODO move to top of file or somewhere better
|
||||
api_register_func('api/friendships/incoming', 'api_friendships_incoming', true);
|
||||
|
||||
function api_statusnet_config($type)
|
||||
{
|
||||
$a = get_app();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue