Merge branch 'develop' into hooks-migration
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
@ -1,42 +1,14 @@
|
||||
import { importEntities } from 'pl-fe/entity-store/actions';
|
||||
import { Entities } from 'pl-fe/entity-store/entities';
|
||||
|
||||
import { getClient } from '../api';
|
||||
|
||||
import type { RootState } from 'pl-fe/store';
|
||||
import type { AnyAction } from 'redux';
|
||||
|
||||
const ACCOUNT_NOTE_SUBMIT_REQUEST = 'ACCOUNT_NOTE_SUBMIT_REQUEST' as const;
|
||||
const ACCOUNT_NOTE_SUBMIT_SUCCESS = 'ACCOUNT_NOTE_SUBMIT_SUCCESS' as const;
|
||||
const ACCOUNT_NOTE_SUBMIT_FAIL = 'ACCOUNT_NOTE_SUBMIT_FAIL' as const;
|
||||
|
||||
const submitAccountNote = (accountId: string, value: string) =>
|
||||
(dispatch: React.Dispatch<AnyAction>, getState: () => RootState) => {
|
||||
dispatch(submitAccountNoteRequest(accountId));
|
||||
(dispatch: React.Dispatch<AnyAction>, getState: () => RootState) =>
|
||||
getClient(getState).accounts.updateAccountNote(accountId, value)
|
||||
.then(response => dispatch(importEntities([response], Entities.RELATIONSHIPS)));
|
||||
|
||||
return getClient(getState).accounts.updateAccountNote(accountId, value)
|
||||
.then(response => {
|
||||
dispatch(submitAccountNoteSuccess(response));
|
||||
}).catch(error => dispatch(submitAccountNoteFail(accountId, error)));
|
||||
};
|
||||
|
||||
const submitAccountNoteRequest = (accountId: string) => ({
|
||||
type: ACCOUNT_NOTE_SUBMIT_REQUEST,
|
||||
accountId,
|
||||
});
|
||||
|
||||
const submitAccountNoteSuccess = (relationship: any) => ({
|
||||
type: ACCOUNT_NOTE_SUBMIT_SUCCESS,
|
||||
accountId: relationship.id,
|
||||
relationship,
|
||||
});
|
||||
|
||||
const submitAccountNoteFail = (accountId: string, error: unknown) => ({
|
||||
type: ACCOUNT_NOTE_SUBMIT_FAIL,
|
||||
accountId,
|
||||
error,
|
||||
});
|
||||
|
||||
export {
|
||||
submitAccountNote,
|
||||
ACCOUNT_NOTE_SUBMIT_REQUEST,
|
||||
ACCOUNT_NOTE_SUBMIT_SUCCESS,
|
||||
ACCOUNT_NOTE_SUBMIT_FAIL,
|
||||
};
|
||||
export { submitAccountNote };
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { PLEROMA, type UpdateNotificationSettingsParams, type Account, type CreateAccountParams, type PaginatedResponse, type Relationship } from 'pl-api';
|
||||
|
||||
import { Entities } from 'pl-fe/entity-store/entities';
|
||||
import { importEntities } from 'pl-fe/pl-hooks/importer';
|
||||
import { selectAccount } from 'pl-fe/selectors';
|
||||
import { isLoggedIn } from 'pl-fe/utils/auth';
|
||||
@ -23,30 +24,10 @@ const ACCOUNT_BLOCK_REQUEST = 'ACCOUNT_BLOCK_REQUEST' as const;
|
||||
const ACCOUNT_BLOCK_SUCCESS = 'ACCOUNT_BLOCK_SUCCESS' as const;
|
||||
const ACCOUNT_BLOCK_FAIL = 'ACCOUNT_BLOCK_FAIL' as const;
|
||||
|
||||
const ACCOUNT_UNBLOCK_REQUEST = 'ACCOUNT_UNBLOCK_REQUEST' as const;
|
||||
const ACCOUNT_UNBLOCK_SUCCESS = 'ACCOUNT_UNBLOCK_SUCCESS' as const;
|
||||
const ACCOUNT_UNBLOCK_FAIL = 'ACCOUNT_UNBLOCK_FAIL' as const;
|
||||
|
||||
const ACCOUNT_MUTE_REQUEST = 'ACCOUNT_MUTE_REQUEST' as const;
|
||||
const ACCOUNT_MUTE_SUCCESS = 'ACCOUNT_MUTE_SUCCESS' as const;
|
||||
const ACCOUNT_MUTE_FAIL = 'ACCOUNT_MUTE_FAIL' as const;
|
||||
|
||||
const ACCOUNT_UNMUTE_REQUEST = 'ACCOUNT_UNMUTE_REQUEST' as const;
|
||||
const ACCOUNT_UNMUTE_SUCCESS = 'ACCOUNT_UNMUTE_SUCCESS' as const;
|
||||
const ACCOUNT_UNMUTE_FAIL = 'ACCOUNT_UNMUTE_FAIL' as const;
|
||||
|
||||
const ACCOUNT_PIN_REQUEST = 'ACCOUNT_PIN_REQUEST' as const;
|
||||
const ACCOUNT_PIN_SUCCESS = 'ACCOUNT_PIN_SUCCESS' as const;
|
||||
const ACCOUNT_PIN_FAIL = 'ACCOUNT_PIN_FAIL' as const;
|
||||
|
||||
const ACCOUNT_UNPIN_REQUEST = 'ACCOUNT_UNPIN_REQUEST' as const;
|
||||
const ACCOUNT_UNPIN_SUCCESS = 'ACCOUNT_UNPIN_SUCCESS' as const;
|
||||
const ACCOUNT_UNPIN_FAIL = 'ACCOUNT_UNPIN_FAIL' as const;
|
||||
|
||||
const ACCOUNT_REMOVE_FROM_FOLLOWERS_REQUEST = 'ACCOUNT_REMOVE_FROM_FOLLOWERS_REQUEST' as const;
|
||||
const ACCOUNT_REMOVE_FROM_FOLLOWERS_SUCCESS = 'ACCOUNT_REMOVE_FROM_FOLLOWERS_SUCCESS' as const;
|
||||
const ACCOUNT_REMOVE_FROM_FOLLOWERS_FAIL = 'ACCOUNT_REMOVE_FROM_FOLLOWERS_FAIL' as const;
|
||||
|
||||
const PINNED_ACCOUNTS_FETCH_REQUEST = 'PINNED_ACCOUNTS_FETCH_REQUEST' as const;
|
||||
const PINNED_ACCOUNTS_FETCH_SUCCESS = 'PINNED_ACCOUNTS_FETCH_SUCCESS' as const;
|
||||
const PINNED_ACCOUNTS_FETCH_FAIL = 'PINNED_ACCOUNTS_FETCH_FAIL' as const;
|
||||
@ -59,10 +40,6 @@ const ACCOUNT_LOOKUP_REQUEST = 'ACCOUNT_LOOKUP_REQUEST' as const;
|
||||
const ACCOUNT_LOOKUP_SUCCESS = 'ACCOUNT_LOOKUP_SUCCESS' as const;
|
||||
const ACCOUNT_LOOKUP_FAIL = 'ACCOUNT_LOOKUP_FAIL' as const;
|
||||
|
||||
const RELATIONSHIPS_FETCH_REQUEST = 'RELATIONSHIPS_FETCH_REQUEST' as const;
|
||||
const RELATIONSHIPS_FETCH_SUCCESS = 'RELATIONSHIPS_FETCH_SUCCESS' as const;
|
||||
const RELATIONSHIPS_FETCH_FAIL = 'RELATIONSHIPS_FETCH_FAIL' as const;
|
||||
|
||||
const FOLLOW_REQUESTS_FETCH_REQUEST = 'FOLLOW_REQUESTS_FETCH_REQUEST' as const;
|
||||
const FOLLOW_REQUESTS_FETCH_SUCCESS = 'FOLLOW_REQUESTS_FETCH_SUCCESS' as const;
|
||||
const FOLLOW_REQUESTS_FETCH_FAIL = 'FOLLOW_REQUESTS_FETCH_FAIL' as const;
|
||||
@ -87,10 +64,6 @@ const BIRTHDAY_REMINDERS_FETCH_REQUEST = 'BIRTHDAY_REMINDERS_FETCH_REQUEST' as c
|
||||
const BIRTHDAY_REMINDERS_FETCH_SUCCESS = 'BIRTHDAY_REMINDERS_FETCH_SUCCESS' as const;
|
||||
const BIRTHDAY_REMINDERS_FETCH_FAIL = 'BIRTHDAY_REMINDERS_FETCH_FAIL' as const;
|
||||
|
||||
const ACCOUNT_BITE_REQUEST = 'ACCOUNT_BITE_REQUEST' as const;
|
||||
const ACCOUNT_BITE_SUCCESS = 'ACCOUNT_BITE_SUCCESS' as const;
|
||||
const ACCOUNT_BITE_FAIL = 'ACCOUNT_BITE_FAIL' as const;
|
||||
|
||||
const maybeRedirectLogin = (error: { response: PlfeResponse }, history?: History) => {
|
||||
// The client is unauthorized - redirect to login.
|
||||
if (history && error?.response?.status === 401) {
|
||||
@ -205,14 +178,8 @@ const unblockAccount = (accountId: string) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
if (!isLoggedIn(getState)) return null;
|
||||
|
||||
dispatch(unblockAccountRequest(accountId));
|
||||
|
||||
return getClient(getState).filtering.unblockAccount(accountId)
|
||||
.then(response => {
|
||||
importEntities({ relationships: [response] });
|
||||
return dispatch(unblockAccountSuccess(response));
|
||||
})
|
||||
.catch(error => dispatch(unblockAccountFail(error)));
|
||||
.then(response => importEntities({ relationships: [response] }));
|
||||
};
|
||||
|
||||
const blockAccountRequest = (accountId: string) => ({
|
||||
@ -231,21 +198,6 @@ const blockAccountFail = (error: unknown) => ({
|
||||
error,
|
||||
});
|
||||
|
||||
const unblockAccountRequest = (accountId: string) => ({
|
||||
type: ACCOUNT_UNBLOCK_REQUEST,
|
||||
accountId,
|
||||
});
|
||||
|
||||
const unblockAccountSuccess = (relationship: Relationship) => ({
|
||||
type: ACCOUNT_UNBLOCK_SUCCESS,
|
||||
relationship,
|
||||
});
|
||||
|
||||
const unblockAccountFail = (error: unknown) => ({
|
||||
type: ACCOUNT_UNBLOCK_FAIL,
|
||||
error,
|
||||
});
|
||||
|
||||
const muteAccount = (accountId: string, notifications?: boolean, duration = 0) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
if (!isLoggedIn(getState)) return null;
|
||||
@ -281,14 +233,8 @@ const unmuteAccount = (accountId: string) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
if (!isLoggedIn(getState)) return null;
|
||||
|
||||
dispatch(unmuteAccountRequest(accountId));
|
||||
|
||||
return getClient(getState()).filtering.unmuteAccount(accountId)
|
||||
.then(response => {
|
||||
importEntities({ relationships: [response] });
|
||||
return dispatch(unmuteAccountSuccess(response));
|
||||
})
|
||||
.catch(error => dispatch(unmuteAccountFail(accountId, error)));
|
||||
.then(response => importEntities({ relationships: [response] }));
|
||||
};
|
||||
|
||||
const muteAccountRequest = (accountId: string) => ({
|
||||
@ -308,85 +254,29 @@ const muteAccountFail = (accountId: string, error: unknown) => ({
|
||||
error,
|
||||
});
|
||||
|
||||
const unmuteAccountRequest = (accountId: string) => ({
|
||||
type: ACCOUNT_UNMUTE_REQUEST,
|
||||
accountId,
|
||||
});
|
||||
|
||||
const unmuteAccountSuccess = (relationship: Relationship) => ({
|
||||
type: ACCOUNT_UNMUTE_SUCCESS,
|
||||
relationship,
|
||||
});
|
||||
|
||||
const unmuteAccountFail = (accountId: string, error: unknown) => ({
|
||||
type: ACCOUNT_UNMUTE_FAIL,
|
||||
accountId,
|
||||
error,
|
||||
});
|
||||
|
||||
const removeFromFollowers = (accountId: string) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
if (!isLoggedIn(getState)) return null;
|
||||
|
||||
dispatch(removeFromFollowersRequest(accountId));
|
||||
|
||||
return getClient(getState()).accounts.removeAccountFromFollowers(accountId)
|
||||
.then(response => dispatch(removeFromFollowersSuccess(response)))
|
||||
.catch(error => dispatch(removeFromFollowersFail(accountId, error)));
|
||||
.then(response => importEntities({ relationships: [response] }));
|
||||
};
|
||||
|
||||
const removeFromFollowersRequest = (accountId: string) => ({
|
||||
type: ACCOUNT_REMOVE_FROM_FOLLOWERS_REQUEST,
|
||||
accountId,
|
||||
});
|
||||
|
||||
const removeFromFollowersSuccess = (relationship: Relationship) => ({
|
||||
type: ACCOUNT_REMOVE_FROM_FOLLOWERS_SUCCESS,
|
||||
relationship,
|
||||
});
|
||||
|
||||
const removeFromFollowersFail = (accountId: string, error: unknown) => ({
|
||||
type: ACCOUNT_REMOVE_FROM_FOLLOWERS_FAIL,
|
||||
accountId,
|
||||
error,
|
||||
});
|
||||
|
||||
const fetchRelationships = (accountIds: string[]) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
if (!isLoggedIn(getState)) return null;
|
||||
|
||||
const loadedRelationships = getState().relationships;
|
||||
const newAccountIds = accountIds.filter(id => loadedRelationships.get(id, null) === null);
|
||||
const loadedRelationships = getState().entities[Entities.RELATIONSHIPS]?.store;
|
||||
const newAccountIds = accountIds.filter(id => !loadedRelationships?.[id]);
|
||||
|
||||
if (newAccountIds.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
dispatch(fetchRelationshipsRequest(newAccountIds));
|
||||
|
||||
return getClient(getState()).accounts.getRelationships(newAccountIds)
|
||||
.then(response => {
|
||||
importEntities({ relationships: response });
|
||||
dispatch(fetchRelationshipsSuccess(response));
|
||||
})
|
||||
.catch(error => dispatch(fetchRelationshipsFail(error)));
|
||||
.then(response => importEntities({ relationships: response }));
|
||||
};
|
||||
|
||||
const fetchRelationshipsRequest = (accountIds: string[]) => ({
|
||||
type: RELATIONSHIPS_FETCH_REQUEST,
|
||||
accountIds,
|
||||
});
|
||||
|
||||
const fetchRelationshipsSuccess = (relationships: Array<Relationship>) => ({
|
||||
type: RELATIONSHIPS_FETCH_SUCCESS,
|
||||
relationships,
|
||||
});
|
||||
|
||||
const fetchRelationshipsFail = (error: unknown) => ({
|
||||
type: RELATIONSHIPS_FETCH_FAIL,
|
||||
error,
|
||||
});
|
||||
|
||||
const fetchFollowRequests = () =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
if (!isLoggedIn(getState)) return null;
|
||||
@ -505,26 +395,16 @@ const pinAccount = (accountId: string) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
if (!isLoggedIn(getState)) return dispatch(noOp);
|
||||
|
||||
dispatch(pinAccountRequest(accountId));
|
||||
|
||||
return getClient(getState).accounts.pinAccount(accountId).then(response => {
|
||||
dispatch(pinAccountSuccess(response));
|
||||
}).catch(error => {
|
||||
dispatch(pinAccountFail(error));
|
||||
});
|
||||
return getClient(getState).accounts.pinAccount(accountId)
|
||||
.then(response => importEntities({ relationships: [response] }));
|
||||
};
|
||||
|
||||
const unpinAccount = (accountId: string) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
if (!isLoggedIn(getState)) return dispatch(noOp);
|
||||
|
||||
dispatch(unpinAccountRequest(accountId));
|
||||
|
||||
return getClient(getState).accounts.unpinAccount(accountId).then(response => {
|
||||
dispatch(unpinAccountSuccess(response));
|
||||
}).catch(error => {
|
||||
dispatch(unpinAccountFail(error));
|
||||
});
|
||||
return getClient(getState).accounts.unpinAccount(accountId)
|
||||
.then(response => importEntities({ relationships: [response] }));
|
||||
};
|
||||
|
||||
const updateNotificationSettings = (params: UpdateNotificationSettingsParams) =>
|
||||
@ -538,36 +418,6 @@ const updateNotificationSettings = (params: UpdateNotificationSettingsParams) =>
|
||||
});
|
||||
};
|
||||
|
||||
const pinAccountRequest = (accountId: string) => ({
|
||||
type: ACCOUNT_PIN_REQUEST,
|
||||
accountId,
|
||||
});
|
||||
|
||||
const pinAccountSuccess = (relationship: Relationship) => ({
|
||||
type: ACCOUNT_PIN_SUCCESS,
|
||||
relationship,
|
||||
});
|
||||
|
||||
const pinAccountFail = (error: unknown) => ({
|
||||
type: ACCOUNT_PIN_FAIL,
|
||||
error,
|
||||
});
|
||||
|
||||
const unpinAccountRequest = (accountId: string) => ({
|
||||
type: ACCOUNT_UNPIN_REQUEST,
|
||||
accountId,
|
||||
});
|
||||
|
||||
const unpinAccountSuccess = (relationship: Relationship) => ({
|
||||
type: ACCOUNT_UNPIN_SUCCESS,
|
||||
relationship,
|
||||
});
|
||||
|
||||
const unpinAccountFail = (error: unknown) => ({
|
||||
type: ACCOUNT_UNPIN_FAIL,
|
||||
error,
|
||||
});
|
||||
|
||||
const fetchPinnedAccounts = (accountId: string) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
dispatch(fetchPinnedAccountsRequest(accountId));
|
||||
@ -650,33 +500,9 @@ const biteAccount = (accountId: string) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
const client = getClient(getState);
|
||||
|
||||
dispatch(biteAccountRequest(accountId));
|
||||
|
||||
return client.accounts.biteAccount(accountId)
|
||||
.then(() => {
|
||||
return dispatch(biteAccountSuccess(accountId));
|
||||
})
|
||||
.catch(error => {
|
||||
dispatch(biteAccountFail(accountId, error));
|
||||
throw error;
|
||||
});
|
||||
return client.accounts.biteAccount(accountId);
|
||||
};
|
||||
|
||||
const biteAccountRequest = (accountId: string) => ({
|
||||
type: ACCOUNT_BITE_REQUEST,
|
||||
accountId,
|
||||
});
|
||||
|
||||
const biteAccountSuccess = (accountId: string) => ({
|
||||
type: ACCOUNT_BITE_SUCCESS,
|
||||
});
|
||||
|
||||
const biteAccountFail = (accountId: string, error: unknown) => ({
|
||||
type: ACCOUNT_BITE_FAIL,
|
||||
accountId,
|
||||
error,
|
||||
});
|
||||
|
||||
export {
|
||||
ACCOUNT_CREATE_REQUEST,
|
||||
ACCOUNT_CREATE_SUCCESS,
|
||||
@ -687,24 +513,9 @@ export {
|
||||
ACCOUNT_BLOCK_REQUEST,
|
||||
ACCOUNT_BLOCK_SUCCESS,
|
||||
ACCOUNT_BLOCK_FAIL,
|
||||
ACCOUNT_UNBLOCK_REQUEST,
|
||||
ACCOUNT_UNBLOCK_SUCCESS,
|
||||
ACCOUNT_UNBLOCK_FAIL,
|
||||
ACCOUNT_MUTE_REQUEST,
|
||||
ACCOUNT_MUTE_SUCCESS,
|
||||
ACCOUNT_MUTE_FAIL,
|
||||
ACCOUNT_UNMUTE_REQUEST,
|
||||
ACCOUNT_UNMUTE_SUCCESS,
|
||||
ACCOUNT_UNMUTE_FAIL,
|
||||
ACCOUNT_PIN_REQUEST,
|
||||
ACCOUNT_PIN_SUCCESS,
|
||||
ACCOUNT_PIN_FAIL,
|
||||
ACCOUNT_UNPIN_REQUEST,
|
||||
ACCOUNT_UNPIN_SUCCESS,
|
||||
ACCOUNT_UNPIN_FAIL,
|
||||
ACCOUNT_REMOVE_FROM_FOLLOWERS_REQUEST,
|
||||
ACCOUNT_REMOVE_FROM_FOLLOWERS_SUCCESS,
|
||||
ACCOUNT_REMOVE_FROM_FOLLOWERS_FAIL,
|
||||
PINNED_ACCOUNTS_FETCH_REQUEST,
|
||||
PINNED_ACCOUNTS_FETCH_SUCCESS,
|
||||
PINNED_ACCOUNTS_FETCH_FAIL,
|
||||
@ -714,9 +525,6 @@ export {
|
||||
ACCOUNT_LOOKUP_REQUEST,
|
||||
ACCOUNT_LOOKUP_SUCCESS,
|
||||
ACCOUNT_LOOKUP_FAIL,
|
||||
RELATIONSHIPS_FETCH_REQUEST,
|
||||
RELATIONSHIPS_FETCH_SUCCESS,
|
||||
RELATIONSHIPS_FETCH_FAIL,
|
||||
FOLLOW_REQUESTS_FETCH_REQUEST,
|
||||
FOLLOW_REQUESTS_FETCH_SUCCESS,
|
||||
FOLLOW_REQUESTS_FETCH_FAIL,
|
||||
@ -735,9 +543,6 @@ export {
|
||||
BIRTHDAY_REMINDERS_FETCH_REQUEST,
|
||||
BIRTHDAY_REMINDERS_FETCH_SUCCESS,
|
||||
BIRTHDAY_REMINDERS_FETCH_FAIL,
|
||||
ACCOUNT_BITE_REQUEST,
|
||||
ACCOUNT_BITE_SUCCESS,
|
||||
ACCOUNT_BITE_FAIL,
|
||||
createAccount,
|
||||
fetchAccount,
|
||||
fetchAccountByUsername,
|
||||
@ -749,25 +554,13 @@ export {
|
||||
blockAccountRequest,
|
||||
blockAccountSuccess,
|
||||
blockAccountFail,
|
||||
unblockAccountRequest,
|
||||
unblockAccountSuccess,
|
||||
unblockAccountFail,
|
||||
muteAccount,
|
||||
unmuteAccount,
|
||||
muteAccountRequest,
|
||||
muteAccountSuccess,
|
||||
muteAccountFail,
|
||||
unmuteAccountRequest,
|
||||
unmuteAccountSuccess,
|
||||
unmuteAccountFail,
|
||||
removeFromFollowers,
|
||||
removeFromFollowersRequest,
|
||||
removeFromFollowersSuccess,
|
||||
removeFromFollowersFail,
|
||||
fetchRelationships,
|
||||
fetchRelationshipsRequest,
|
||||
fetchRelationshipsSuccess,
|
||||
fetchRelationshipsFail,
|
||||
fetchFollowRequests,
|
||||
fetchFollowRequestsRequest,
|
||||
fetchFollowRequestsSuccess,
|
||||
@ -787,12 +580,6 @@ export {
|
||||
pinAccount,
|
||||
unpinAccount,
|
||||
updateNotificationSettings,
|
||||
pinAccountRequest,
|
||||
pinAccountSuccess,
|
||||
pinAccountFail,
|
||||
unpinAccountRequest,
|
||||
unpinAccountSuccess,
|
||||
unpinAccountFail,
|
||||
fetchPinnedAccounts,
|
||||
fetchPinnedAccountsRequest,
|
||||
fetchPinnedAccountsSuccess,
|
||||
@ -801,7 +588,4 @@ export {
|
||||
accountLookup,
|
||||
fetchBirthdayReminders,
|
||||
biteAccount,
|
||||
biteAccountRequest,
|
||||
biteAccountSuccess,
|
||||
biteAccountFail,
|
||||
};
|
||||
|
||||
@ -31,6 +31,7 @@ const blockDomain = (domain: string) =>
|
||||
dispatch(blockDomainRequest(domain));
|
||||
|
||||
return getClient(getState).filtering.blockDomain(domain).then(() => {
|
||||
// TODO: Update relationships on block
|
||||
const accounts = selectAccountsByDomain(getState(), domain);
|
||||
if (!accounts) return;
|
||||
dispatch(blockDomainSuccess(domain, accounts));
|
||||
@ -63,6 +64,7 @@ const unblockDomain = (domain: string) =>
|
||||
dispatch(unblockDomainRequest(domain));
|
||||
|
||||
return getClient(getState).filtering.unblockDomain(domain).then(() => {
|
||||
// TODO: Update relationships on unblock
|
||||
const accounts = selectAccountsByDomain(getState(), domain);
|
||||
if (!accounts) return;
|
||||
dispatch(unblockDomainSuccess(domain, accounts));
|
||||
|
||||
@ -5,8 +5,6 @@ import { normalizeAccount, normalizeGroup, type Account, type Group } from 'pl-f
|
||||
import type { Account as BaseAccount, Group as BaseGroup, Poll, Status as BaseStatus } from 'pl-api';
|
||||
import type { AppDispatch } from 'pl-fe/store';
|
||||
|
||||
const ACCOUNT_IMPORT = 'ACCOUNT_IMPORT';
|
||||
const ACCOUNTS_IMPORT = 'ACCOUNTS_IMPORT';
|
||||
const STATUS_IMPORT = 'STATUS_IMPORT';
|
||||
const STATUSES_IMPORT = 'STATUSES_IMPORT';
|
||||
const POLLS_IMPORT = 'POLLS_IMPORT';
|
||||
@ -157,8 +155,6 @@ const importFetchedPoll = (poll: Poll) =>
|
||||
};
|
||||
|
||||
export {
|
||||
ACCOUNT_IMPORT,
|
||||
ACCOUNTS_IMPORT,
|
||||
STATUS_IMPORT,
|
||||
STATUSES_IMPORT,
|
||||
POLLS_IMPORT,
|
||||
|
||||
@ -1,22 +1,14 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
|
||||
import { fetchRelationshipsFail, fetchRelationshipsSuccess } from 'pl-fe/actions/accounts';
|
||||
import { useAppDispatch, useClient } from 'pl-fe/hooks';
|
||||
import { useClient } from 'pl-fe/hooks';
|
||||
|
||||
const useFetchRelationships = () => {
|
||||
const client = useClient();
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ accountIds }: { accountIds: string[]}) => {
|
||||
return client.accounts.getRelationships(accountIds);
|
||||
},
|
||||
onSuccess(response) {
|
||||
dispatch(fetchRelationshipsSuccess(response));
|
||||
},
|
||||
onError(error) {
|
||||
dispatch(fetchRelationshipsFail(error));
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -35,7 +35,6 @@ import plfe from './pl-fe';
|
||||
import polls from './polls';
|
||||
import profile_hover_card from './profile-hover-card';
|
||||
import push_notifications from './push-notifications';
|
||||
import relationships from './relationships';
|
||||
import scheduled_statuses from './scheduled-statuses';
|
||||
import search from './search';
|
||||
import security from './security';
|
||||
@ -83,7 +82,6 @@ const reducers = {
|
||||
polls,
|
||||
profile_hover_card,
|
||||
push_notifications,
|
||||
relationships,
|
||||
scheduled_statuses,
|
||||
search,
|
||||
security,
|
||||
|
||||
@ -1,40 +0,0 @@
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
|
||||
import lain from 'pl-fe/__fixtures__/lain.json';
|
||||
import { ACCOUNT_IMPORT } from 'pl-fe/actions/importer';
|
||||
|
||||
import reducer from './relationships';
|
||||
|
||||
describe('relationships reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {} as any)).toEqual(ImmutableMap());
|
||||
});
|
||||
|
||||
describe('ACCOUNT_IMPORT', () => {
|
||||
it('should import the relationship', () => {
|
||||
const action = {
|
||||
type: ACCOUNT_IMPORT,
|
||||
account: lain,
|
||||
};
|
||||
const state = ImmutableMap<string, any>();
|
||||
expect(reducer(state, action).toJS()).toEqual({
|
||||
'9v5bqYwY2jfmvPNhTM': {
|
||||
blocked_by: false,
|
||||
blocking: false,
|
||||
domain_blocking: false,
|
||||
endorsed: false,
|
||||
followed_by: true,
|
||||
following: true,
|
||||
id: '9v5bqYwY2jfmvPNhTM',
|
||||
muting: false,
|
||||
muting_notifications: false,
|
||||
note: '',
|
||||
notifying: false,
|
||||
requested: false,
|
||||
showing_reblogs: true,
|
||||
subscribing: false,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,85 +0,0 @@
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
import get from 'lodash/get';
|
||||
import { type Relationship, relationshipSchema } from 'pl-api';
|
||||
|
||||
import { ACCOUNT_NOTE_SUBMIT_SUCCESS } from '../actions/account-notes';
|
||||
import {
|
||||
ACCOUNT_BLOCK_SUCCESS,
|
||||
ACCOUNT_UNBLOCK_SUCCESS,
|
||||
ACCOUNT_MUTE_SUCCESS,
|
||||
ACCOUNT_UNMUTE_SUCCESS,
|
||||
ACCOUNT_PIN_SUCCESS,
|
||||
ACCOUNT_UNPIN_SUCCESS,
|
||||
ACCOUNT_REMOVE_FROM_FOLLOWERS_SUCCESS,
|
||||
RELATIONSHIPS_FETCH_SUCCESS,
|
||||
} from '../actions/accounts';
|
||||
import { DOMAIN_BLOCK_SUCCESS, DOMAIN_UNBLOCK_SUCCESS } from '../actions/domain-blocks';
|
||||
import { ACCOUNT_IMPORT, ACCOUNTS_IMPORT } from '../actions/importer';
|
||||
|
||||
import type { APIEntity } from 'pl-fe/types/entities';
|
||||
import type { AnyAction } from 'redux';
|
||||
|
||||
type State = ImmutableMap<string, Relationship>;
|
||||
type APIEntities = Array<APIEntity>;
|
||||
|
||||
const normalizeRelationships = (state: State, relationships: APIEntities) => {
|
||||
relationships.forEach(relationship => {
|
||||
try {
|
||||
state = state.set(relationship.id, relationshipSchema.parse(relationship));
|
||||
} catch (_e) {
|
||||
// do nothing
|
||||
}
|
||||
});
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
const setDomainBlocking = (state: State, accounts: string[], blocking: boolean) =>
|
||||
state.withMutations(map => {
|
||||
accounts.forEach(id => {
|
||||
map.setIn([id, 'domain_blocking'], blocking);
|
||||
});
|
||||
});
|
||||
|
||||
const importPleromaAccount = (state: State, account: APIEntity) => {
|
||||
const relationship = get(account, ['pleroma', 'relationship'], {});
|
||||
if (relationship.id)
|
||||
return normalizeRelationships(state, [relationship]);
|
||||
return state;
|
||||
};
|
||||
|
||||
const importPleromaAccounts = (state: State, accounts: APIEntities) => {
|
||||
accounts.forEach(account => {
|
||||
state = importPleromaAccount(state, account);
|
||||
});
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
const relationships = (state: State = ImmutableMap<string, Relationship>(), action: AnyAction) => {
|
||||
switch (action.type) {
|
||||
case ACCOUNT_IMPORT:
|
||||
return importPleromaAccount(state, action.account);
|
||||
case ACCOUNTS_IMPORT:
|
||||
return importPleromaAccounts(state, action.accounts);
|
||||
case ACCOUNT_BLOCK_SUCCESS:
|
||||
case ACCOUNT_UNBLOCK_SUCCESS:
|
||||
case ACCOUNT_MUTE_SUCCESS:
|
||||
case ACCOUNT_UNMUTE_SUCCESS:
|
||||
case ACCOUNT_PIN_SUCCESS:
|
||||
case ACCOUNT_UNPIN_SUCCESS:
|
||||
case ACCOUNT_NOTE_SUBMIT_SUCCESS:
|
||||
case ACCOUNT_REMOVE_FROM_FOLLOWERS_SUCCESS:
|
||||
return normalizeRelationships(state, [action.relationship]);
|
||||
case RELATIONSHIPS_FETCH_SUCCESS:
|
||||
return normalizeRelationships(state, action.relationships);
|
||||
case DOMAIN_BLOCK_SUCCESS:
|
||||
return setDomainBlocking(state, action.accounts, true);
|
||||
case DOMAIN_UNBLOCK_SUCCESS:
|
||||
return setDomainBlocking(state, action.accounts, false);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export { relationships as default };
|
||||
@ -13,7 +13,7 @@ import { validId } from 'pl-fe/utils/auth';
|
||||
import ConfigDB from 'pl-fe/utils/config-db';
|
||||
import { shouldFilter } from 'pl-fe/utils/timelines';
|
||||
|
||||
import type { Account as BaseAccount, Filter, MediaAttachment } from 'pl-api';
|
||||
import type { Account as BaseAccount, Filter, MediaAttachment, Relationship } from 'pl-api';
|
||||
import type { EntityStore } from 'pl-fe/entity-store/types';
|
||||
import type { Account, Group } from 'pl-fe/normalizers';
|
||||
import type { MinifiedStatus } from 'pl-fe/reducers/statuses';
|
||||
@ -33,7 +33,7 @@ const selectOwnAccount = (state: RootState) => {
|
||||
};
|
||||
|
||||
const getAccountBase = (state: RootState, accountId: string) => state.entities[Entities.ACCOUNTS]?.store[accountId] as Account | undefined;
|
||||
const getAccountRelationship = (state: RootState, accountId: string) => state.relationships.get(accountId);
|
||||
const getAccountRelationship = (state: RootState, accountId: string) => state.entities[Entities.RELATIONSHIPS]?.store[accountId] as Relationship | undefined;
|
||||
const getAccountMeta = (state: RootState, accountId: string) => state.accounts_meta[accountId];
|
||||
|
||||
const makeGetAccount = () => createSelector([
|
||||
|
||||
Reference in New Issue
Block a user