From 3d76cd21e6af794edfe452460c985ec11d96b69e Mon Sep 17 00:00:00 2001 From: Justin Date: Sat, 14 May 2022 14:33:14 -0400 Subject: [PATCH] Skip API requests if logged out --- app/soapbox/actions/custom_emojis.js | 3 +++ app/soapbox/actions/suggestions.js | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/soapbox/actions/custom_emojis.js b/app/soapbox/actions/custom_emojis.js index 9ec8156b1..49e903f37 100644 --- a/app/soapbox/actions/custom_emojis.js +++ b/app/soapbox/actions/custom_emojis.js @@ -6,6 +6,9 @@ export const CUSTOM_EMOJIS_FETCH_FAIL = 'CUSTOM_EMOJIS_FETCH_FAIL'; export function fetchCustomEmojis() { return (dispatch, getState) => { + const me = getState().get('me'); + if (!me) return; + dispatch(fetchCustomEmojisRequest()); api(getState).get('/api/v1/custom_emojis').then(response => { diff --git a/app/soapbox/actions/suggestions.js b/app/soapbox/actions/suggestions.js index 0221b3a05..ede37ff30 100644 --- a/app/soapbox/actions/suggestions.js +++ b/app/soapbox/actions/suggestions.js @@ -8,13 +8,13 @@ import { importFetchedAccounts } from './importer'; export const SUGGESTIONS_FETCH_REQUEST = 'SUGGESTIONS_FETCH_REQUEST'; export const SUGGESTIONS_FETCH_SUCCESS = 'SUGGESTIONS_FETCH_SUCCESS'; -export const SUGGESTIONS_FETCH_FAIL = 'SUGGESTIONS_FETCH_FAIL'; +export const SUGGESTIONS_FETCH_FAIL = 'SUGGESTIONS_FETCH_FAIL'; export const SUGGESTIONS_DISMISS = 'SUGGESTIONS_DISMISS'; export const SUGGESTIONS_V2_FETCH_REQUEST = 'SUGGESTIONS_V2_FETCH_REQUEST'; export const SUGGESTIONS_V2_FETCH_SUCCESS = 'SUGGESTIONS_V2_FETCH_SUCCESS'; -export const SUGGESTIONS_V2_FETCH_FAIL = 'SUGGESTIONS_V2_FETCH_FAIL'; +export const SUGGESTIONS_V2_FETCH_FAIL = 'SUGGESTIONS_V2_FETCH_FAIL'; export function fetchSuggestionsV1(params = {}) { return (dispatch, getState) => { @@ -48,23 +48,26 @@ export function fetchSuggestionsV2(params = {}) { export function fetchSuggestions(params = { limit: 50 }) { return (dispatch, getState) => { const state = getState(); + const me = state.get('me'); const instance = state.get('instance'); const features = getFeatures(instance); + if (!me) return; + if (features.suggestionsV2) { dispatch(fetchSuggestionsV2(params)) .then(suggestions => { const accountIds = suggestions.map(({ account }) => account.id); dispatch(fetchRelationships(accountIds)); }) - .catch(() => {}); + .catch(() => { }); } else if (features.suggestions) { dispatch(fetchSuggestionsV1(params)) .then(accounts => { const accountIds = accounts.map(({ id }) => id); dispatch(fetchRelationships(accountIds)); }) - .catch(() => {}); + .catch(() => { }); } else { // Do nothing }