mirror of
https://github.com/friendica/friendica
synced 2025-04-21 23:10:11 +00:00
Add support for max_id parameter in new Twitter contact API endpoints
- Use filter_input instead of manual type casting
This commit is contained in:
parent
7a5afc10bb
commit
8111ede2e5
6 changed files with 112 additions and 50 deletions
|
@ -114,8 +114,6 @@ abstract class ContactEndpoint extends BaseApi
|
|||
'total_count' => $return['total_count'],
|
||||
];
|
||||
|
||||
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
@ -140,28 +138,33 @@ abstract class ContactEndpoint extends BaseApi
|
|||
$hide_friends = (bool)$profile['hide-friends'];
|
||||
}
|
||||
|
||||
$condition = DBA::collapseCondition([
|
||||
'rel' => $rel,
|
||||
'uid' => $uid,
|
||||
'self' => false,
|
||||
'deleted' => false,
|
||||
'hidden' => false,
|
||||
'archive' => false,
|
||||
'pending' => false
|
||||
]);
|
||||
|
||||
if ($cursor !== -1) {
|
||||
$condition[0] .= " AND `id` > ?";
|
||||
$condition[] = $cursor;
|
||||
}
|
||||
|
||||
$ids = [];
|
||||
$next_cursor = 0;
|
||||
$previous_cursor = 0;
|
||||
$total_count = 0;
|
||||
if (!$hide_friends) {
|
||||
$condition = DBA::collapseCondition([
|
||||
'rel' => $rel,
|
||||
'uid' => $uid,
|
||||
'self' => false,
|
||||
'deleted' => false,
|
||||
'hidden' => false,
|
||||
'archive' => false,
|
||||
'pending' => false
|
||||
]);
|
||||
|
||||
$total_count = DBA::count('contact', $condition);
|
||||
|
||||
if ($cursor !== -1) {
|
||||
if ($cursor > 0) {
|
||||
$condition[0] .= " AND `id` > ?";
|
||||
$condition[] = $cursor;
|
||||
} else {
|
||||
$condition[0] .= " AND `id` < ?";
|
||||
$condition[] = -$cursor;
|
||||
}
|
||||
}
|
||||
|
||||
$contacts = Contact::selectToArray(['id'], $condition, ['limit' => $count, 'order' => ['id']]);
|
||||
|
||||
// Contains user-specific contact ids
|
||||
|
@ -169,9 +172,32 @@ abstract class ContactEndpoint extends BaseApi
|
|||
|
||||
// Cursor is on the user-specific contact id since it's the sort field
|
||||
if (count($ids)) {
|
||||
$previous_cursor = -$ids[0];
|
||||
$next_cursor = $ids[count($ids) -1];
|
||||
}
|
||||
|
||||
// No next page
|
||||
if ($total_count <= count($contacts) || count($contacts) < $count) {
|
||||
$next_cursor = 0;
|
||||
}
|
||||
// End of results
|
||||
if ($cursor < 0 && count($contacts) === 0) {
|
||||
$next_cursor = -1;
|
||||
}
|
||||
|
||||
// No previous page
|
||||
if ($cursor === -1) {
|
||||
$previous_cursor = 0;
|
||||
}
|
||||
|
||||
if ($cursor > 0 && count($contacts) === 0) {
|
||||
$previous_cursor = -$cursor;
|
||||
}
|
||||
|
||||
if ($cursor < 0 && count($contacts) === 0) {
|
||||
$next_cursor = -1;
|
||||
}
|
||||
|
||||
// Conversion to public contact ids
|
||||
array_walk($ids, function (&$contactId) use ($uid, $stringify_ids) {
|
||||
$cdata = Contact::getPublicAndUserContacID($contactId, $uid);
|
||||
|
@ -181,11 +207,6 @@ abstract class ContactEndpoint extends BaseApi
|
|||
$contactId = (int)$cdata['public'];
|
||||
}
|
||||
});
|
||||
|
||||
// No next page
|
||||
if ($total_count <= count($contacts)) {
|
||||
$next_cursor = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$return = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue