kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Await all the importFetchedStatuses calls
rodzic
ecdfa13053
commit
f63340713a
|
@ -112,11 +112,11 @@ function fetchReports(params: Record<string, any> = {}) {
|
||||||
try {
|
try {
|
||||||
const response = await api(getState).get('/api/v1/admin/reports', { searchParams: params });
|
const response = await api(getState).get('/api/v1/admin/reports', { searchParams: params });
|
||||||
const reports = await response.json();
|
const reports = await response.json();
|
||||||
reports.forEach((report: APIEntity) => {
|
await Promise.all(reports.map(async (report: APIEntity) => {
|
||||||
dispatch(importFetchedAccount(report.account?.account));
|
dispatch(importFetchedAccount(report.account?.account));
|
||||||
dispatch(importFetchedAccount(report.target_account?.account));
|
dispatch(importFetchedAccount(report.target_account?.account));
|
||||||
dispatch(importFetchedStatuses(report.statuses));
|
await dispatch(importFetchedStatuses(report.statuses));
|
||||||
});
|
}));
|
||||||
dispatch({ type: ADMIN_REPORTS_FETCH_SUCCESS, reports, params });
|
dispatch({ type: ADMIN_REPORTS_FETCH_SUCCESS, reports, params });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch({ type: ADMIN_REPORTS_FETCH_FAIL, error, params });
|
dispatch({ type: ADMIN_REPORTS_FETCH_FAIL, error, params });
|
||||||
|
|
|
@ -59,7 +59,7 @@ const expandConversations = ({ maxId }: Record<string, any> = {}) => (dispatch:
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
dispatch(importFetchedAccounts(data.reduce((aggr: Array<APIEntity>, item: APIEntity) => aggr.concat(item.accounts), [])));
|
dispatch(importFetchedAccounts(data.reduce((aggr: Array<APIEntity>, item: APIEntity) => aggr.concat(item.accounts), [])));
|
||||||
dispatch(importFetchedStatuses(data.map((item: Record<string, any>) => item.last_status).filter((x?: APIEntity) => !!x)));
|
await dispatch(importFetchedStatuses(data.map((item: Record<string, any>) => item.last_status).filter((x?: APIEntity) => !!x)));
|
||||||
dispatch(expandConversationsSuccess(data, next, isLoadingRecent));
|
dispatch(expandConversationsSuccess(data, next, isLoadingRecent));
|
||||||
})
|
})
|
||||||
.catch(err => dispatch(expandConversationsFail(err)));
|
.catch(err => dispatch(expandConversationsFail(err)));
|
||||||
|
@ -81,11 +81,11 @@ const expandConversationsFail = (error: unknown) => ({
|
||||||
error,
|
error,
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateConversations = (conversation: APIEntity) => (dispatch: AppDispatch) => {
|
const updateConversations = (conversation: APIEntity) => async (dispatch: AppDispatch) => {
|
||||||
dispatch(importFetchedAccounts(conversation.accounts));
|
dispatch(importFetchedAccounts(conversation.accounts));
|
||||||
|
|
||||||
if (conversation.last_status) {
|
if (conversation.last_status) {
|
||||||
dispatch(importFetchedStatus(conversation.last_status));
|
await dispatch(importFetchedStatus(conversation.last_status));
|
||||||
}
|
}
|
||||||
|
|
||||||
return dispatch({
|
return dispatch({
|
||||||
|
|
|
@ -77,8 +77,8 @@ const emojiReact = (status: Status, emoji: string, custom?: string) =>
|
||||||
|
|
||||||
return api(getState)
|
return api(getState)
|
||||||
.put(`/api/v1/pleroma/statuses/${status.id}/reactions/${emoji}`)
|
.put(`/api/v1/pleroma/statuses/${status.id}/reactions/${emoji}`)
|
||||||
.then((response) => response.json()).then((data) => {
|
.then((response) => response.json()).then(async (data) => {
|
||||||
dispatch(importFetchedStatus(data));
|
await dispatch(importFetchedStatus(data));
|
||||||
dispatch(emojiReactSuccess(status, emoji));
|
dispatch(emojiReactSuccess(status, emoji));
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
dispatch(emojiReactFail(status, emoji, error));
|
dispatch(emojiReactFail(status, emoji, error));
|
||||||
|
@ -93,8 +93,8 @@ const unEmojiReact = (status: Status, emoji: string) =>
|
||||||
|
|
||||||
return api(getState)
|
return api(getState)
|
||||||
.delete(`/api/v1/pleroma/statuses/${status.id}/reactions/${emoji}`)
|
.delete(`/api/v1/pleroma/statuses/${status.id}/reactions/${emoji}`)
|
||||||
.then((response) => response.json()).then((data) => {
|
.then((response) => response.json()).then(async (data) => {
|
||||||
dispatch(importFetchedStatus(data));
|
await dispatch(importFetchedStatus(data));
|
||||||
dispatch(unEmojiReactSuccess(status, emoji));
|
dispatch(unEmojiReactSuccess(status, emoji));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(unEmojiReactFail(status, emoji, error));
|
dispatch(unEmojiReactFail(status, emoji, error));
|
||||||
|
|
|
@ -226,9 +226,9 @@ const submitEvent = () =>
|
||||||
const method = id === null ? 'POST' : 'PUT';
|
const method = id === null ? 'POST' : 'PUT';
|
||||||
const path = id === null ? '/api/v1/pleroma/events' : `/api/v1/pleroma/events/${id}`;
|
const path = id === null ? '/api/v1/pleroma/events' : `/api/v1/pleroma/events/${id}`;
|
||||||
|
|
||||||
return api(getState).request(method, path, params).then((response) => response.json()).then((data) => {
|
return api(getState).request(method, path, params).then((response) => response.json()).then(async (data) => {
|
||||||
dispatch(closeModal('COMPOSE_EVENT'));
|
dispatch(closeModal('COMPOSE_EVENT'));
|
||||||
dispatch(importFetchedStatus(data));
|
await dispatch(importFetchedStatus(data));
|
||||||
dispatch(submitEventSuccess(data));
|
dispatch(submitEventSuccess(data));
|
||||||
toast.success(
|
toast.success(
|
||||||
id ? messages.editSuccess : messages.success,
|
id ? messages.editSuccess : messages.success,
|
||||||
|
@ -268,8 +268,8 @@ const joinEvent = (id: string, participationMessage?: string) =>
|
||||||
|
|
||||||
return api(getState).post(`/api/v1/pleroma/events/${id}/join`, {
|
return api(getState).post(`/api/v1/pleroma/events/${id}/join`, {
|
||||||
participation_message: participationMessage,
|
participation_message: participationMessage,
|
||||||
}).then((response) => response.json()).then((data) => {
|
}).then((response) => response.json()).then(async (data) => {
|
||||||
dispatch(importFetchedStatus(data));
|
await dispatch(importFetchedStatus(data));
|
||||||
dispatch(joinEventSuccess(data));
|
dispatch(joinEventSuccess(data));
|
||||||
toast.success(
|
toast.success(
|
||||||
data.pleroma.event?.join_state === 'pending' ? messages.joinRequestSuccess : messages.joinSuccess,
|
data.pleroma.event?.join_state === 'pending' ? messages.joinRequestSuccess : messages.joinSuccess,
|
||||||
|
@ -310,8 +310,8 @@ const leaveEvent = (id: string) =>
|
||||||
|
|
||||||
dispatch(leaveEventRequest(status));
|
dispatch(leaveEventRequest(status));
|
||||||
|
|
||||||
return api(getState).post(`/api/v1/pleroma/events/${id}/leave`).then((response) => response.json()).then((data) => {
|
return api(getState).post(`/api/v1/pleroma/events/${id}/leave`).then((response) => response.json()).then(async (data) => {
|
||||||
dispatch(importFetchedStatus(data));
|
await dispatch(importFetchedStatus(data));
|
||||||
dispatch(leaveEventSuccess(data));
|
dispatch(leaveEventSuccess(data));
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
dispatch(leaveEventFail(error, status));
|
dispatch(leaveEventFail(error, status));
|
||||||
|
@ -584,7 +584,7 @@ const fetchRecentEvents = () =>
|
||||||
const next = response.next();
|
const next = response.next();
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
dispatch(importFetchedStatuses(data));
|
await dispatch(importFetchedStatuses(data));
|
||||||
dispatch({
|
dispatch({
|
||||||
type: RECENT_EVENTS_FETCH_SUCCESS,
|
type: RECENT_EVENTS_FETCH_SUCCESS,
|
||||||
statuses: data,
|
statuses: data,
|
||||||
|
@ -607,7 +607,7 @@ const fetchJoinedEvents = () =>
|
||||||
const next = response.next();
|
const next = response.next();
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
dispatch(importFetchedStatuses(data));
|
await dispatch(importFetchedStatuses(data));
|
||||||
dispatch({
|
dispatch({
|
||||||
type: JOINED_EVENTS_FETCH_SUCCESS,
|
type: JOINED_EVENTS_FETCH_SUCCESS,
|
||||||
statuses: data,
|
statuses: data,
|
||||||
|
|
|
@ -36,7 +36,7 @@ const fetchFavouritedStatuses = () =>
|
||||||
api(getState).get('/api/v1/favourites').then(async (response) => {
|
api(getState).get('/api/v1/favourites').then(async (response) => {
|
||||||
const next = response.next();
|
const next = response.next();
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
dispatch(importFetchedStatuses(data));
|
await dispatch(importFetchedStatuses(data));
|
||||||
dispatch(fetchFavouritedStatusesSuccess(data, next));
|
dispatch(fetchFavouritedStatusesSuccess(data, next));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(fetchFavouritedStatusesFail(error));
|
dispatch(fetchFavouritedStatusesFail(error));
|
||||||
|
@ -76,7 +76,7 @@ const expandFavouritedStatuses = () =>
|
||||||
api(getState).get(url).then(async (response) => {
|
api(getState).get(url).then(async (response) => {
|
||||||
const next = response.next();
|
const next = response.next();
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
dispatch(importFetchedStatuses(data));
|
await dispatch(importFetchedStatuses(data));
|
||||||
dispatch(expandFavouritedStatusesSuccess(data, next));
|
dispatch(expandFavouritedStatusesSuccess(data, next));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(expandFavouritedStatusesFail(error));
|
dispatch(expandFavouritedStatusesFail(error));
|
||||||
|
@ -111,7 +111,7 @@ const fetchAccountFavouritedStatuses = (accountId: string) =>
|
||||||
api(getState).get(`/api/v1/pleroma/accounts/${accountId}/favourites`).then(async (response) => {
|
api(getState).get(`/api/v1/pleroma/accounts/${accountId}/favourites`).then(async (response) => {
|
||||||
const next = response.next();
|
const next = response.next();
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
dispatch(importFetchedStatuses(data));
|
await dispatch(importFetchedStatuses(data));
|
||||||
dispatch(fetchAccountFavouritedStatusesSuccess(accountId, data, next));
|
dispatch(fetchAccountFavouritedStatusesSuccess(accountId, data, next));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(fetchAccountFavouritedStatusesFail(accountId, error));
|
dispatch(fetchAccountFavouritedStatusesFail(accountId, error));
|
||||||
|
@ -154,7 +154,7 @@ const expandAccountFavouritedStatuses = (accountId: string) =>
|
||||||
api(getState).get(url).then(async (response) => {
|
api(getState).get(url).then(async (response) => {
|
||||||
const next = response.next();
|
const next = response.next();
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
dispatch(importFetchedStatuses(data));
|
await dispatch(importFetchedStatuses(data));
|
||||||
dispatch(expandAccountFavouritedStatusesSuccess(accountId, data, next));
|
dispatch(expandAccountFavouritedStatusesSuccess(accountId, data, next));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(expandAccountFavouritedStatusesFail(accountId, error));
|
dispatch(expandAccountFavouritedStatusesFail(accountId, error));
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { importEntities } from 'soapbox/entity-store/actions.ts';
|
import { importEntities } from 'soapbox/entity-store/actions.ts';
|
||||||
import { Entities } from 'soapbox/entity-store/entities.ts';
|
import { Entities } from 'soapbox/entity-store/entities.ts';
|
||||||
import { Group, accountSchema, groupSchema, statusSchema } from 'soapbox/schemas/index.ts';
|
import { Group, accountSchema, groupSchema, statusSchema } from 'soapbox/schemas/index.ts';
|
||||||
import { filteredArray } from 'soapbox/schemas/utils.ts';
|
import { filteredArray, filteredArrayAsync } from 'soapbox/schemas/utils.ts';
|
||||||
|
|
||||||
import { getSettings } from '../settings.ts';
|
import { getSettings } from '../settings.ts';
|
||||||
|
|
||||||
|
@ -103,27 +103,27 @@ const importFetchedStatus = (status: APIEntity, idempotencyKey?: string) =>
|
||||||
status = result.data;
|
status = result.data;
|
||||||
|
|
||||||
if (status.reblog?.id) {
|
if (status.reblog?.id) {
|
||||||
dispatch(importFetchedStatus(status.reblog));
|
await dispatch(importFetchedStatus(status.reblog));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fedibird quotes
|
// Fedibird quotes
|
||||||
if (status.quote?.id) {
|
if (status.quote?.id) {
|
||||||
dispatch(importFetchedStatus(status.quote));
|
await dispatch(importFetchedStatus(status.quote));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pleroma quotes
|
// Pleroma quotes
|
||||||
if (status.pleroma?.quote?.id) {
|
if (status.pleroma?.quote?.id) {
|
||||||
dispatch(importFetchedStatus(status.pleroma.quote));
|
await dispatch(importFetchedStatus(status.pleroma.quote));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fedibird quote from reblog
|
// Fedibird quote from reblog
|
||||||
if (status.reblog?.quote?.id) {
|
if (status.reblog?.quote?.id) {
|
||||||
dispatch(importFetchedStatus(status.reblog.quote));
|
await dispatch(importFetchedStatus(status.reblog.quote));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pleroma quote from reblog
|
// Pleroma quote from reblog
|
||||||
if (status.reblog?.pleroma?.quote?.id) {
|
if (status.reblog?.pleroma?.quote?.id) {
|
||||||
dispatch(importFetchedStatus(status.reblog.pleroma.quote));
|
await dispatch(importFetchedStatus(status.reblog.pleroma.quote));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status.poll?.id) {
|
if (status.poll?.id) {
|
||||||
|
@ -144,13 +144,9 @@ const importFetchedStatuses = (statuses: APIEntity[]) =>
|
||||||
const normalStatuses: APIEntity[] = [];
|
const normalStatuses: APIEntity[] = [];
|
||||||
const polls: APIEntity[] = [];
|
const polls: APIEntity[] = [];
|
||||||
|
|
||||||
|
statuses = await filteredArrayAsync(statusSchema).parseAsync(statuses);
|
||||||
|
|
||||||
async function processStatus(status: APIEntity) {
|
async function processStatus(status: APIEntity) {
|
||||||
const result = await statusSchema.safeParseAsync(status);
|
|
||||||
|
|
||||||
// Skip broken statuses
|
|
||||||
if (!result.success) return;
|
|
||||||
status = result.data;
|
|
||||||
|
|
||||||
normalStatuses.push(status);
|
normalStatuses.push(status);
|
||||||
accounts.push(status.account);
|
accounts.push(status.account);
|
||||||
|
|
||||||
|
|
|
@ -96,10 +96,10 @@ const reblog = (status: StatusEntity, effects?: ReblogEffects) =>
|
||||||
dispatch(reblogRequest(status));
|
dispatch(reblogRequest(status));
|
||||||
effects?.reblogEffect(status.id);
|
effects?.reblogEffect(status.id);
|
||||||
|
|
||||||
api(getState).post(`/api/v1/statuses/${status.id}/reblog`).then((response) => response.json()).then((data) => {
|
api(getState).post(`/api/v1/statuses/${status.id}/reblog`).then((response) => response.json()).then(async (data) => {
|
||||||
// The reblog API method returns a new status wrapped around the original. In this case we are only
|
// The reblog API method returns a new status wrapped around the original. In this case we are only
|
||||||
// interested in how the original is modified, hence passing it skipping the wrapper
|
// interested in how the original is modified, hence passing it skipping the wrapper
|
||||||
dispatch(importFetchedStatus(data.reblog));
|
await dispatch(importFetchedStatus(data.reblog));
|
||||||
dispatch(reblogSuccess(status));
|
dispatch(reblogSuccess(status));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(reblogFail(status, error));
|
dispatch(reblogFail(status, error));
|
||||||
|
@ -626,8 +626,8 @@ const pin = (status: StatusEntity) =>
|
||||||
|
|
||||||
dispatch(pinRequest(status));
|
dispatch(pinRequest(status));
|
||||||
|
|
||||||
api(getState).post(`/api/v1/statuses/${status.id}/pin`).then((response) => response.json()).then((data) => {
|
api(getState).post(`/api/v1/statuses/${status.id}/pin`).then((response) => response.json()).then(async (data) => {
|
||||||
dispatch(importFetchedStatus(data));
|
await dispatch(importFetchedStatus(data));
|
||||||
dispatch(pinSuccess(status));
|
dispatch(pinSuccess(status));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(pinFail(status, error));
|
dispatch(pinFail(status, error));
|
||||||
|
@ -673,8 +673,8 @@ const unpin = (status: StatusEntity) =>
|
||||||
|
|
||||||
dispatch(unpinRequest(status));
|
dispatch(unpinRequest(status));
|
||||||
|
|
||||||
api(getState).post(`/api/v1/statuses/${status.id}/unpin`).then((response) => response.json()).then((data) => {
|
api(getState).post(`/api/v1/statuses/${status.id}/unpin`).then((response) => response.json()).then(async (data) => {
|
||||||
dispatch(importFetchedStatus(data));
|
await dispatch(importFetchedStatus(data));
|
||||||
dispatch(unpinSuccess(status));
|
dispatch(unpinSuccess(status));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(unpinFail(status, error));
|
dispatch(unpinFail(status, error));
|
||||||
|
|
|
@ -58,7 +58,7 @@ const fetchRelatedRelationships = (dispatch: AppDispatch, notifications: APIEnti
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateNotifications = (notification: APIEntity) =>
|
const updateNotifications = (notification: APIEntity) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
async (dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
const showInColumn = getSettings(getState()).getIn(['notifications', 'shows', notification.type], true);
|
const showInColumn = getSettings(getState()).getIn(['notifications', 'shows', notification.type], true);
|
||||||
|
|
||||||
if (notification.account) {
|
if (notification.account) {
|
||||||
|
@ -71,7 +71,7 @@ const updateNotifications = (notification: APIEntity) =>
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notification.status) {
|
if (notification.status) {
|
||||||
dispatch(importFetchedStatus(notification.status));
|
await dispatch(importFetchedStatus(notification.status));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showInColumn) {
|
if (showInColumn) {
|
||||||
|
@ -235,7 +235,7 @@ const expandNotifications = ({ maxId }: Record<string, any> = {}, done: () => an
|
||||||
}, { accounts: {}, statuses: {} });
|
}, { accounts: {}, statuses: {} });
|
||||||
|
|
||||||
dispatch(importFetchedAccounts(Object.values(entries.accounts)));
|
dispatch(importFetchedAccounts(Object.values(entries.accounts)));
|
||||||
dispatch(importFetchedStatuses(Object.values(entries.statuses)));
|
await dispatch(importFetchedStatuses(Object.values(entries.statuses)));
|
||||||
|
|
||||||
const statusesFromGroups = (Object.values(entries.statuses) as Status[]).filter((status) => !!status.group);
|
const statusesFromGroups = (Object.values(entries.statuses) as Status[]).filter((status) => !!status.group);
|
||||||
dispatch(fetchGroupRelationships(statusesFromGroups.map((status: any) => status.group?.id)));
|
dispatch(fetchGroupRelationships(statusesFromGroups.map((status: any) => status.group?.id)));
|
||||||
|
|
|
@ -18,8 +18,8 @@ const fetchPinnedStatuses = () =>
|
||||||
|
|
||||||
dispatch(fetchPinnedStatusesRequest());
|
dispatch(fetchPinnedStatusesRequest());
|
||||||
|
|
||||||
api(getState).get(`/api/v1/accounts/${me}/statuses`, { searchParams: { pinned: true } }).then((response) => response.json()).then((data) => {
|
api(getState).get(`/api/v1/accounts/${me}/statuses`, { searchParams: { pinned: true } }).then((response) => response.json()).then(async (data) => {
|
||||||
dispatch(importFetchedStatuses(data));
|
await dispatch(importFetchedStatuses(data));
|
||||||
dispatch(fetchPinnedStatusesSuccess(data, null));
|
dispatch(fetchPinnedStatusesSuccess(data, null));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(fetchPinnedStatusesFail(error));
|
dispatch(fetchPinnedStatusesFail(error));
|
||||||
|
|
|
@ -82,7 +82,7 @@ const submitSearch = (filter?: SearchFilter) =>
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.statuses) {
|
if (data.statuses) {
|
||||||
dispatch(importFetchedStatuses(data.statuses));
|
await dispatch(importFetchedStatuses(data.statuses));
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(fetchSearchSuccess(data, value, type, next));
|
dispatch(fetchSearchSuccess(data, value, type, next));
|
||||||
|
@ -154,7 +154,7 @@ const expandSearch = (type: SearchFilter) => (dispatch: AppDispatch, getState: (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.statuses) {
|
if (data.statuses) {
|
||||||
dispatch(importFetchedStatuses(data.statuses));
|
await dispatch(importFetchedStatuses(data.statuses));
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(expandSearchSuccess(data, value, type, next));
|
dispatch(expandSearchSuccess(data, value, type, next));
|
||||||
|
|
|
@ -28,7 +28,7 @@ export const fetchStatusQuotes = (statusId: string) =>
|
||||||
return api(getState).get(`/api/v1/pleroma/statuses/${statusId}/quotes`).then(async (response) => {
|
return api(getState).get(`/api/v1/pleroma/statuses/${statusId}/quotes`).then(async (response) => {
|
||||||
const next = response.next();
|
const next = response.next();
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
dispatch(importFetchedStatuses(data));
|
await dispatch(importFetchedStatuses(data));
|
||||||
return dispatch({
|
return dispatch({
|
||||||
type: STATUS_QUOTES_FETCH_SUCCESS,
|
type: STATUS_QUOTES_FETCH_SUCCESS,
|
||||||
statusId,
|
statusId,
|
||||||
|
@ -59,7 +59,7 @@ export const expandStatusQuotes = (statusId: string) =>
|
||||||
|
|
||||||
return api(getState).get(url).then(async (response) => {
|
return api(getState).get(url).then(async (response) => {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
dispatch(importFetchedStatuses(data));
|
await dispatch(importFetchedStatuses(data));
|
||||||
dispatch({
|
dispatch({
|
||||||
type: STATUS_QUOTES_EXPAND_SUCCESS,
|
type: STATUS_QUOTES_EXPAND_SUCCESS,
|
||||||
statusId,
|
statusId,
|
||||||
|
|
|
@ -72,7 +72,7 @@ const createStatus = (params: Record<string, any>, idempotencyKey: string, statu
|
||||||
status.expectsCard = true;
|
status.expectsCard = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(importFetchedStatus(status, idempotencyKey));
|
await dispatch(importFetchedStatus(status, idempotencyKey));
|
||||||
dispatch({ type: STATUS_CREATE_SUCCESS, status, params, idempotencyKey, editing: !!statusId });
|
dispatch({ type: STATUS_CREATE_SUCCESS, status, params, idempotencyKey, editing: !!statusId });
|
||||||
|
|
||||||
// Poll the backend for the updated card
|
// Poll the backend for the updated card
|
||||||
|
@ -80,9 +80,9 @@ const createStatus = (params: Record<string, any>, idempotencyKey: string, statu
|
||||||
const delay = 1000;
|
const delay = 1000;
|
||||||
|
|
||||||
const poll = (retries = 5) => {
|
const poll = (retries = 5) => {
|
||||||
api(getState).get(`/api/v1/statuses/${status.id}`).then((response) => response.json()).then((data) => {
|
api(getState).get(`/api/v1/statuses/${status.id}`).then((response) => response.json()).then(async (data) => {
|
||||||
if (data?.card) {
|
if (data?.card) {
|
||||||
dispatch(importFetchedStatus(data));
|
await dispatch(importFetchedStatus(data));
|
||||||
} else if (retries > 0 && response.status === 200) {
|
} else if (retries > 0 && response.status === 200) {
|
||||||
setTimeout(() => poll(retries - 1), delay);
|
setTimeout(() => poll(retries - 1), delay);
|
||||||
}
|
}
|
||||||
|
@ -125,8 +125,8 @@ const fetchStatus = (id: string) => {
|
||||||
|
|
||||||
dispatch({ type: STATUS_FETCH_REQUEST, id, skipLoading });
|
dispatch({ type: STATUS_FETCH_REQUEST, id, skipLoading });
|
||||||
|
|
||||||
return api(getState).get(`/api/v1/statuses/${id}`).then((response) => response.json()).then((status) => {
|
return api(getState).get(`/api/v1/statuses/${id}`).then((response) => response.json()).then(async (status) => {
|
||||||
dispatch(importFetchedStatus(status));
|
await dispatch(importFetchedStatus(status));
|
||||||
if (status.group) {
|
if (status.group) {
|
||||||
dispatch(fetchGroupRelationships([status.group.id]));
|
dispatch(fetchGroupRelationships([status.group.id]));
|
||||||
}
|
}
|
||||||
|
@ -174,15 +174,15 @@ const fetchContext = (id: string) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
dispatch({ type: CONTEXT_FETCH_REQUEST, id });
|
dispatch({ type: CONTEXT_FETCH_REQUEST, id });
|
||||||
|
|
||||||
return api(getState).get(`/api/v1/statuses/${id}/context`).then((response) => response.json()).then((context) => {
|
return api(getState).get(`/api/v1/statuses/${id}/context`).then((response) => response.json()).then(async (context) => {
|
||||||
if (Array.isArray(context)) {
|
if (Array.isArray(context)) {
|
||||||
// Mitra: returns a list of statuses
|
// Mitra: returns a list of statuses
|
||||||
dispatch(importFetchedStatuses(context));
|
await dispatch(importFetchedStatuses(context));
|
||||||
} else if (typeof context === 'object') {
|
} else if (typeof context === 'object') {
|
||||||
// Standard Mastodon API returns a map with `ancestors` and `descendants`
|
// Standard Mastodon API returns a map with `ancestors` and `descendants`
|
||||||
const { ancestors, descendants } = context;
|
const { ancestors, descendants } = context;
|
||||||
const statuses = ancestors.concat(descendants);
|
const statuses = ancestors.concat(descendants);
|
||||||
dispatch(importFetchedStatuses(statuses));
|
await dispatch(importFetchedStatuses(statuses));
|
||||||
dispatch({ type: CONTEXT_FETCH_SUCCESS, id, ancestors, descendants });
|
dispatch({ type: CONTEXT_FETCH_SUCCESS, id, ancestors, descendants });
|
||||||
} else {
|
} else {
|
||||||
throw context;
|
throw context;
|
||||||
|
@ -198,11 +198,11 @@ const fetchContext = (id: string) =>
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchNext = (statusId: string, next: string) =>
|
const fetchNext = (statusId: string, next: string) =>
|
||||||
async(dispatch: AppDispatch, getState: () => RootState) => {
|
async (dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
const response = await api(getState).get(next);
|
const response = await api(getState).get(next);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
dispatch(importFetchedStatuses(data));
|
await dispatch(importFetchedStatuses(data));
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: CONTEXT_FETCH_SUCCESS,
|
type: CONTEXT_FETCH_SUCCESS,
|
||||||
|
@ -215,18 +215,18 @@ const fetchNext = (statusId: string, next: string) =>
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchAncestors = (id: string) =>
|
const fetchAncestors = (id: string) =>
|
||||||
async(dispatch: AppDispatch, getState: () => RootState) => {
|
async (dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
const response = await api(getState).get(`/api/v1/statuses/${id}/context/ancestors`);
|
const response = await api(getState).get(`/api/v1/statuses/${id}/context/ancestors`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
dispatch(importFetchedStatuses(data));
|
await dispatch(importFetchedStatuses(data));
|
||||||
return response;
|
return response;
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchDescendants = (id: string) =>
|
const fetchDescendants = (id: string) =>
|
||||||
async(dispatch: AppDispatch, getState: () => RootState) => {
|
async (dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
const response = await api(getState).get(`/api/v1/statuses/${id}/context/descendants`);
|
const response = await api(getState).get(`/api/v1/statuses/${id}/context/descendants`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
dispatch(importFetchedStatuses(data));
|
await dispatch(importFetchedStatuses(data));
|
||||||
return response;
|
return response;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ const TIMELINE_INSERT = 'TIMELINE_INSERT' as const;
|
||||||
const MAX_QUEUED_ITEMS = 40;
|
const MAX_QUEUED_ITEMS = 40;
|
||||||
|
|
||||||
const processTimelineUpdate = (timeline: string, status: APIEntity, accept: ((status: APIEntity) => boolean) | null) =>
|
const processTimelineUpdate = (timeline: string, status: APIEntity, accept: ((status: APIEntity) => boolean) | null) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
async (dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
const me = getState().me;
|
const me = getState().me;
|
||||||
const ownStatus = status.account?.id === me;
|
const ownStatus = status.account?.id === me;
|
||||||
const hasPendingStatuses = !getState().pending_statuses.isEmpty();
|
const hasPendingStatuses = !getState().pending_statuses.isEmpty();
|
||||||
|
@ -46,7 +46,7 @@ const processTimelineUpdate = (timeline: string, status: APIEntity, accept: ((st
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(importFetchedStatus(status));
|
await dispatch(importFetchedStatus(status));
|
||||||
|
|
||||||
if (shouldSkipQueue) {
|
if (shouldSkipQueue) {
|
||||||
dispatch(updateTimeline(timeline, status.id, accept));
|
dispatch(updateTimeline(timeline, status.id, accept));
|
||||||
|
|
|
@ -29,7 +29,7 @@ const fetchTrendingStatuses = () =>
|
||||||
|
|
||||||
const statuses = data;
|
const statuses = data;
|
||||||
|
|
||||||
dispatch(importFetchedStatuses(statuses));
|
await dispatch(importFetchedStatuses(statuses));
|
||||||
dispatch(fetchTrendingStatusesSuccess(statuses, next));
|
dispatch(fetchTrendingStatusesSuccess(statuses, next));
|
||||||
return statuses;
|
return statuses;
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
@ -57,7 +57,7 @@ const expandTrendingStatuses = (path: string) =>
|
||||||
|
|
||||||
const statuses = data;
|
const statuses = data;
|
||||||
|
|
||||||
dispatch(importFetchedStatuses(statuses));
|
await dispatch(importFetchedStatuses(statuses));
|
||||||
dispatch(expandTrendingStatusesSuccess(statuses, next));
|
dispatch(expandTrendingStatusesSuccess(statuses, next));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(expandTrendingStatusesFail(error));
|
dispatch(expandTrendingStatusesFail(error));
|
||||||
|
|
Ładowanie…
Reference in New Issue