diff --git a/app/soapbox/actions/blocks.js b/app/soapbox/actions/blocks.js index 5c351b674..9896495ff 100644 --- a/app/soapbox/actions/blocks.js +++ b/app/soapbox/actions/blocks.js @@ -2,6 +2,7 @@ import api, { getLinks } from '../api'; import { fetchRelationships } from './accounts'; import { importFetchedAccounts } from './importer'; import { isLoggedIn } from 'soapbox/utils/auth'; +import { getNextLinkName } from 'soapbox/utils/quirks'; export const BLOCKS_FETCH_REQUEST = 'BLOCKS_FETCH_REQUEST'; export const BLOCKS_FETCH_SUCCESS = 'BLOCKS_FETCH_SUCCESS'; @@ -14,11 +15,12 @@ export const BLOCKS_EXPAND_FAIL = 'BLOCKS_EXPAND_FAIL'; export function fetchBlocks() { return (dispatch, getState) => { if (!isLoggedIn(getState)) return; + const nextLinkName = getNextLinkName(getState); dispatch(fetchBlocksRequest()); api(getState).get('/api/v1/blocks').then(response => { - const next = getLinks(response).refs.find(link => link.rel === 'next'); + const next = getLinks(response).refs.find(link => link.rel === nextLinkName); dispatch(importFetchedAccounts(response.data)); dispatch(fetchBlocksSuccess(response.data, next ? next.uri : null)); dispatch(fetchRelationships(response.data.map(item => item.id))); @@ -50,6 +52,7 @@ export function fetchBlocksFail(error) { export function expandBlocks() { return (dispatch, getState) => { if (!isLoggedIn(getState)) return; + const nextLinkName = getNextLinkName(getState); const url = getState().getIn(['user_lists', 'blocks', 'next']); @@ -60,7 +63,7 @@ export function expandBlocks() { dispatch(expandBlocksRequest()); api(getState).get(url).then(response => { - const next = getLinks(response).refs.find(link => link.rel === 'next'); + const next = getLinks(response).refs.find(link => link.rel === nextLinkName); dispatch(importFetchedAccounts(response.data)); dispatch(expandBlocksSuccess(response.data, next ? next.uri : null)); dispatch(fetchRelationships(response.data.map(item => item.id))); diff --git a/app/soapbox/actions/mutes.js b/app/soapbox/actions/mutes.js index 7ad66a3c0..7b9ef58c4 100644 --- a/app/soapbox/actions/mutes.js +++ b/app/soapbox/actions/mutes.js @@ -3,6 +3,7 @@ import { fetchRelationships } from './accounts'; import { importFetchedAccounts } from './importer'; import { openModal } from './modal'; import { isLoggedIn } from 'soapbox/utils/auth'; +import { getNextLinkName } from 'soapbox/utils/quirks'; export const MUTES_FETCH_REQUEST = 'MUTES_FETCH_REQUEST'; export const MUTES_FETCH_SUCCESS = 'MUTES_FETCH_SUCCESS'; @@ -18,11 +19,12 @@ export const MUTES_TOGGLE_HIDE_NOTIFICATIONS = 'MUTES_TOGGLE_HIDE_NOTIFICATIONS' export function fetchMutes() { return (dispatch, getState) => { if (!isLoggedIn(getState)) return; + const nextLinkName = getNextLinkName(getState); dispatch(fetchMutesRequest()); api(getState).get('/api/v1/mutes').then(response => { - const next = getLinks(response).refs.find(link => link.rel === 'next'); + const next = getLinks(response).refs.find(link => link.rel === nextLinkName); dispatch(importFetchedAccounts(response.data)); dispatch(fetchMutesSuccess(response.data, next ? next.uri : null)); dispatch(fetchRelationships(response.data.map(item => item.id))); @@ -54,6 +56,7 @@ export function fetchMutesFail(error) { export function expandMutes() { return (dispatch, getState) => { if (!isLoggedIn(getState)) return; + const nextLinkName = getNextLinkName(getState); const url = getState().getIn(['user_lists', 'mutes', 'next']); @@ -64,7 +67,7 @@ export function expandMutes() { dispatch(expandMutesRequest()); api(getState).get(url).then(response => { - const next = getLinks(response).refs.find(link => link.rel === 'next'); + const next = getLinks(response).refs.find(link => link.rel === nextLinkName); dispatch(importFetchedAccounts(response.data)); dispatch(expandMutesSuccess(response.data, next ? next.uri : null)); dispatch(fetchRelationships(response.data.map(item => item.id))); diff --git a/app/soapbox/utils/quirks.js b/app/soapbox/utils/quirks.js new file mode 100644 index 000000000..764b10e26 --- /dev/null +++ b/app/soapbox/utils/quirks.js @@ -0,0 +1,12 @@ +import { parseVersion } from './features'; + +// For solving bugs between API implementations +export const getQuirks = instance => { + const v = parseVersion(instance.get('version')); + return { + invertedPagination: v.software === 'Pleroma', + }; +}; + +export const getNextLinkName = getState => + getQuirks(getState().get('instance')).invertedPagination ? 'prev' : 'next';