Add accounts_meta reducer to support storing source data for multiple accounts
This commit is contained in:
parent
d2a6a90757
commit
56462d8a9a
|
@ -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));
|
||||
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ const normalizeAccount = (state, account) => {
|
|||
'followers_count',
|
||||
'following_count',
|
||||
'statuses_count',
|
||||
'source',
|
||||
]);
|
||||
|
||||
return state.set(account.id, normalized);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue