correctly paginate on MastoAPI

This commit is contained in:
Henry Jameson 2019-03-25 21:04:52 +02:00
parent 50960c7cfc
commit 968e6c7fe8
3 changed files with 32 additions and 24 deletions

View file

@ -276,11 +276,15 @@ const fetchUserRelationship = ({id, credentials}) => {
})
}
const fetchFriends = ({id, page, credentials}) => {
const fetchFriends = ({id, maxId, sinceId, limit = 20, credentials}) => {
let url = MASTODON_FOLLOWING_URL(id)
if (page) {
url = url + `?page=${page}`
}
const args = [
maxId && `max_id=${maxId}`,
sinceId && `max_id=${sinceId}`,
limit && `limit=${limit}`
].filter(_ => _).join('&')
url = url + (args ? '?' + args : '')
return fetch(url, { headers: authHeaders(credentials) })
.then((data) => data.json())
.then((data) => data.map(parseUser))
@ -293,11 +297,15 @@ const exportFriends = ({id, credentials}) => {
.then((data) => data.map(parseUser))
}
const fetchFollowers = ({id, page, credentials}) => {
const fetchFollowers = ({id, maxId, sinceId, limit = 20, credentials}) => {
let url = MASTODON_FOLLOWERS_URL(id)
if (page) {
url = url + `?page=${page}`
}
const args = [
maxId && `max_id=${maxId}`,
sinceId && `max_id=${sinceId}`,
limit && `limit=${limit}`
].filter(_ => _).join('&')
url = url + (args ? '?' + args : '')
return fetch(url, { headers: authHeaders(credentials) })
.then((data) => data.json())
.then((data) => data.map(parseUser))

View file

@ -10,16 +10,16 @@ const backendInteractorService = (credentials) => {
return apiService.fetchConversation({id, credentials})
}
const fetchFriends = ({id, page}) => {
return apiService.fetchFriends({id, page, credentials})
const fetchFriends = ({id, maxId, sinceId, limit}) => {
return apiService.fetchFriends({id, maxId, sinceId, limit, credentials})
}
const exportFriends = ({id}) => {
return apiService.exportFriends({id, credentials})
}
const fetchFollowers = ({id, page}) => {
return apiService.fetchFollowers({id, page, credentials})
const fetchFollowers = ({id, maxId, sinceId, limit}) => {
return apiService.fetchFollowers({id, maxId, sinceId, limit, credentials})
}
const fetchAllFollowing = ({username}) => {