diff --git a/app/soapbox/actions/aliases.js b/app/soapbox/actions/aliases.js index cc62f8fa6..7f2dc6b00 100644 --- a/app/soapbox/actions/aliases.js +++ b/app/soapbox/actions/aliases.js @@ -55,8 +55,10 @@ export const changeAliasesSuggestions = value => ({ export const addToAliases = (intl, apId) => (dispatch, getState) => { if (!isLoggedIn(getState)) return; + const state = getState(); - const alsoKnownAs = getState().getIn(['meta', 'pleroma', 'also_known_as']); + const me = state.get('me'); + const alsoKnownAs = state.getIn(['accounts_meta', me, 'pleroma', 'also_known_as']); dispatch(addToAliasesRequest(apId)); @@ -92,8 +94,10 @@ export const addToAliasesFail = (apId, error) => ({ export const removeFromAliases = (intl, apId) => (dispatch, getState) => { if (!isLoggedIn(getState)) return; + const state = getState(); - const alsoKnownAs = getState().getIn(['meta', 'pleroma', 'also_known_as']); + const me = state.get('me'); + const alsoKnownAs = state.getIn(['accounts_meta', me, 'pleroma', 'also_known_as']); dispatch(removeFromAliasesRequest(apId)); diff --git a/app/soapbox/features/aliases/components/account.js b/app/soapbox/features/aliases/components/account.js index dcdfe7814..ff4ab069a 100644 --- a/app/soapbox/features/aliases/components/account.js +++ b/app/soapbox/features/aliases/components/account.js @@ -18,14 +18,17 @@ const makeMapStateToProps = () => { const getAccount = makeGetAccount(); const mapStateToProps = (state, { accountId, added }) => { + const me = state.get('me'); + const ownAccount = getAccount(state, me); + const account = getAccount(state, accountId); const apId = account.getIn(['pleroma', 'ap_id']); return { account, apId, - added: typeof added === 'undefined' ? state.getIn(['meta', 'pleroma', 'also_known_as']).includes(apId) : added, - me: state.get('me'), + added: typeof added === 'undefined' ? ownAccount.getIn(['pleroma', 'also_known_as']).includes(apId) : added, + me, }; }; diff --git a/app/soapbox/features/aliases/index.js b/app/soapbox/features/aliases/index.js index b2653ca6f..1171e9f95 100644 --- a/app/soapbox/features/aliases/index.js +++ b/app/soapbox/features/aliases/index.js @@ -9,6 +9,7 @@ import Icon from 'soapbox/components/icon'; import Search from './components/search'; import Account from './components/account'; import { removeFromAliases } from '../../actions/aliases'; +import { makeGetAccount } from 'soapbox/selectors'; const messages = defineMessages({ heading: { id: 'column.aliases', defaultMessage: 'Account aliases' }, @@ -19,13 +20,24 @@ const messages = defineMessages({ delete: { id: 'column.aliases.delete', defaultMessage: 'Delete' }, }); -const mapStateToProps = state => ({ - aliases: state.getIn(['meta', 'pleroma', 'also_known_as']), - searchAccountIds: state.getIn(['aliases', 'suggestions', 'items']), - loaded: state.getIn(['aliases', 'suggestions', 'loaded']), -}); +const makeMapStateToProps = () => { + const getAccount = makeGetAccount(); -export default @connect(mapStateToProps) + const mapStateToProps = state => { + const me = state.get('me'); + const account = getAccount(state, me); + + return { + aliases: account.getIn(['pleroma', 'also_known_as']), + searchAccountIds: state.getIn(['aliases', 'suggestions', 'items']), + loaded: state.getIn(['aliases', 'suggestions', 'loaded']), + }; + }; + + return mapStateToProps; +}; + +export default @connect(makeMapStateToProps) @injectIntl class Aliases extends ImmutablePureComponent { @@ -78,4 +90,4 @@ class Aliases extends ImmutablePureComponent { ); } -} \ No newline at end of file +} diff --git a/app/soapbox/features/edit_profile/index.js b/app/soapbox/features/edit_profile/index.js index 00c04aa3c..d0d343d13 100644 --- a/app/soapbox/features/edit_profile/index.js +++ b/app/soapbox/features/edit_profile/index.js @@ -26,6 +26,7 @@ import { unescape } from 'lodash'; import { isVerified } from 'soapbox/utils/accounts'; import { getSoapboxConfig } from 'soapbox/actions/soapbox'; import { getFeatures } from 'soapbox/utils/features'; +import { makeGetAccount } from 'soapbox/selectors'; const hidesNetwork = account => { const pleroma = account.get('pleroma'); @@ -45,22 +46,23 @@ const messages = defineMessages({ displayNamePlaceholder: { id: 'edit_profile.fields.display_name_placeholder', defaultMessage: 'Name' }, }); -const mapStateToProps = state => { - const me = state.get('me'); - const account = state.getIn(['accounts', me]); - const soapbox = getSoapboxConfig(state); +const makeMapStateToProps = () => { + const getAccount = makeGetAccount(); - const baseProfile = ImmutableMap({ - pleroma: state.getIn(['meta', 'pleroma', me]), - source: state.getIn(['meta', 'source', me]), - }); + const mapStateToProps = state => { + const me = state.get('me'); + const account = getAccount(state, me); + const soapbox = getSoapboxConfig(state); - return { - account: baseProfile.merge(account), - maxFields: state.getIn(['instance', 'pleroma', 'metadata', 'fields_limits', 'max_fields'], 4), - verifiedCanEditName: soapbox.get('verifiedCanEditName'), - supportsEmailList: getFeatures(state.get('instance')).emailList, + return { + account, + maxFields: state.getIn(['instance', 'pleroma', 'metadata', 'fields_limits', 'max_fields'], 4), + verifiedCanEditName: soapbox.get('verifiedCanEditName'), + supportsEmailList: getFeatures(state.get('instance')).emailList, + }; }; + + return mapStateToProps; }; // Forces fields to be maxFields size, filling empty values @@ -77,7 +79,7 @@ const unescapeParams = (map, params) => ( ), map) ); -export default @connect(mapStateToProps) +export default @connect(makeMapStateToProps) @injectIntl class EditProfile extends ImmutablePureComponent { diff --git a/app/soapbox/reducers/accounts.js b/app/soapbox/reducers/accounts.js index 8a00be845..fb0ac3ca6 100644 --- a/app/soapbox/reducers/accounts.js +++ b/app/soapbox/reducers/accounts.js @@ -46,6 +46,7 @@ const normalizeAccount = (state, account) => { 'followers_count', 'following_count', 'statuses_count', + 'source', ]); return state.set(account.id, normalized); diff --git a/app/soapbox/reducers/accounts_meta.js b/app/soapbox/reducers/accounts_meta.js new file mode 100644 index 000000000..51d9ee00a --- /dev/null +++ b/app/soapbox/reducers/accounts_meta.js @@ -0,0 +1,28 @@ +/** + * Accounts Meta: private user data only the owner should see. + * @module soapbox/reducers/accounts_meta + */ + +import { ME_FETCH_SUCCESS, ME_PATCH_SUCCESS } from 'soapbox/actions/me'; +import { Map as ImmutableMap, fromJS } from 'immutable'; + +const initialState = ImmutableMap(); + +const importAccount = (state, account) => { + const accountId = account.get('id'); + + return state.set(accountId, ImmutableMap({ + pleroma: account.get('pleroma', ImmutableMap()).delete('settings_store'), + source: account.get('source', ImmutableMap()), + })); +}; + +export default function accounts_meta(state = initialState, action) { + switch(action.type) { + case ME_FETCH_SUCCESS: + case ME_PATCH_SUCCESS: + return importAccount(state, fromJS(action.me)); + default: + return state; + } +} diff --git a/app/soapbox/reducers/index.js b/app/soapbox/reducers/index.js index cf62b4fdf..5c050b133 100644 --- a/app/soapbox/reducers/index.js +++ b/app/soapbox/reducers/index.js @@ -54,6 +54,7 @@ import admin_log from './admin_log'; import security from './security'; import scheduled_statuses from './scheduled_statuses'; import aliases from './aliases'; +import accounts_meta from './accounts_meta'; const appReducer = combineReducers({ dropdown_menu, @@ -109,6 +110,7 @@ const appReducer = combineReducers({ security, scheduled_statuses, aliases, + accounts_meta, }); // Clear the state (mostly) when the user logs out diff --git a/app/soapbox/reducers/meta.js b/app/soapbox/reducers/meta.js index 4de0119a7..315a7c030 100644 --- a/app/soapbox/reducers/meta.js +++ b/app/soapbox/reducers/meta.js @@ -1,31 +1,12 @@ 'use strict'; -import { ME_FETCH_SUCCESS, ME_PATCH_SUCCESS } from 'soapbox/actions/me'; import { INSTANCE_FETCH_FAIL } from 'soapbox/actions/instance'; -import { Map as ImmutableMap, fromJS } from 'immutable'; +import { Map as ImmutableMap } from 'immutable'; const initialState = ImmutableMap(); -const importAccount = (state, account) => { - return state.withMutations(state => { - const accountId = account.get('id'); - - if (account.has('pleroma')) { - const pleroPrefs = account.get('pleroma').delete('settings_store'); - state.setIn(['pleroma', accountId], pleroPrefs); - } - - if (account.has('source')) { - state.setIn(['source', accountId], account.get('source')); - } - }); -}; - export default function meta(state = initialState, action) { switch(action.type) { - case ME_FETCH_SUCCESS: - case ME_PATCH_SUCCESS: - return importAccount(state, fromJS(action.me)); case INSTANCE_FETCH_FAIL: return state.set('instance_fetch_failed', true); default: diff --git a/app/soapbox/selectors/index.js b/app/soapbox/selectors/index.js index faa6ed1b3..60afa8bd8 100644 --- a/app/soapbox/selectors/index.js +++ b/app/soapbox/selectors/index.js @@ -14,6 +14,7 @@ const getAccountBase = (state, id) => state.getIn(['accounts', id], null const getAccountCounters = (state, id) => state.getIn(['accounts_counters', id], null); const getAccountRelationship = (state, id) => state.getIn(['relationships', id], null); const getAccountMoved = (state, id) => state.getIn(['accounts', state.getIn(['accounts', id, 'moved'])]); +const getAccountMeta = (state, id) => state.getIn(['accounts_meta', id], ImmutableMap()); const getAccountAdminData = (state, id) => state.getIn(['admin', 'users', id]); const getAccountPatron = (state, id) => { const url = state.getIn(['accounts', id, 'url']); @@ -26,14 +27,18 @@ export const makeGetAccount = () => { getAccountCounters, getAccountRelationship, getAccountMoved, + getAccountMeta, getAccountAdminData, getAccountPatron, - ], (base, counters, relationship, moved, admin, patron) => { + ], (base, counters, relationship, moved, meta, admin, patron) => { if (base === null) { return null; } - return base.merge(counters).withMutations(map => { + return base.withMutations(map => { + map.merge(counters); + map.merge(meta); + map.set('pleroma', meta.get('pleroma', ImmutableMap()).merge(base.get('pleroma', ImmutableMap()))); // Lol, thanks Pleroma map.set('relationship', relationship); map.set('moved', moved); map.set('patron', patron);