diff --git a/.eslintrc.js b/.eslintrc.js index 27134414f..c12341232 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -223,6 +223,23 @@ module.exports = { ], 'import/no-unresolved': 'error', 'import/no-webpack-loader-syntax': 'error', + 'import/order': [ + 'error', + { + groups: [ + 'builtin', + 'external', + 'internal', + 'parent', + 'sibling', + 'index', + 'object', + 'type', + ], + 'newlines-between': 'always', + alphabetize: { order: 'asc' }, + }, + ], 'promise/catch-or-return': 'error', diff --git a/app/soapbox/actions/__tests__/about-test.js b/app/soapbox/actions/__tests__/about-test.js index f6ce02099..49840e357 100644 --- a/app/soapbox/actions/__tests__/about-test.js +++ b/app/soapbox/actions/__tests__/about-test.js @@ -1,13 +1,15 @@ +import MockAdapter from 'axios-mock-adapter'; +import { Map as ImmutableMap } from 'immutable'; + +import { staticClient } from 'soapbox/api'; +import { mockStore } from 'soapbox/test_helpers'; + import { FETCH_ABOUT_PAGE_REQUEST, FETCH_ABOUT_PAGE_SUCCESS, FETCH_ABOUT_PAGE_FAIL, fetchAboutPage, } from '../about'; -import { Map as ImmutableMap } from 'immutable'; -import MockAdapter from 'axios-mock-adapter'; -import { staticClient } from 'soapbox/api'; -import { mockStore } from 'soapbox/test_helpers'; describe('fetchAboutPage()', () => { it('creates the expected actions on success', () => { diff --git a/app/soapbox/actions/__tests__/preload-test.js b/app/soapbox/actions/__tests__/preload-test.js index bf0dc83a5..5290802d2 100644 --- a/app/soapbox/actions/__tests__/preload-test.js +++ b/app/soapbox/actions/__tests__/preload-test.js @@ -1,12 +1,14 @@ +import { Map as ImmutableMap } from 'immutable'; + +import { __stub } from 'soapbox/api'; +import { mockStore } from 'soapbox/test_helpers'; + +import { VERIFY_CREDENTIALS_REQUEST } from '../auth'; +import { ACCOUNTS_IMPORT } from '../importer'; import { MASTODON_PRELOAD_IMPORT, preloadMastodon, } from '../preload'; -import { VERIFY_CREDENTIALS_REQUEST } from '../auth'; -import { ACCOUNTS_IMPORT } from '../importer'; -import { Map as ImmutableMap } from 'immutable'; -import { __stub } from 'soapbox/api'; -import { mockStore } from 'soapbox/test_helpers'; describe('preloadMastodon()', () => { it('creates the expected actions', () => { diff --git a/app/soapbox/actions/accounts.js b/app/soapbox/actions/accounts.js index de0751342..aacdcd106 100644 --- a/app/soapbox/actions/accounts.js +++ b/app/soapbox/actions/accounts.js @@ -1,11 +1,13 @@ +import { isLoggedIn } from 'soapbox/utils/auth'; +import { getFeatures } from 'soapbox/utils/features'; + import api, { getLinks } from '../api'; + import { importFetchedAccount, importFetchedAccounts, importErrorWhileFetchingAccountByUsername, } from './importer'; -import { isLoggedIn } from 'soapbox/utils/auth'; -import { getFeatures } from 'soapbox/utils/features'; export const ACCOUNT_CREATE_REQUEST = 'ACCOUNT_CREATE_REQUEST'; export const ACCOUNT_CREATE_SUCCESS = 'ACCOUNT_CREATE_SUCCESS'; diff --git a/app/soapbox/actions/admin.js b/app/soapbox/actions/admin.js index 8e3de078e..414cb07d6 100644 --- a/app/soapbox/actions/admin.js +++ b/app/soapbox/actions/admin.js @@ -1,6 +1,7 @@ -import api from '../api'; -import { importFetchedAccount, importFetchedStatuses } from 'soapbox/actions/importer'; import { fetchRelationships } from 'soapbox/actions/accounts'; +import { importFetchedAccount, importFetchedStatuses } from 'soapbox/actions/importer'; + +import api from '../api'; export const ADMIN_CONFIG_FETCH_REQUEST = 'ADMIN_CONFIG_FETCH_REQUEST'; export const ADMIN_CONFIG_FETCH_SUCCESS = 'ADMIN_CONFIG_FETCH_SUCCESS'; diff --git a/app/soapbox/actions/aliases.js b/app/soapbox/actions/aliases.js index 7f2dc6b00..cdeb7208c 100644 --- a/app/soapbox/actions/aliases.js +++ b/app/soapbox/actions/aliases.js @@ -1,10 +1,13 @@ import { defineMessages } from 'react-intl'; -import api from '../api'; -import { importFetchedAccount, importFetchedAccounts } from './importer'; -import { showAlertForError } from './alerts'; -import snackbar from './snackbar'; + import { isLoggedIn } from 'soapbox/utils/auth'; + +import api from '../api'; + +import { showAlertForError } from './alerts'; +import { importFetchedAccount, importFetchedAccounts } from './importer'; import { ME_PATCH_SUCCESS } from './me'; +import snackbar from './snackbar'; export const ALIASES_SUGGESTIONS_CHANGE = 'ALIASES_SUGGESTIONS_CHANGE'; export const ALIASES_SUGGESTIONS_READY = 'ALIASES_SUGGESTIONS_READY'; diff --git a/app/soapbox/actions/auth.js b/app/soapbox/actions/auth.js index eafb23212..5274a98cf 100644 --- a/app/soapbox/actions/auth.js +++ b/app/soapbox/actions/auth.js @@ -8,18 +8,21 @@ */ import { defineMessages } from 'react-intl'; -import api, { baseClient } from '../api'; -import { importFetchedAccount } from './importer'; -import snackbar from 'soapbox/actions/snackbar'; + import { createAccount } from 'soapbox/actions/accounts'; -import { fetchMeSuccess, fetchMeFail } from 'soapbox/actions/me'; -import { getLoggedInAccount, parseBaseURL } from 'soapbox/utils/auth'; import { createApp } from 'soapbox/actions/apps'; +import { fetchMeSuccess, fetchMeFail } from 'soapbox/actions/me'; import { obtainOAuthToken, revokeOAuthToken } from 'soapbox/actions/oauth'; +import snackbar from 'soapbox/actions/snackbar'; +import KVStore from 'soapbox/storage/kv_store'; +import { getLoggedInAccount, parseBaseURL } from 'soapbox/utils/auth'; import sourceCode from 'soapbox/utils/code'; import { getFeatures } from 'soapbox/utils/features'; import { isStandalone } from 'soapbox/utils/state'; -import KVStore from 'soapbox/storage/kv_store'; + +import api, { baseClient } from '../api'; + +import { importFetchedAccount } from './importer'; export const SWITCH_ACCOUNT = 'SWITCH_ACCOUNT'; @@ -140,6 +143,7 @@ export function otpVerify(code, mfa_token) { code: code, challenge_type: 'totp', redirect_uri: 'urn:ietf:wg:oauth:2.0:oob', + scope: getScopes(getState()), }).then(({ data: token }) => dispatch(authLoggedIn(token))); }; } diff --git a/app/soapbox/actions/blocks.js b/app/soapbox/actions/blocks.js index 63d01de3a..554446f2f 100644 --- a/app/soapbox/actions/blocks.js +++ b/app/soapbox/actions/blocks.js @@ -1,9 +1,11 @@ -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'; +import api, { getLinks } from '../api'; + +import { fetchRelationships } from './accounts'; +import { importFetchedAccounts } from './importer'; + export const BLOCKS_FETCH_REQUEST = 'BLOCKS_FETCH_REQUEST'; export const BLOCKS_FETCH_SUCCESS = 'BLOCKS_FETCH_SUCCESS'; export const BLOCKS_FETCH_FAIL = 'BLOCKS_FETCH_FAIL'; diff --git a/app/soapbox/actions/bookmarks.js b/app/soapbox/actions/bookmarks.js index cf1ca8113..a0400ff38 100644 --- a/app/soapbox/actions/bookmarks.js +++ b/app/soapbox/actions/bookmarks.js @@ -1,4 +1,5 @@ import api, { getLinks } from '../api'; + import { importFetchedStatuses } from './importer'; export const BOOKMARKED_STATUSES_FETCH_REQUEST = 'BOOKMARKED_STATUSES_FETCH_REQUEST'; diff --git a/app/soapbox/actions/chats.js b/app/soapbox/actions/chats.js index 2ca996cfe..8003bb8cb 100644 --- a/app/soapbox/actions/chats.js +++ b/app/soapbox/actions/chats.js @@ -1,8 +1,10 @@ -import api, { getLinks } from '../api'; +import { Map as ImmutableMap } from 'immutable'; +import { v4 as uuidv4 } from 'uuid'; + import { getSettings, changeSetting } from 'soapbox/actions/settings'; import { getFeatures } from 'soapbox/utils/features'; -import { v4 as uuidv4 } from 'uuid'; -import { Map as ImmutableMap } from 'immutable'; + +import api, { getLinks } from '../api'; export const CHATS_FETCH_REQUEST = 'CHATS_FETCH_REQUEST'; export const CHATS_FETCH_SUCCESS = 'CHATS_FETCH_SUCCESS'; diff --git a/app/soapbox/actions/compose.js b/app/soapbox/actions/compose.js index 124ef69c4..9801b40b2 100644 --- a/app/soapbox/actions/compose.js +++ b/app/soapbox/actions/compose.js @@ -1,20 +1,23 @@ -import api from '../api'; import { CancelToken, isCancel } from 'axios'; import { throttle } from 'lodash'; +import { defineMessages } from 'react-intl'; + +import snackbar from 'soapbox/actions/snackbar'; +import { isLoggedIn } from 'soapbox/utils/auth'; +import { getFeatures } from 'soapbox/utils/features'; + +import api from '../api'; import { search as emojiSearch } from '../features/emoji/emoji_mart_search_light'; import { tagHistory } from '../settings'; -import { useEmoji } from './emojis'; import resizeImage from '../utils/resize_image'; -import { importFetchedAccounts } from './importer'; + import { showAlert, showAlertForError } from './alerts'; -import { defineMessages } from 'react-intl'; +import { useEmoji } from './emojis'; +import { importFetchedAccounts } from './importer'; +import { uploadMedia, fetchMedia, updateMedia } from './media'; import { openModal, closeModal } from './modal'; import { getSettings } from './settings'; -import { getFeatures } from 'soapbox/utils/features'; -import { uploadMedia, fetchMedia, updateMedia } from './media'; -import { isLoggedIn } from 'soapbox/utils/auth'; import { createStatus } from './statuses'; -import snackbar from 'soapbox/actions/snackbar'; let cancelFetchComposeSuggestionsAccounts; diff --git a/app/soapbox/actions/conversations.js b/app/soapbox/actions/conversations.js index e019441f9..4e7eb214f 100644 --- a/app/soapbox/actions/conversations.js +++ b/app/soapbox/actions/conversations.js @@ -1,10 +1,12 @@ +import { isLoggedIn } from 'soapbox/utils/auth'; + import api, { getLinks } from '../api'; + import { importFetchedAccounts, importFetchedStatuses, importFetchedStatus, } from './importer'; -import { isLoggedIn } from 'soapbox/utils/auth'; export const CONVERSATIONS_MOUNT = 'CONVERSATIONS_MOUNT'; export const CONVERSATIONS_UNMOUNT = 'CONVERSATIONS_UNMOUNT'; diff --git a/app/soapbox/actions/directory.js b/app/soapbox/actions/directory.js index 35e699703..0ee15386b 100644 --- a/app/soapbox/actions/directory.js +++ b/app/soapbox/actions/directory.js @@ -1,6 +1,7 @@ import api from '../api'; -import { importFetchedAccounts } from './importer'; + import { fetchRelationships } from './accounts'; +import { importFetchedAccounts } from './importer'; export const DIRECTORY_FETCH_REQUEST = 'DIRECTORY_FETCH_REQUEST'; export const DIRECTORY_FETCH_SUCCESS = 'DIRECTORY_FETCH_SUCCESS'; diff --git a/app/soapbox/actions/domain_blocks.js b/app/soapbox/actions/domain_blocks.js index 8872590a3..92824a55c 100644 --- a/app/soapbox/actions/domain_blocks.js +++ b/app/soapbox/actions/domain_blocks.js @@ -1,6 +1,7 @@ -import api, { getLinks } from '../api'; import { isLoggedIn } from 'soapbox/utils/auth'; +import api, { getLinks } from '../api'; + export const DOMAIN_BLOCK_REQUEST = 'DOMAIN_BLOCK_REQUEST'; export const DOMAIN_BLOCK_SUCCESS = 'DOMAIN_BLOCK_SUCCESS'; export const DOMAIN_BLOCK_FAIL = 'DOMAIN_BLOCK_FAIL'; diff --git a/app/soapbox/actions/emoji_reacts.js b/app/soapbox/actions/emoji_reacts.js index 8ed43b8ed..a057dd35e 100644 --- a/app/soapbox/actions/emoji_reacts.js +++ b/app/soapbox/actions/emoji_reacts.js @@ -1,8 +1,11 @@ +import { List as ImmutableList } from 'immutable'; + +import { isLoggedIn } from 'soapbox/utils/auth'; + import api from '../api'; + import { importFetchedAccounts, importFetchedStatus } from './importer'; import { favourite, unfavourite } from './interactions'; -import { isLoggedIn } from 'soapbox/utils/auth'; -import { List as ImmutableList } from 'immutable'; export const EMOJI_REACT_REQUEST = 'EMOJI_REACT_REQUEST'; export const EMOJI_REACT_SUCCESS = 'EMOJI_REACT_SUCCESS'; diff --git a/app/soapbox/actions/export_data.js b/app/soapbox/actions/export_data.js index 479b44b0a..12e0bd58b 100644 --- a/app/soapbox/actions/export_data.js +++ b/app/soapbox/actions/export_data.js @@ -1,5 +1,7 @@ import { defineMessages } from 'react-intl'; + import snackbar from 'soapbox/actions/snackbar'; + import api, { getLinks } from '../api'; export const EXPORT_FOLLOWS_REQUEST = 'EXPORT_FOLLOWS_REQUEST'; diff --git a/app/soapbox/actions/external_auth.js b/app/soapbox/actions/external_auth.js index d486b4026..b3258ab70 100644 --- a/app/soapbox/actions/external_auth.js +++ b/app/soapbox/actions/external_auth.js @@ -6,15 +6,17 @@ * @see module:soapbox/actions/oauth */ -import { baseClient } from '../api'; -import { createApp } from 'soapbox/actions/apps'; -import { obtainOAuthToken } from 'soapbox/actions/oauth'; -import { authLoggedIn, verifyCredentials, switchAccount } from 'soapbox/actions/auth'; -import { parseBaseURL } from 'soapbox/utils/auth'; -import { getFeatures } from 'soapbox/utils/features'; -import sourceCode from 'soapbox/utils/code'; import { Map as ImmutableMap, fromJS } from 'immutable'; +import { createApp } from 'soapbox/actions/apps'; +import { authLoggedIn, verifyCredentials, switchAccount } from 'soapbox/actions/auth'; +import { obtainOAuthToken } from 'soapbox/actions/oauth'; +import { parseBaseURL } from 'soapbox/utils/auth'; +import sourceCode from 'soapbox/utils/code'; +import { getFeatures } from 'soapbox/utils/features'; + +import { baseClient } from '../api'; + const fetchExternalInstance = baseURL => { return baseClient(null, baseURL) .get('/api/v1/instance') diff --git a/app/soapbox/actions/favourites.js b/app/soapbox/actions/favourites.js index dfc1ee9ba..c4bce15e9 100644 --- a/app/soapbox/actions/favourites.js +++ b/app/soapbox/actions/favourites.js @@ -1,7 +1,9 @@ -import api, { getLinks } from '../api'; -import { importFetchedStatuses } from './importer'; import { isLoggedIn } from 'soapbox/utils/auth'; +import api, { getLinks } from '../api'; + +import { importFetchedStatuses } from './importer'; + export const FAVOURITED_STATUSES_FETCH_REQUEST = 'FAVOURITED_STATUSES_FETCH_REQUEST'; export const FAVOURITED_STATUSES_FETCH_SUCCESS = 'FAVOURITED_STATUSES_FETCH_SUCCESS'; export const FAVOURITED_STATUSES_FETCH_FAIL = 'FAVOURITED_STATUSES_FETCH_FAIL'; diff --git a/app/soapbox/actions/filters.js b/app/soapbox/actions/filters.js index b5964cd38..e6af25f9c 100644 --- a/app/soapbox/actions/filters.js +++ b/app/soapbox/actions/filters.js @@ -1,8 +1,10 @@ import { defineMessages } from 'react-intl'; -import api from '../api'; + import snackbar from 'soapbox/actions/snackbar'; import { isLoggedIn } from 'soapbox/utils/auth'; +import api from '../api'; + export const FILTERS_FETCH_REQUEST = 'FILTERS_FETCH_REQUEST'; export const FILTERS_FETCH_SUCCESS = 'FILTERS_FETCH_SUCCESS'; export const FILTERS_FETCH_FAIL = 'FILTERS_FETCH_FAIL'; diff --git a/app/soapbox/actions/group_editor.js b/app/soapbox/actions/group_editor.js index b74533a14..f504a743a 100644 --- a/app/soapbox/actions/group_editor.js +++ b/app/soapbox/actions/group_editor.js @@ -1,6 +1,7 @@ -import api from '../api'; import { isLoggedIn } from 'soapbox/utils/auth'; +import api from '../api'; + export const GROUP_CREATE_REQUEST = 'GROUP_CREATE_REQUEST'; export const GROUP_CREATE_SUCCESS = 'GROUP_CREATE_SUCCESS'; export const GROUP_CREATE_FAIL = 'GROUP_CREATE_FAIL'; diff --git a/app/soapbox/actions/groups.js b/app/soapbox/actions/groups.js index 94b3675ad..3c6255216 100644 --- a/app/soapbox/actions/groups.js +++ b/app/soapbox/actions/groups.js @@ -1,8 +1,10 @@ -import api, { getLinks } from '../api'; -import { importFetchedAccounts } from './importer'; -import { fetchRelationships } from './accounts'; import { isLoggedIn } from 'soapbox/utils/auth'; +import api, { getLinks } from '../api'; + +import { fetchRelationships } from './accounts'; +import { importFetchedAccounts } from './importer'; + export const GROUP_FETCH_REQUEST = 'GROUP_FETCH_REQUEST'; export const GROUP_FETCH_SUCCESS = 'GROUP_FETCH_SUCCESS'; export const GROUP_FETCH_FAIL = 'GROUP_FETCH_FAIL'; diff --git a/app/soapbox/actions/import_data.js b/app/soapbox/actions/import_data.js index acf205f94..7bde21a4a 100644 --- a/app/soapbox/actions/import_data.js +++ b/app/soapbox/actions/import_data.js @@ -1,7 +1,9 @@ import { defineMessages } from 'react-intl'; -import api from '../api'; + import snackbar from 'soapbox/actions/snackbar'; +import api from '../api'; + export const IMPORT_FOLLOWS_REQUEST = 'IMPORT_FOLLOWS_REQUEST'; export const IMPORT_FOLLOWS_SUCCESS = 'IMPORT_FOLLOWS_SUCCESS'; export const IMPORT_FOLLOWS_FAIL = 'IMPORT_FOLLOWS_FAIL'; diff --git a/app/soapbox/actions/importer/index.js b/app/soapbox/actions/importer/index.js index ee4f1cfa7..407bb7c30 100644 --- a/app/soapbox/actions/importer/index.js +++ b/app/soapbox/actions/importer/index.js @@ -1,4 +1,5 @@ import { getSettings } from '../settings'; + import { normalizeAccount, normalizeStatus, diff --git a/app/soapbox/actions/importer/normalizer.js b/app/soapbox/actions/importer/normalizer.js index 922e57986..240abddcc 100644 --- a/app/soapbox/actions/importer/normalizer.js +++ b/app/soapbox/actions/importer/normalizer.js @@ -1,4 +1,5 @@ import escapeTextContentForBrowser from 'escape-html'; + import emojify from '../../features/emoji/emoji'; import { unescapeHTML } from '../../utils/html'; diff --git a/app/soapbox/actions/instance.js b/app/soapbox/actions/instance.js index bc3b95758..85d8b2a3f 100644 --- a/app/soapbox/actions/instance.js +++ b/app/soapbox/actions/instance.js @@ -1,8 +1,10 @@ -import api from '../api'; import { get } from 'lodash'; -import { parseVersion } from 'soapbox/utils/features'; -import { getAuthUserUrl } from 'soapbox/utils/auth'; + import KVStore from 'soapbox/storage/kv_store'; +import { getAuthUserUrl } from 'soapbox/utils/auth'; +import { parseVersion } from 'soapbox/utils/features'; + +import api from '../api'; export const INSTANCE_FETCH_REQUEST = 'INSTANCE_FETCH_REQUEST'; export const INSTANCE_FETCH_SUCCESS = 'INSTANCE_FETCH_SUCCESS'; diff --git a/app/soapbox/actions/interactions.js b/app/soapbox/actions/interactions.js index c67789117..d7f27a96c 100644 --- a/app/soapbox/actions/interactions.js +++ b/app/soapbox/actions/interactions.js @@ -1,9 +1,12 @@ import { defineMessages } from 'react-intl'; -import api from '../api'; -import { importFetchedAccounts, importFetchedStatus } from './importer'; + import snackbar from 'soapbox/actions/snackbar'; import { isLoggedIn } from 'soapbox/utils/auth'; +import api from '../api'; + +import { importFetchedAccounts, importFetchedStatus } from './importer'; + export const REBLOG_REQUEST = 'REBLOG_REQUEST'; export const REBLOG_SUCCESS = 'REBLOG_SUCCESS'; export const REBLOG_FAIL = 'REBLOG_FAIL'; diff --git a/app/soapbox/actions/lists.js b/app/soapbox/actions/lists.js index a04bbc6f1..6b39978d2 100644 --- a/app/soapbox/actions/lists.js +++ b/app/soapbox/actions/lists.js @@ -1,8 +1,10 @@ -import api from '../api'; -import { importFetchedAccounts } from './importer'; -import { showAlertForError } from './alerts'; import { isLoggedIn } from 'soapbox/utils/auth'; +import api from '../api'; + +import { showAlertForError } from './alerts'; +import { importFetchedAccounts } from './importer'; + export const LIST_FETCH_REQUEST = 'LIST_FETCH_REQUEST'; export const LIST_FETCH_SUCCESS = 'LIST_FETCH_SUCCESS'; export const LIST_FETCH_FAIL = 'LIST_FETCH_FAIL'; diff --git a/app/soapbox/actions/me.js b/app/soapbox/actions/me.js index 2dcf36ab9..e04001e4c 100644 --- a/app/soapbox/actions/me.js +++ b/app/soapbox/actions/me.js @@ -1,8 +1,10 @@ -import api from '../api'; -import { importFetchedAccount } from './importer'; -import { loadCredentials } from './auth'; import { getAuthUserId, getAuthUserUrl } from 'soapbox/utils/auth'; +import api from '../api'; + +import { loadCredentials } from './auth'; +import { importFetchedAccount } from './importer'; + export const ME_FETCH_REQUEST = 'ME_FETCH_REQUEST'; export const ME_FETCH_SUCCESS = 'ME_FETCH_SUCCESS'; export const ME_FETCH_FAIL = 'ME_FETCH_FAIL'; diff --git a/app/soapbox/actions/media.js b/app/soapbox/actions/media.js index 3c71c91a4..460c2f079 100644 --- a/app/soapbox/actions/media.js +++ b/app/soapbox/actions/media.js @@ -1,6 +1,7 @@ -import api from '../api'; import { getFeatures } from 'soapbox/utils/features'; +import api from '../api'; + const noOp = () => {}; export function fetchMedia(mediaId) { diff --git a/app/soapbox/actions/mfa.js b/app/soapbox/actions/mfa.js index 171446053..d41c60f52 100644 --- a/app/soapbox/actions/mfa.js +++ b/app/soapbox/actions/mfa.js @@ -60,10 +60,12 @@ export function confirmMfa(method, code, password) { return (dispatch, getState) => { const params = { code, password }; dispatch({ type: MFA_CONFIRM_REQUEST, method, code }); - return api(getState).post(`/api/pleroma/accounts/mfa/confirm/${method}`, params).then(() => { + return api(getState).post(`/api/pleroma/accounts/mfa/confirm/${method}`, params).then(({ data }) => { dispatch({ type: MFA_CONFIRM_SUCCESS, method, code }); + return data; }).catch(error => { - dispatch({ type: MFA_CONFIRM_FAIL, method, code, error }); + dispatch({ type: MFA_CONFIRM_FAIL, method, code, error, skipAlert: true }); + throw error; }); }; } @@ -71,10 +73,12 @@ export function confirmMfa(method, code, password) { export function disableMfa(method, password) { return (dispatch, getState) => { dispatch({ type: MFA_DISABLE_REQUEST, method }); - return api(getState).delete(`/api/pleroma/accounts/mfa/${method}`, { data: { password } }).then(response => { + return api(getState).delete(`/api/pleroma/accounts/mfa/${method}`, { data: { password } }).then(({ data }) => { dispatch({ type: MFA_DISABLE_SUCCESS, method }); + return data; }).catch(error => { - dispatch({ type: MFA_DISABLE_FAIL, method }); + dispatch({ type: MFA_DISABLE_FAIL, method, skipAlert: true }); + throw error; }); }; } diff --git a/app/soapbox/actions/moderation.js b/app/soapbox/actions/moderation.js index cda6f3b23..7bad7e82d 100644 --- a/app/soapbox/actions/moderation.js +++ b/app/soapbox/actions/moderation.js @@ -1,8 +1,9 @@ import React from 'react'; import { defineMessages } from 'react-intl'; -import { openModal } from 'soapbox/actions/modal'; -import { deactivateUsers, deleteUsers, deleteStatus, toggleStatusSensitivity } from 'soapbox/actions/admin'; + import { fetchAccountByUsername } from 'soapbox/actions/accounts'; +import { deactivateUsers, deleteUsers, deleteStatus, toggleStatusSensitivity } from 'soapbox/actions/admin'; +import { openModal } from 'soapbox/actions/modal'; import snackbar from 'soapbox/actions/snackbar'; import AccountContainer from 'soapbox/containers/account_container'; import { isLocal } from 'soapbox/utils/accounts'; diff --git a/app/soapbox/actions/mrf.js b/app/soapbox/actions/mrf.js index e4f07a9fd..39359e965 100644 --- a/app/soapbox/actions/mrf.js +++ b/app/soapbox/actions/mrf.js @@ -1,7 +1,9 @@ -import { fetchConfig, updateConfig } from './admin'; import { Set as ImmutableSet } from 'immutable'; + import ConfigDB from 'soapbox/utils/config_db'; +import { fetchConfig, updateConfig } from './admin'; + const simplePolicyMerge = (simplePolicy, host, restrictions) => { return simplePolicy.map((hosts, key) => { const isRestricted = restrictions.get(key); diff --git a/app/soapbox/actions/mutes.js b/app/soapbox/actions/mutes.js index 3cdc3b5fb..f7c2b6a11 100644 --- a/app/soapbox/actions/mutes.js +++ b/app/soapbox/actions/mutes.js @@ -1,9 +1,11 @@ +import { isLoggedIn } from 'soapbox/utils/auth'; +import { getNextLinkName } from 'soapbox/utils/quirks'; + import api, { getLinks } from '../api'; + 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'; diff --git a/app/soapbox/actions/notifications.js b/app/soapbox/actions/notifications.js index ca37cf525..08f9bb718 100644 --- a/app/soapbox/actions/notifications.js +++ b/app/soapbox/actions/notifications.js @@ -1,6 +1,20 @@ -import api, { getLinks } from '../api'; +import { + List as ImmutableList, + Map as ImmutableMap, + OrderedMap as ImmutableOrderedMap, +} from 'immutable'; import IntlMessageFormat from 'intl-messageformat'; import 'intl-pluralrules'; +import { defineMessages } from 'react-intl'; + +import { isLoggedIn } from 'soapbox/utils/auth'; +import { parseVersion, PLEROMA } from 'soapbox/utils/features'; +import { joinPublicPath } from 'soapbox/utils/static'; + +import api, { getLinks } from '../api'; +import { getFilters, regexFromFilters } from '../selectors'; +import { unescapeHTML } from '../utils/html'; + import { fetchRelationships } from './accounts'; import { importFetchedAccount, @@ -10,17 +24,6 @@ import { } from './importer'; import { saveMarker } from './markers'; import { getSettings, saveSettings } from './settings'; -import { defineMessages } from 'react-intl'; -import { - List as ImmutableList, - Map as ImmutableMap, - OrderedMap as ImmutableOrderedMap, -} from 'immutable'; -import { unescapeHTML } from '../utils/html'; -import { getFilters, regexFromFilters } from '../selectors'; -import { isLoggedIn } from 'soapbox/utils/auth'; -import { parseVersion, PLEROMA } from 'soapbox/utils/features'; -import { joinPublicPath } from 'soapbox/utils/static'; export const NOTIFICATIONS_UPDATE = 'NOTIFICATIONS_UPDATE'; export const NOTIFICATIONS_UPDATE_NOOP = 'NOTIFICATIONS_UPDATE_NOOP'; diff --git a/app/soapbox/actions/pin_statuses.js b/app/soapbox/actions/pin_statuses.js index ecab511d0..26194f553 100644 --- a/app/soapbox/actions/pin_statuses.js +++ b/app/soapbox/actions/pin_statuses.js @@ -1,7 +1,9 @@ -import api from '../api'; -import { importFetchedStatuses } from './importer'; import { isLoggedIn } from 'soapbox/utils/auth'; +import api from '../api'; + +import { importFetchedStatuses } from './importer'; + export const PINNED_STATUSES_FETCH_REQUEST = 'PINNED_STATUSES_FETCH_REQUEST'; export const PINNED_STATUSES_FETCH_SUCCESS = 'PINNED_STATUSES_FETCH_SUCCESS'; export const PINNED_STATUSES_FETCH_FAIL = 'PINNED_STATUSES_FETCH_FAIL'; diff --git a/app/soapbox/actions/polls.js b/app/soapbox/actions/polls.js index 8e8b82df5..a37410dc9 100644 --- a/app/soapbox/actions/polls.js +++ b/app/soapbox/actions/polls.js @@ -1,4 +1,5 @@ import api from '../api'; + import { importFetchedPoll } from './importer'; export const POLL_VOTE_REQUEST = 'POLL_VOTE_REQUEST'; diff --git a/app/soapbox/actions/preload.js b/app/soapbox/actions/preload.js index c8f2fe7d1..d14c6f9fe 100644 --- a/app/soapbox/actions/preload.js +++ b/app/soapbox/actions/preload.js @@ -1,6 +1,7 @@ import { mapValues } from 'lodash'; -import { importFetchedAccounts } from './importer'; + import { verifyCredentials } from './auth'; +import { importFetchedAccounts } from './importer'; export const PLEROMA_PRELOAD_IMPORT = 'PLEROMA_PRELOAD_IMPORT'; export const MASTODON_PRELOAD_IMPORT = 'MASTODON_PRELOAD_IMPORT'; diff --git a/app/soapbox/actions/push_notifications/index.js b/app/soapbox/actions/push_notifications/index.js index 2ffec500a..32b0ffcaf 100644 --- a/app/soapbox/actions/push_notifications/index.js +++ b/app/soapbox/actions/push_notifications/index.js @@ -1,3 +1,4 @@ +import { register, saveSettings } from './registerer'; import { SET_BROWSER_SUPPORT, SET_SUBSCRIPTION, @@ -5,7 +6,6 @@ import { SET_ALERTS, setAlerts, } from './setter'; -import { register, saveSettings } from './registerer'; export { SET_BROWSER_SUPPORT, diff --git a/app/soapbox/actions/push_notifications/registerer.js b/app/soapbox/actions/push_notifications/registerer.js index 2dca31fe8..b4d86631e 100644 --- a/app/soapbox/actions/push_notifications/registerer.js +++ b/app/soapbox/actions/push_notifications/registerer.js @@ -1,9 +1,11 @@ -import { decode as decodeBase64 } from '../../utils/base64'; -import { pushNotificationsSetting } from '../../settings'; -import { setBrowserSupport, setSubscription, clearSubscription } from './setter'; import { createPushSubsription, updatePushSubscription } from 'soapbox/actions/push_subscriptions'; import { getVapidKey } from 'soapbox/utils/auth'; +import { pushNotificationsSetting } from '../../settings'; +import { decode as decodeBase64 } from '../../utils/base64'; + +import { setBrowserSupport, setSubscription, clearSubscription } from './setter'; + // Taken from https://www.npmjs.com/package/web-push const urlBase64ToUint8Array = (base64String) => { const padding = '='.repeat((4 - base64String.length % 4) % 4); diff --git a/app/soapbox/actions/reports.js b/app/soapbox/actions/reports.js index 9d0d4e581..2db3bce31 100644 --- a/app/soapbox/actions/reports.js +++ b/app/soapbox/actions/reports.js @@ -1,4 +1,5 @@ import api from '../api'; + import { openModal, closeModal } from './modal'; export const REPORT_INIT = 'REPORT_INIT'; diff --git a/app/soapbox/actions/search.js b/app/soapbox/actions/search.js index 6764dc534..27cb4bdbd 100644 --- a/app/soapbox/actions/search.js +++ b/app/soapbox/actions/search.js @@ -1,4 +1,5 @@ import api from '../api'; + import { fetchRelationships } from './accounts'; import { importFetchedAccounts, importFetchedStatuses } from './importer'; diff --git a/app/soapbox/actions/security.js b/app/soapbox/actions/security.js index e5e15b6f5..4cc957992 100644 --- a/app/soapbox/actions/security.js +++ b/app/soapbox/actions/security.js @@ -4,9 +4,11 @@ * @see module:soapbox/actions/auth */ -import api from '../api'; -import { getLoggedInAccount } from 'soapbox/utils/auth'; import snackbar from 'soapbox/actions/snackbar'; +import { getLoggedInAccount } from 'soapbox/utils/auth'; + +import api from '../api'; + import { AUTH_LOGGED_OUT, messages } from './auth'; export const FETCH_TOKENS_REQUEST = 'FETCH_TOKENS_REQUEST'; diff --git a/app/soapbox/actions/settings.js b/app/soapbox/actions/settings.js index e10f2f430..4a50909fa 100644 --- a/app/soapbox/actions/settings.js +++ b/app/soapbox/actions/settings.js @@ -1,11 +1,14 @@ -import { debounce } from 'lodash'; -import { showAlertForError } from './alerts'; -import { patchMe } from 'soapbox/actions/me'; import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet } from 'immutable'; -import { isLoggedIn } from 'soapbox/utils/auth'; -import uuid from '../uuid'; +import { debounce } from 'lodash'; import { createSelector } from 'reselect'; +import { patchMe } from 'soapbox/actions/me'; +import { isLoggedIn } from 'soapbox/utils/auth'; + +import uuid from '../uuid'; + +import { showAlertForError } from './alerts'; + export const SETTING_CHANGE = 'SETTING_CHANGE'; export const SETTING_SAVE = 'SETTING_SAVE'; export const SETTINGS_UPDATE = 'SETTINGS_UPDATE'; @@ -165,6 +168,18 @@ export const getSettings = createSelector([ .mergeDeep(settings); }); +export function changeSettingImmediate(path, value) { + return dispatch => { + dispatch({ + type: SETTING_CHANGE, + path, + value, + }); + + dispatch(saveSettingsImmediate()); + }; +} + export function changeSetting(path, value) { return dispatch => { dispatch({ @@ -177,23 +192,29 @@ export function changeSetting(path, value) { }; } +export function saveSettingsImmediate() { + return (dispatch, getState) => { + if (!isLoggedIn(getState)) return; + + const state = getState(); + if (getSettings(state).getIn(['saved'])) return; + + const data = state.get('settings').delete('saved').toJS(); + + dispatch(patchMe({ + pleroma_settings_store: { + [FE_NAME]: data, + }, + })).then(response => { + dispatch({ type: SETTING_SAVE }); + }).catch(error => { + dispatch(showAlertForError(error)); + }); + }; +} + const debouncedSave = debounce((dispatch, getState) => { - if (!isLoggedIn(getState)) return; - - const state = getState(); - if (getSettings(state).getIn(['saved'])) return; - - const data = state.get('settings').delete('saved').toJS(); - - dispatch(patchMe({ - pleroma_settings_store: { - [FE_NAME]: data, - }, - })).then(response => { - dispatch({ type: SETTING_SAVE }); - }).catch(error => { - dispatch(showAlertForError(error)); - }); + dispatch(saveSettingsImmediate()); }, 5000, { trailing: true }); export function saveSettings() { diff --git a/app/soapbox/actions/soapbox.js b/app/soapbox/actions/soapbox.js index 4358e9f1d..d85bd0f0f 100644 --- a/app/soapbox/actions/soapbox.js +++ b/app/soapbox/actions/soapbox.js @@ -1,9 +1,11 @@ -import api, { staticClient } from '../api'; import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; -import { getFeatures } from 'soapbox/utils/features'; import { createSelector } from 'reselect'; + import { getHost } from 'soapbox/actions/instance'; import KVStore from 'soapbox/storage/kv_store'; +import { getFeatures } from 'soapbox/utils/features'; + +import api, { staticClient } from '../api'; export const SOAPBOX_CONFIG_REQUEST_SUCCESS = 'SOAPBOX_CONFIG_REQUEST_SUCCESS'; export const SOAPBOX_CONFIG_REQUEST_FAIL = 'SOAPBOX_CONFIG_REQUEST_FAIL'; diff --git a/app/soapbox/actions/statuses.js b/app/soapbox/actions/statuses.js index ec5811cba..150b6d8c7 100644 --- a/app/soapbox/actions/statuses.js +++ b/app/soapbox/actions/statuses.js @@ -1,11 +1,13 @@ -import api from '../api'; -import { deleteFromTimelines } from './timelines'; -import { importFetchedStatus, importFetchedStatuses } from './importer'; -import { openModal } from './modal'; import { isLoggedIn } from 'soapbox/utils/auth'; import { getFeatures } from 'soapbox/utils/features'; import { shouldHaveCard } from 'soapbox/utils/status'; +import api from '../api'; + +import { importFetchedStatus, importFetchedStatuses } from './importer'; +import { openModal } from './modal'; +import { deleteFromTimelines } from './timelines'; + export const STATUS_CREATE_REQUEST = 'STATUS_CREATE_REQUEST'; export const STATUS_CREATE_SUCCESS = 'STATUS_CREATE_SUCCESS'; export const STATUS_CREATE_FAIL = 'STATUS_CREATE_FAIL'; diff --git a/app/soapbox/actions/streaming.js b/app/soapbox/actions/streaming.js index 1b8de7b97..bd1ed00da 100644 --- a/app/soapbox/actions/streaming.js +++ b/app/soapbox/actions/streaming.js @@ -1,4 +1,11 @@ +import { getSettings } from 'soapbox/actions/settings'; +import messages from 'soapbox/locales/messages'; + import { connectStream } from '../stream'; + +import { updateConversations } from './conversations'; +import { fetchFilters } from './filters'; +import { updateNotificationsQueue, expandNotifications } from './notifications'; import { deleteFromTimelines, expandHomeTimeline, @@ -6,11 +13,6 @@ import { disconnectTimeline, processTimelineUpdate, } from './timelines'; -import { updateNotificationsQueue, expandNotifications } from './notifications'; -import { updateConversations } from './conversations'; -import { fetchFilters } from './filters'; -import { getSettings } from 'soapbox/actions/settings'; -import messages from 'soapbox/locales/messages'; export const STREAMING_CHAT_UPDATE = 'STREAMING_CHAT_UPDATE'; export const STREAMING_FOLLOW_RELATIONSHIPS_UPDATE = 'STREAMING_FOLLOW_RELATIONSHIPS_UPDATE'; diff --git a/app/soapbox/actions/suggestions.js b/app/soapbox/actions/suggestions.js index d36c2c21d..d896e6e07 100644 --- a/app/soapbox/actions/suggestions.js +++ b/app/soapbox/actions/suggestions.js @@ -1,8 +1,10 @@ -import api from '../api'; -import { importFetchedAccounts } from './importer'; import { isLoggedIn } from 'soapbox/utils/auth'; import { getFeatures } from 'soapbox/utils/features'; + +import api from '../api'; + import { fetchRelationships } from './accounts'; +import { importFetchedAccounts } from './importer'; export const SUGGESTIONS_FETCH_REQUEST = 'SUGGESTIONS_FETCH_REQUEST'; export const SUGGESTIONS_FETCH_SUCCESS = 'SUGGESTIONS_FETCH_SUCCESS'; diff --git a/app/soapbox/actions/timelines.js b/app/soapbox/actions/timelines.js index 934c52b00..bef27b287 100644 --- a/app/soapbox/actions/timelines.js +++ b/app/soapbox/actions/timelines.js @@ -1,9 +1,12 @@ -import { importFetchedStatus, importFetchedStatuses } from './importer'; -import api, { getLinks } from '../api'; import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable'; + import { getSettings } from 'soapbox/actions/settings'; import { shouldFilter } from 'soapbox/utils/timelines'; +import api, { getLinks } from '../api'; + +import { importFetchedStatus, importFetchedStatuses } from './importer'; + export const TIMELINE_UPDATE = 'TIMELINE_UPDATE'; export const TIMELINE_DELETE = 'TIMELINE_DELETE'; export const TIMELINE_CLEAR = 'TIMELINE_CLEAR'; diff --git a/app/soapbox/api.js b/app/soapbox/api.js index 2a6b5092a..13ee07186 100644 --- a/app/soapbox/api.js +++ b/app/soapbox/api.js @@ -7,9 +7,10 @@ import axios from 'axios'; import LinkHeader from 'http-link-header'; -import { getAccessToken, getAppToken, parseBaseURL } from 'soapbox/utils/auth'; import { createSelector } from 'reselect'; + import { BACKEND_URL, FE_SUBDIRECTORY } from 'soapbox/build_config'; +import { getAccessToken, getAppToken, parseBaseURL } from 'soapbox/utils/auth'; import { isURL } from 'soapbox/utils/auth'; /** diff --git a/app/soapbox/base_polyfills.js b/app/soapbox/base_polyfills.js index d54ed977c..e4744fee3 100644 --- a/app/soapbox/base_polyfills.js +++ b/app/soapbox/base_polyfills.js @@ -4,9 +4,10 @@ import 'intl'; import 'intl/locale-data/jsonp/en'; import 'es6-symbol/implement'; import includes from 'array-includes'; +import isNaN from 'is-nan'; import assign from 'object-assign'; import values from 'object.values'; -import isNaN from 'is-nan'; + import { decode as decodeBase64 } from './utils/base64'; if (!Array.prototype.includes) { diff --git a/app/soapbox/components/__mocks__/react-inlinesvg.js b/app/soapbox/components/__mocks__/react-inlinesvg.js index 33da43fde..41000c5cc 100644 --- a/app/soapbox/components/__mocks__/react-inlinesvg.js +++ b/app/soapbox/components/__mocks__/react-inlinesvg.js @@ -1,5 +1,5 @@ -import React from 'react'; import PropTypes from 'prop-types'; +import React from 'react'; export default function InlineSVG({ src }) { return ; diff --git a/app/soapbox/components/__tests__/autosuggest_emoji-test.js b/app/soapbox/components/__tests__/autosuggest_emoji-test.js index 05616e444..9a2fb58e8 100644 --- a/app/soapbox/components/__tests__/autosuggest_emoji-test.js +++ b/app/soapbox/components/__tests__/autosuggest_emoji-test.js @@ -1,5 +1,6 @@ import React from 'react'; import renderer from 'react-test-renderer'; + import AutosuggestEmoji from '../autosuggest_emoji'; describe('', () => { diff --git a/app/soapbox/components/__tests__/avatar-test.js b/app/soapbox/components/__tests__/avatar-test.js index 297b0b413..3834dfbb5 100644 --- a/app/soapbox/components/__tests__/avatar-test.js +++ b/app/soapbox/components/__tests__/avatar-test.js @@ -1,6 +1,8 @@ -import React from 'react'; import { fromJS } from 'immutable'; +import React from 'react'; + import { createComponent } from 'soapbox/test_helpers'; + import Avatar from '../avatar'; describe('', () => { diff --git a/app/soapbox/components/__tests__/avatar_overlay-test.js b/app/soapbox/components/__tests__/avatar_overlay-test.js index c469dcc75..db4250c59 100644 --- a/app/soapbox/components/__tests__/avatar_overlay-test.js +++ b/app/soapbox/components/__tests__/avatar_overlay-test.js @@ -1,6 +1,8 @@ -import React from 'react'; import { fromJS } from 'immutable'; +import React from 'react'; + import { createComponent } from 'soapbox/test_helpers'; + import AvatarOverlay from '../avatar_overlay'; describe(' { diff --git a/app/soapbox/components/__tests__/badge-test.js b/app/soapbox/components/__tests__/badge-test.js index 5a42f0531..0b577dc18 100644 --- a/app/soapbox/components/__tests__/badge-test.js +++ b/app/soapbox/components/__tests__/badge-test.js @@ -1,5 +1,6 @@ import React from 'react'; import renderer from 'react-test-renderer'; + import Badge from '../badge'; describe('', () => { diff --git a/app/soapbox/components/__tests__/button-test.js b/app/soapbox/components/__tests__/button-test.js index 160cd3cbc..e1480fe6f 100644 --- a/app/soapbox/components/__tests__/button-test.js +++ b/app/soapbox/components/__tests__/button-test.js @@ -1,6 +1,7 @@ import { shallow } from 'enzyme'; import React from 'react'; import renderer from 'react-test-renderer'; + import Button from '../button'; describe('