Remove unused account reducer... 🤦
This commit is contained in:
parent
32006407a3
commit
c6f179b1be
|
@ -30,7 +30,7 @@ function useAccount(accountId?: string, opts: UseAccountOpts = {}) {
|
||||||
isLoading: isRelationshipLoading,
|
isLoading: isRelationshipLoading,
|
||||||
} = useRelationship(accountId, { enabled: withRelationship });
|
} = useRelationship(accountId, { enabled: withRelationship });
|
||||||
|
|
||||||
const isBlocked = entity?.relationship?.blocked_by === true;
|
const isBlocked = relationship?.blocked_by === true;
|
||||||
const isUnavailable = (me === entity?.id) ? false : (isBlocked && !features.blockersVisible);
|
const isUnavailable = (me === entity?.id) ? false : (isBlocked && !features.blockersVisible);
|
||||||
|
|
||||||
const account = useMemo(
|
const account = useMemo(
|
||||||
|
|
|
@ -31,7 +31,7 @@ function useAccountLookup(acct: string | undefined, opts: UseAccountLookupOpts =
|
||||||
isLoading: isRelationshipLoading,
|
isLoading: isRelationshipLoading,
|
||||||
} = useRelationship(account?.id, { enabled: withRelationship });
|
} = useRelationship(account?.id, { enabled: withRelationship });
|
||||||
|
|
||||||
const isBlocked = account?.relationship?.blocked_by === true;
|
const isBlocked = relationship?.blocked_by === true;
|
||||||
const isUnavailable = (me === account?.id) ? false : (isBlocked && !features.blockersVisible);
|
const isUnavailable = (me === account?.id) ? false : (isBlocked && !features.blockersVisible);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -9,11 +9,10 @@ import {
|
||||||
fromJS,
|
fromJS,
|
||||||
} from 'immutable';
|
} from 'immutable';
|
||||||
|
|
||||||
import type { ReducerAccount } from 'soapbox/reducers/accounts';
|
|
||||||
import type { Account, EmbeddedEntity } from 'soapbox/types/entities';
|
import type { Account, EmbeddedEntity } from 'soapbox/types/entities';
|
||||||
|
|
||||||
export const AdminAccountRecord = ImmutableRecord({
|
export const AdminAccountRecord = ImmutableRecord({
|
||||||
account: null as EmbeddedEntity<Account | ReducerAccount>,
|
account: null as EmbeddedEntity<Account>,
|
||||||
approved: false,
|
approved: false,
|
||||||
confirmed: false,
|
confirmed: false,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
|
|
|
@ -9,21 +9,20 @@ import {
|
||||||
fromJS,
|
fromJS,
|
||||||
} from 'immutable';
|
} from 'immutable';
|
||||||
|
|
||||||
import type { ReducerAccount } from 'soapbox/reducers/accounts';
|
|
||||||
import type { Account, EmbeddedEntity, Status } from 'soapbox/types/entities';
|
import type { Account, EmbeddedEntity, Status } from 'soapbox/types/entities';
|
||||||
|
|
||||||
export const AdminReportRecord = ImmutableRecord({
|
export const AdminReportRecord = ImmutableRecord({
|
||||||
account: null as EmbeddedEntity<Account | ReducerAccount>,
|
account: null as EmbeddedEntity<Account>,
|
||||||
action_taken: false,
|
action_taken: false,
|
||||||
action_taken_by_account: null as EmbeddedEntity<Account | ReducerAccount> | null,
|
action_taken_by_account: null as EmbeddedEntity<Account> | null,
|
||||||
assigned_account: null as EmbeddedEntity<Account | ReducerAccount> | null,
|
assigned_account: null as EmbeddedEntity<Account> | null,
|
||||||
category: '',
|
category: '',
|
||||||
comment: '',
|
comment: '',
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
id: '',
|
id: '',
|
||||||
rules: ImmutableList<string>(),
|
rules: ImmutableList<string>(),
|
||||||
statuses: ImmutableList<EmbeddedEntity<Status>>(),
|
statuses: ImmutableList<EmbeddedEntity<Status>>(),
|
||||||
target_account: null as EmbeddedEntity<Account | ReducerAccount>,
|
target_account: null as EmbeddedEntity<Account>,
|
||||||
updated_at: new Date(),
|
updated_at: new Date(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,10 @@ import { pollSchema } from 'soapbox/schemas';
|
||||||
import { stripCompatibilityFeatures } from 'soapbox/utils/html';
|
import { stripCompatibilityFeatures } from 'soapbox/utils/html';
|
||||||
import { makeEmojiMap } from 'soapbox/utils/normalizers';
|
import { makeEmojiMap } from 'soapbox/utils/normalizers';
|
||||||
|
|
||||||
import type { ReducerAccount } from 'soapbox/reducers/accounts';
|
|
||||||
import type { Account, Attachment, Emoji, EmbeddedEntity, Poll } from 'soapbox/types/entities';
|
import type { Account, Attachment, Emoji, EmbeddedEntity, Poll } from 'soapbox/types/entities';
|
||||||
|
|
||||||
export const StatusEditRecord = ImmutableRecord({
|
export const StatusEditRecord = ImmutableRecord({
|
||||||
account: null as EmbeddedEntity<Account | ReducerAccount>,
|
account: null as EmbeddedEntity<Account>,
|
||||||
content: '',
|
content: '',
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
emojis: ImmutableList<Emoji>(),
|
emojis: ImmutableList<Emoji>(),
|
||||||
|
|
|
@ -1,176 +0,0 @@
|
||||||
import { produce } from 'immer';
|
|
||||||
|
|
||||||
import {
|
|
||||||
ADMIN_USERS_TAG_REQUEST,
|
|
||||||
ADMIN_USERS_TAG_SUCCESS,
|
|
||||||
ADMIN_USERS_TAG_FAIL,
|
|
||||||
ADMIN_USERS_UNTAG_REQUEST,
|
|
||||||
ADMIN_USERS_UNTAG_SUCCESS,
|
|
||||||
ADMIN_USERS_UNTAG_FAIL,
|
|
||||||
ADMIN_ADD_PERMISSION_GROUP_REQUEST,
|
|
||||||
ADMIN_ADD_PERMISSION_GROUP_SUCCESS,
|
|
||||||
ADMIN_ADD_PERMISSION_GROUP_FAIL,
|
|
||||||
ADMIN_REMOVE_PERMISSION_GROUP_REQUEST,
|
|
||||||
ADMIN_REMOVE_PERMISSION_GROUP_SUCCESS,
|
|
||||||
ADMIN_REMOVE_PERMISSION_GROUP_FAIL,
|
|
||||||
ADMIN_USERS_DELETE_REQUEST,
|
|
||||||
ADMIN_USERS_DELETE_FAIL,
|
|
||||||
ADMIN_USERS_DEACTIVATE_REQUEST,
|
|
||||||
ADMIN_USERS_DEACTIVATE_FAIL,
|
|
||||||
} from 'soapbox/actions/admin';
|
|
||||||
import { CHATS_FETCH_SUCCESS, CHATS_EXPAND_SUCCESS, CHAT_FETCH_SUCCESS } from 'soapbox/actions/chats';
|
|
||||||
import {
|
|
||||||
ACCOUNT_IMPORT,
|
|
||||||
ACCOUNTS_IMPORT,
|
|
||||||
ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP,
|
|
||||||
} from 'soapbox/actions/importer';
|
|
||||||
import { STREAMING_CHAT_UPDATE } from 'soapbox/actions/streaming';
|
|
||||||
import { Account, accountSchema } from 'soapbox/schemas';
|
|
||||||
|
|
||||||
import type { AnyAction } from 'redux';
|
|
||||||
|
|
||||||
export interface ReducerAccount extends Omit<Account, 'moved'> {
|
|
||||||
moved: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
type State = Record<string, ReducerAccount>;
|
|
||||||
|
|
||||||
const initialState: State = {};
|
|
||||||
|
|
||||||
/** Convert sub-entities into string IDs (or null). */
|
|
||||||
function minifyAccount(account: Account): ReducerAccount {
|
|
||||||
return { ...account, moved: account.moved?.id ?? null };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Parse account data, and import valid accounts into the state. */
|
|
||||||
function fixAccount(state: State, data: unknown): State {
|
|
||||||
const result = accountSchema.safeParse(data);
|
|
||||||
|
|
||||||
if (!result.success) {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
const account = result.data;
|
|
||||||
const normalized = minifyAccount(account);
|
|
||||||
|
|
||||||
return { ...state, [normalized.id]: normalized };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Import valid accounts into the state. */
|
|
||||||
function normalizeAccounts(state: State, data: unknown[]): State {
|
|
||||||
return produce(state, draft => {
|
|
||||||
data.forEach((item) => fixAccount(draft, item));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function importAccountFromChat(state: State, chat: any): State {
|
|
||||||
return fixAccount(state, chat.account);
|
|
||||||
}
|
|
||||||
|
|
||||||
function importAccountsFromChats(state: State, chats: unknown[]): State {
|
|
||||||
return produce(state, draft => {
|
|
||||||
chats.forEach(chat => importAccountFromChat(draft, chat));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function addTags(state: State, accountIds: string[], tags: string[]): State {
|
|
||||||
return produce(state, draft => {
|
|
||||||
for (const id of accountIds) {
|
|
||||||
const account = draft[id];
|
|
||||||
if (!account) continue;
|
|
||||||
|
|
||||||
const tagSet = new Set([...account.pleroma.tags, ...tags]);
|
|
||||||
account.pleroma.tags = [...tagSet];
|
|
||||||
|
|
||||||
if (tagSet.has('verified')) {
|
|
||||||
account.verified = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeTags (state: State, accountIds: string[], tags: string[]): State {
|
|
||||||
return produce(state, draft => {
|
|
||||||
for (const id of accountIds) {
|
|
||||||
const account = draft[id];
|
|
||||||
if (!account) continue;
|
|
||||||
|
|
||||||
const tagSet = new Set(account.pleroma.tags).difference(new Set(tags));
|
|
||||||
account.pleroma.tags = [...tagSet];
|
|
||||||
|
|
||||||
if (tagSet.has('verified')) {
|
|
||||||
account.verified = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function setActive(state: State, accountIds: Array<string>, active: boolean): State {
|
|
||||||
return produce(state, draft => {
|
|
||||||
for (const id of accountIds) {
|
|
||||||
const account = draft[id];
|
|
||||||
if (!account) continue;
|
|
||||||
|
|
||||||
account.pleroma.deactivated = !active;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function setPermission(state: State, accountIds: string[], permissionGroup: string, value: boolean): State {
|
|
||||||
return produce(state, draft => {
|
|
||||||
for (const id of accountIds) {
|
|
||||||
const account = draft[id];
|
|
||||||
if (!account) continue;
|
|
||||||
|
|
||||||
switch (permissionGroup) {
|
|
||||||
case 'admin':
|
|
||||||
account.pleroma.is_admin = value;
|
|
||||||
break;
|
|
||||||
case 'moderator':
|
|
||||||
account.pleroma.is_moderator = value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function accounts(state: State = initialState, action: AnyAction): State {
|
|
||||||
switch (action.type) {
|
|
||||||
case ACCOUNT_IMPORT:
|
|
||||||
return fixAccount(state, action.account);
|
|
||||||
case ACCOUNTS_IMPORT:
|
|
||||||
return normalizeAccounts(state, action.accounts);
|
|
||||||
case ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP:
|
|
||||||
return fixAccount(state, { id: -1, username: action.username });
|
|
||||||
case CHATS_FETCH_SUCCESS:
|
|
||||||
case CHATS_EXPAND_SUCCESS:
|
|
||||||
return importAccountsFromChats(state, action.chats);
|
|
||||||
case CHAT_FETCH_SUCCESS:
|
|
||||||
case STREAMING_CHAT_UPDATE:
|
|
||||||
return importAccountsFromChats(state, [action.chat]);
|
|
||||||
case ADMIN_USERS_TAG_REQUEST:
|
|
||||||
case ADMIN_USERS_TAG_SUCCESS:
|
|
||||||
case ADMIN_USERS_UNTAG_FAIL:
|
|
||||||
return addTags(state, action.accountIds, action.tags);
|
|
||||||
case ADMIN_USERS_UNTAG_REQUEST:
|
|
||||||
case ADMIN_USERS_UNTAG_SUCCESS:
|
|
||||||
case ADMIN_USERS_TAG_FAIL:
|
|
||||||
return removeTags(state, action.accountIds, action.tags);
|
|
||||||
case ADMIN_ADD_PERMISSION_GROUP_REQUEST:
|
|
||||||
case ADMIN_ADD_PERMISSION_GROUP_SUCCESS:
|
|
||||||
case ADMIN_REMOVE_PERMISSION_GROUP_FAIL:
|
|
||||||
return setPermission(state, action.accountIds, action.permissionGroup, true);
|
|
||||||
case ADMIN_REMOVE_PERMISSION_GROUP_REQUEST:
|
|
||||||
case ADMIN_REMOVE_PERMISSION_GROUP_SUCCESS:
|
|
||||||
case ADMIN_ADD_PERMISSION_GROUP_FAIL:
|
|
||||||
return setPermission(state, action.accountIds, action.permissionGroup, false);
|
|
||||||
case ADMIN_USERS_DELETE_REQUEST:
|
|
||||||
case ADMIN_USERS_DEACTIVATE_REQUEST:
|
|
||||||
return setActive(state, action.accountIds, false);
|
|
||||||
case ADMIN_USERS_DELETE_FAIL:
|
|
||||||
case ADMIN_USERS_DEACTIVATE_FAIL:
|
|
||||||
return setActive(state, action.accountIds, true);
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,6 +7,7 @@ import emojify from 'soapbox/features/emoji';
|
||||||
import { unescapeHTML } from 'soapbox/utils/html';
|
import { unescapeHTML } from 'soapbox/utils/html';
|
||||||
|
|
||||||
import { customEmojiSchema } from './custom-emoji';
|
import { customEmojiSchema } from './custom-emoji';
|
||||||
|
import { Relationship } from './relationship';
|
||||||
import { coerceObject, contentSchema, filteredArray, makeCustomEmojiMap } from './utils';
|
import { coerceObject, contentSchema, filteredArray, makeCustomEmojiMap } from './utils';
|
||||||
|
|
||||||
import type { Resolve } from 'soapbox/utils/types';
|
import type { Resolve } from 'soapbox/utils/types';
|
||||||
|
@ -180,6 +181,9 @@ const accountSchema = baseAccountSchema.extend({
|
||||||
moved: baseAccountSchema.transform(transformAccount).nullable().catch(null),
|
moved: baseAccountSchema.transform(transformAccount).nullable().catch(null),
|
||||||
}).transform(transformAccount);
|
}).transform(transformAccount);
|
||||||
|
|
||||||
type Account = Resolve<z.infer<typeof accountSchema>>;
|
type Account = Resolve<z.infer<typeof accountSchema>> & {
|
||||||
|
// FIXME: decouple these in components.
|
||||||
|
relationship?: Relationship;
|
||||||
|
}
|
||||||
|
|
||||||
export { accountSchema, type Account };
|
export { accountSchema, type Account };
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
import { AccountRecord } from 'soapbox/normalizers';
|
|
||||||
|
|
||||||
import {
|
|
||||||
getDomain,
|
|
||||||
} from './accounts';
|
|
||||||
|
|
||||||
import type { ReducerAccount } from 'soapbox/reducers/accounts';
|
|
||||||
|
|
||||||
describe('getDomain', () => {
|
|
||||||
const account = AccountRecord({
|
|
||||||
acct: 'alice',
|
|
||||||
url: 'https://party.com/users/alice',
|
|
||||||
}) as ReducerAccount;
|
|
||||||
it('returns the domain', () => {
|
|
||||||
expect(getDomain(account)).toEqual('party.com');
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Reference in New Issue