2021-09-26 12:46:13 +09:00
|
|
|
import { Map as ImmutableMap } from 'immutable';
|
|
|
|
|
2023-05-24 00:15:17 +09:00
|
|
|
import { ACCOUNT_LOOKUP_FAIL } from '../actions/accounts';
|
2023-11-04 00:00:03 +09:00
|
|
|
import { importAccounts } from '../actions/accounts_typed';
|
2024-01-03 00:02:25 +09:00
|
|
|
import { domain } from '../initial_state';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
2024-09-17 23:59:29 +09:00
|
|
|
const pattern = new RegExp(`@${domain}$`, 'gi');
|
|
|
|
|
|
|
|
export const normalizeForLookup = str =>
|
|
|
|
str.toLowerCase().replace(pattern, '');
|
2022-10-21 17:06:03 +09:00
|
|
|
|
2021-09-26 12:46:13 +09:00
|
|
|
const initialState = ImmutableMap();
|
|
|
|
|
|
|
|
export default function accountsMap(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
2022-11-28 04:48:12 +09:00
|
|
|
case ACCOUNT_LOOKUP_FAIL:
|
|
|
|
return action.error?.response?.status === 404 ? state.set(normalizeForLookup(action.acct), null) : state;
|
2023-11-04 00:00:03 +09:00
|
|
|
case importAccounts.type:
|
|
|
|
return state.withMutations(map => action.payload.accounts.forEach(account => map.set(normalizeForLookup(account.acct), account.id)));
|
2021-09-26 12:46:13 +09:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2022-12-19 00:51:37 +09:00
|
|
|
}
|