More work on pl-api migration
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
@ -329,7 +329,7 @@ const deleteUsers = (accountIds: string[]) =>
|
||||
const approveMastodonUsers = (accountIds: string[]) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
const client = getClient(getState);
|
||||
Promise.all(accountIds.map(accountId => {
|
||||
return Promise.all(accountIds.map(accountId => {
|
||||
client.request(`/api/v1/admin/accounts/${accountId}/approve`, { method: 'POST' })
|
||||
.then(({ json: user }) => {
|
||||
dispatch({ type: ADMIN_USERS_APPROVE_SUCCESS, users: [user], accountIds: [accountId] });
|
||||
@ -450,10 +450,10 @@ const addPermission = (accountIds: string[], permissionGroup: string) =>
|
||||
return getClient(getState).request(`/api/v1/pleroma/admin/users/permission_group/${permissionGroup}`, {
|
||||
method: 'POST', body: { nicknames },
|
||||
}).then(({ json: data }) => {
|
||||
dispatch({ type: ADMIN_ADD_PERMISSION_GROUP_SUCCESS, accountIds, permissionGroup, data });
|
||||
}).catch(error => {
|
||||
dispatch({ type: ADMIN_ADD_PERMISSION_GROUP_FAIL, error, accountIds, permissionGroup });
|
||||
});
|
||||
dispatch({ type: ADMIN_ADD_PERMISSION_GROUP_SUCCESS, accountIds, permissionGroup, data });
|
||||
}).catch(error => {
|
||||
dispatch({ type: ADMIN_ADD_PERMISSION_GROUP_FAIL, error, accountIds, permissionGroup });
|
||||
});
|
||||
};
|
||||
|
||||
const removePermission = (accountIds: string[], permissionGroup: string) =>
|
||||
@ -463,10 +463,10 @@ const removePermission = (accountIds: string[], permissionGroup: string) =>
|
||||
return getClient(getState).request(`/api/v1/pleroma/admin/users/permission_group/${permissionGroup}`, {
|
||||
method: 'DELETE', body: { nicknames },
|
||||
}).then(({ json: data }) => {
|
||||
dispatch({ type: ADMIN_REMOVE_PERMISSION_GROUP_SUCCESS, accountIds, permissionGroup, data });
|
||||
}).catch(error => {
|
||||
dispatch({ type: ADMIN_REMOVE_PERMISSION_GROUP_FAIL, error, accountIds, permissionGroup });
|
||||
});
|
||||
dispatch({ type: ADMIN_REMOVE_PERMISSION_GROUP_SUCCESS, accountIds, permissionGroup, data });
|
||||
}).catch(error => {
|
||||
dispatch({ type: ADMIN_REMOVE_PERMISSION_GROUP_FAIL, error, accountIds, permissionGroup });
|
||||
});
|
||||
};
|
||||
|
||||
const promoteToAdmin = (accountId: string) =>
|
||||
|
||||
@ -2,7 +2,6 @@ import { defineMessages } from 'react-intl';
|
||||
|
||||
import toast from 'soapbox/toast';
|
||||
import { isLoggedIn } from 'soapbox/utils/auth';
|
||||
import { getFeatures } from 'soapbox/utils/features';
|
||||
|
||||
import { getClient } from '../api';
|
||||
|
||||
@ -86,11 +85,6 @@ const changeAliasesSuggestions = (value: string) => ({
|
||||
const addToAliases = (account: Account) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
if (!isLoggedIn(getState)) return;
|
||||
const state = getState();
|
||||
|
||||
const instance = state.instance;
|
||||
const features = getFeatures(instance);
|
||||
|
||||
dispatch(addToAliasesRequest());
|
||||
|
||||
return getClient(getState).settings.addAccountAlias(account.acct).then(() => {
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
* @see module:soapbox/actions/auth
|
||||
*/
|
||||
|
||||
import { PlApiClient } from 'pl-api';
|
||||
import { PlApiClient, type CreateApplicationParams } from 'pl-api';
|
||||
|
||||
import * as BuildConfig from 'soapbox/build-config';
|
||||
|
||||
@ -16,7 +16,7 @@ const APP_CREATE_REQUEST = 'APP_CREATE_REQUEST';
|
||||
const APP_CREATE_SUCCESS = 'APP_CREATE_SUCCESS';
|
||||
const APP_CREATE_FAIL = 'APP_CREATE_FAIL';
|
||||
|
||||
const createApp = (params?: Record<string, string>, baseURL?: string) =>
|
||||
const createApp = (params: CreateApplicationParams, baseURL?: string) =>
|
||||
(dispatch: React.Dispatch<AnyAction>) => {
|
||||
dispatch({ type: APP_CREATE_REQUEST, params });
|
||||
|
||||
|
||||
@ -599,7 +599,7 @@ const fetchComposeSuggestionsTags = (dispatch: AppDispatch, getState: () => Root
|
||||
const { trends } = getFeatures(instance);
|
||||
|
||||
if (trends) {
|
||||
const currentTrends = state.trends.items;
|
||||
const currentTrends = state.trends.items.toArray();
|
||||
|
||||
return dispatch(updateSuggestionTags(composeId, token, currentTrends));
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ const fetchDirectory = (params: Record<string, any>) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
dispatch(fetchDirectoryRequest());
|
||||
|
||||
return getClient(getState()).instance.profileDirectory({...params, limit: 20}).then((data) => {
|
||||
return getClient(getState()).instance.profileDirectory({ ...params, limit: 20 }).then((data) => {
|
||||
dispatch(importFetchedAccounts(data));
|
||||
dispatch(fetchDirectorySuccess(data));
|
||||
dispatch(fetchRelationships(data.map((x: APIEntity) => x.id)));
|
||||
|
||||
@ -215,12 +215,12 @@ const submitEvent = () =>
|
||||
const params: CreateEventParams = {
|
||||
name,
|
||||
status,
|
||||
start_time: startTime,
|
||||
start_time: startTime.toISOString(),
|
||||
join_mode: joinMode,
|
||||
content_type: 'text/markdown',
|
||||
};
|
||||
|
||||
if (endTime) params.end_time = endTime;
|
||||
if (endTime) params.end_time = endTime?.toISOString();
|
||||
if (banner) params.banner_id = banner.id;
|
||||
if (location) params.location_id = location.origin_id;
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ import { isLoggedIn } from 'soapbox/utils/auth';
|
||||
|
||||
import { getClient } from '../api';
|
||||
|
||||
import type { FilterContext } from 'pl-api';
|
||||
import type { AppDispatch, RootState } from 'soapbox/store';
|
||||
|
||||
const FILTERS_FETCH_REQUEST = 'FILTERS_FETCH_REQUEST';
|
||||
@ -78,7 +79,7 @@ const fetchFilter = (id: string) =>
|
||||
}));
|
||||
};
|
||||
|
||||
const createFilter = (title: string, expires_in: number | undefined, context: Array<string>, hide: boolean, keywords_attributes: FilterKeywords) =>
|
||||
const createFilter = (title: string, expires_in: number | undefined, context: Array<FilterContext>, hide: boolean, keywords_attributes: FilterKeywords) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
dispatch({ type: FILTERS_CREATE_REQUEST });
|
||||
|
||||
@ -96,7 +97,7 @@ const createFilter = (title: string, expires_in: number | undefined, context: Ar
|
||||
});
|
||||
};
|
||||
|
||||
const updateFilter = (id: string, title: string, expires_in: number | undefined, context: Array<string>, hide: boolean, keywords_attributes: FilterKeywords) =>
|
||||
const updateFilter = (id: string, title: string, expires_in: number | undefined, context: Array<FilterContext>, hide: boolean, keywords_attributes: FilterKeywords) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
dispatch({ type: FILTERS_UPDATE_REQUEST });
|
||||
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import { serialize } from 'object-to-formdata';
|
||||
|
||||
import { selectAccount } from 'soapbox/selectors';
|
||||
import { setSentryAccount } from 'soapbox/sentry';
|
||||
import KVStore from 'soapbox/storage/kv-store';
|
||||
@ -68,11 +66,11 @@ const persistAuthAccount = (account: APIEntity, params: Record<string, any>) =>
|
||||
}
|
||||
};
|
||||
|
||||
const patchMe = (params: Record<string, any>, isFormData = false) =>
|
||||
const patchMe = (params: Record<string, any>) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
dispatch(patchMeRequest());
|
||||
|
||||
return getClient(getState()).settings.updateCredentials(params)
|
||||
return getClient(getState).settings.updateCredentials(params)
|
||||
.then(response => {
|
||||
persistAuthAccount(response, params);
|
||||
dispatch(patchMeSuccess(response));
|
||||
|
||||
@ -2,7 +2,6 @@ import { defineMessages, type IntlShape } from 'react-intl';
|
||||
|
||||
import toast from 'soapbox/toast';
|
||||
import { isLoggedIn } from 'soapbox/utils/auth';
|
||||
import { getFeatures } from 'soapbox/utils/features';
|
||||
import { formatBytes, getVideoDuration } from 'soapbox/utils/media';
|
||||
import resizeImage from 'soapbox/utils/resize-image';
|
||||
|
||||
|
||||
@ -273,8 +273,6 @@ const expandNotifications = ({ maxId }: Record<string, any> = {}, done: () => an
|
||||
dispatch(expandNotificationsRequest(isLoadingMore));
|
||||
|
||||
return getClient(state).notifications.getNotifications(params, { signal: abortExpandNotifications.signal }).then(response => {
|
||||
console.log(response);
|
||||
|
||||
const entries = (response.items).reduce((acc, item) => {
|
||||
if (item.account?.id) {
|
||||
acc.accounts[item.account.id] = item.account;
|
||||
@ -301,7 +299,6 @@ const expandNotifications = ({ maxId }: Record<string, any> = {}, done: () => an
|
||||
fetchRelatedRelationships(dispatch, response.items);
|
||||
done();
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
dispatch(expandNotificationsFail(error, isLoadingMore));
|
||||
done();
|
||||
});
|
||||
|
||||
@ -28,10 +28,9 @@ const fetchPoll = (pollId: string) =>
|
||||
dispatch(fetchPollRequest());
|
||||
|
||||
return getClient(getState()).polls.getPoll(pollId).then((data) => {
|
||||
dispatch(importFetchedPoll(data));
|
||||
dispatch(fetchPollSuccess(data));
|
||||
})
|
||||
.catch(err => dispatch(fetchPollFail(err)));
|
||||
dispatch(importFetchedPoll(data));
|
||||
dispatch(fetchPollSuccess(data));
|
||||
}).catch(err => dispatch(fetchPollFail(err)));
|
||||
};
|
||||
|
||||
const voteRequest = () => ({
|
||||
|
||||
@ -23,11 +23,11 @@ const createPushSubscription = (params: CreatePushNotificationsSubscriptionParam
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
dispatch({ type: PUSH_SUBSCRIPTION_CREATE_REQUEST, params });
|
||||
return getClient(getState).pushNotifications.createSubscription(params)
|
||||
.then((subscription) =>
|
||||
dispatch({ type: PUSH_SUBSCRIPTION_CREATE_SUCCESS, params, subscription }),
|
||||
).catch(error =>
|
||||
dispatch({ type: PUSH_SUBSCRIPTION_CREATE_FAIL, params, error }),
|
||||
);
|
||||
.then((subscription) =>
|
||||
dispatch({ type: PUSH_SUBSCRIPTION_CREATE_SUCCESS, params, subscription }),
|
||||
).catch(error =>
|
||||
dispatch({ type: PUSH_SUBSCRIPTION_CREATE_FAIL, params, error }),
|
||||
);
|
||||
};
|
||||
|
||||
const fetchPushSubscription = () =>
|
||||
|
||||
@ -67,7 +67,7 @@ const submitReport = () =>
|
||||
rule_ids: reports.new.rule_ids.toArray(),
|
||||
comment: reports.new.comment,
|
||||
forward: reports.new.forward,
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
const submitReportRequest = () => ({
|
||||
|
||||
@ -122,7 +122,7 @@ const expandSearch = (type: SearchFilter) => (dispatch: AppDispatch, getState: (
|
||||
|
||||
dispatch(expandSearchRequest(type));
|
||||
|
||||
let params: Record<string, any> = {
|
||||
const params: Record<string, any> = {
|
||||
type,
|
||||
offset,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user