Actions: TypeScript

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2022-06-19 22:54:20 +02:00
parent 313bdd1980
commit f3b0230480
2 changed files with 150 additions and 110 deletions

View file

@ -1,4 +1,4 @@
import { Map as ImmutableMap } from 'immutable'; import { List as ImmutableList, Map as ImmutableMap } from 'immutable';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { getSettings, changeSetting } from 'soapbox/actions/settings'; import { getSettings, changeSetting } from 'soapbox/actions/settings';
@ -6,47 +6,49 @@ import { getFeatures } from 'soapbox/utils/features';
import api, { getLinks } from '../api'; import api, { getLinks } from '../api';
export const CHATS_FETCH_REQUEST = 'CHATS_FETCH_REQUEST'; import type { History } from 'history';
export const CHATS_FETCH_SUCCESS = 'CHATS_FETCH_SUCCESS'; import type { AppDispatch, RootState } from 'soapbox/store';
export const CHATS_FETCH_FAIL = 'CHATS_FETCH_FAIL';
export const CHATS_EXPAND_REQUEST = 'CHATS_EXPAND_REQUEST'; const CHATS_FETCH_REQUEST = 'CHATS_FETCH_REQUEST';
export const CHATS_EXPAND_SUCCESS = 'CHATS_EXPAND_SUCCESS'; const CHATS_FETCH_SUCCESS = 'CHATS_FETCH_SUCCESS';
export const CHATS_EXPAND_FAIL = 'CHATS_EXPAND_FAIL'; const CHATS_FETCH_FAIL = 'CHATS_FETCH_FAIL';
export const CHAT_MESSAGES_FETCH_REQUEST = 'CHAT_MESSAGES_FETCH_REQUEST'; const CHATS_EXPAND_REQUEST = 'CHATS_EXPAND_REQUEST';
export const CHAT_MESSAGES_FETCH_SUCCESS = 'CHAT_MESSAGES_FETCH_SUCCESS'; const CHATS_EXPAND_SUCCESS = 'CHATS_EXPAND_SUCCESS';
export const CHAT_MESSAGES_FETCH_FAIL = 'CHAT_MESSAGES_FETCH_FAIL'; const CHATS_EXPAND_FAIL = 'CHATS_EXPAND_FAIL';
export const CHAT_MESSAGE_SEND_REQUEST = 'CHAT_MESSAGE_SEND_REQUEST'; const CHAT_MESSAGES_FETCH_REQUEST = 'CHAT_MESSAGES_FETCH_REQUEST';
export const CHAT_MESSAGE_SEND_SUCCESS = 'CHAT_MESSAGE_SEND_SUCCESS'; const CHAT_MESSAGES_FETCH_SUCCESS = 'CHAT_MESSAGES_FETCH_SUCCESS';
export const CHAT_MESSAGE_SEND_FAIL = 'CHAT_MESSAGE_SEND_FAIL'; const CHAT_MESSAGES_FETCH_FAIL = 'CHAT_MESSAGES_FETCH_FAIL';
export const CHAT_FETCH_REQUEST = 'CHAT_FETCH_REQUEST'; const CHAT_MESSAGE_SEND_REQUEST = 'CHAT_MESSAGE_SEND_REQUEST';
export const CHAT_FETCH_SUCCESS = 'CHAT_FETCH_SUCCESS'; const CHAT_MESSAGE_SEND_SUCCESS = 'CHAT_MESSAGE_SEND_SUCCESS';
export const CHAT_FETCH_FAIL = 'CHAT_FETCH_FAIL'; const CHAT_MESSAGE_SEND_FAIL = 'CHAT_MESSAGE_SEND_FAIL';
export const CHAT_READ_REQUEST = 'CHAT_READ_REQUEST'; const CHAT_FETCH_REQUEST = 'CHAT_FETCH_REQUEST';
export const CHAT_READ_SUCCESS = 'CHAT_READ_SUCCESS'; const CHAT_FETCH_SUCCESS = 'CHAT_FETCH_SUCCESS';
export const CHAT_READ_FAIL = 'CHAT_READ_FAIL'; const CHAT_FETCH_FAIL = 'CHAT_FETCH_FAIL';
export const CHAT_MESSAGE_DELETE_REQUEST = 'CHAT_MESSAGE_DELETE_REQUEST'; const CHAT_READ_REQUEST = 'CHAT_READ_REQUEST';
export const CHAT_MESSAGE_DELETE_SUCCESS = 'CHAT_MESSAGE_DELETE_SUCCESS'; const CHAT_READ_SUCCESS = 'CHAT_READ_SUCCESS';
export const CHAT_MESSAGE_DELETE_FAIL = 'CHAT_MESSAGE_DELETE_FAIL'; const CHAT_READ_FAIL = 'CHAT_READ_FAIL';
export function fetchChatsV1() { const CHAT_MESSAGE_DELETE_REQUEST = 'CHAT_MESSAGE_DELETE_REQUEST';
return (dispatch, getState) => const CHAT_MESSAGE_DELETE_SUCCESS = 'CHAT_MESSAGE_DELETE_SUCCESS';
const CHAT_MESSAGE_DELETE_FAIL = 'CHAT_MESSAGE_DELETE_FAIL';
const fetchChatsV1 = () =>
(dispatch: AppDispatch, getState: () => RootState) =>
api(getState).get('/api/v1/pleroma/chats').then((response) => { api(getState).get('/api/v1/pleroma/chats').then((response) => {
dispatch({ type: CHATS_FETCH_SUCCESS, chats: response.data }); dispatch({ type: CHATS_FETCH_SUCCESS, chats: response.data });
}).catch(error => { }).catch(error => {
dispatch({ type: CHATS_FETCH_FAIL, error }); dispatch({ type: CHATS_FETCH_FAIL, error });
}); });
}
export function fetchChatsV2() { const fetchChatsV2 = () =>
return (dispatch, getState) => (dispatch: AppDispatch, getState: () => RootState) =>
api(getState).get('/api/v2/pleroma/chats').then((response) => { api(getState).get('/api/v2/pleroma/chats').then((response) => {
let next = getLinks(response).refs.find(link => link.rel === 'next'); let next: { uri: string } | undefined = getLinks(response).refs.find(link => link.rel === 'next');
if (!next && response.data.length) { if (!next && response.data.length) {
next = { uri: `/api/v2/pleroma/chats?max_id=${response.data[response.data.length - 1].id}&offset=0` }; next = { uri: `/api/v2/pleroma/chats?max_id=${response.data[response.data.length - 1].id}&offset=0` };
@ -56,10 +58,9 @@ export function fetchChatsV2() {
}).catch(error => { }).catch(error => {
dispatch({ type: CHATS_FETCH_FAIL, error }); dispatch({ type: CHATS_FETCH_FAIL, error });
}); });
}
export function fetchChats() { const fetchChats = () =>
return (dispatch, getState) => { (dispatch: AppDispatch, getState: () => RootState) => {
const state = getState(); const state = getState();
const { instance } = state; const { instance } = state;
const features = getFeatures(instance); const features = getFeatures(instance);
@ -71,11 +72,10 @@ export function fetchChats() {
return dispatch(fetchChatsV1()); return dispatch(fetchChatsV1());
} }
}; };
}
export function expandChats() { const expandChats = () =>
return (dispatch, getState) => { (dispatch: AppDispatch, getState: () => RootState) => {
const url = getState().getIn(['chats', 'next']); const url = getState().chats.next;
if (url === null) { if (url === null) {
return; return;
@ -90,10 +90,9 @@ export function expandChats() {
dispatch({ type: CHATS_EXPAND_FAIL, error }); dispatch({ type: CHATS_EXPAND_FAIL, error });
}); });
}; };
}
export function fetchChatMessages(chatId, maxId = null) { const fetchChatMessages = (chatId: string, maxId: string | null = null) =>
return (dispatch, getState) => { (dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: CHAT_MESSAGES_FETCH_REQUEST, chatId, maxId }); dispatch({ type: CHAT_MESSAGES_FETCH_REQUEST, chatId, maxId });
return api(getState).get(`/api/v1/pleroma/chats/${chatId}/messages`, { params: { max_id: maxId } }).then(({ data }) => { return api(getState).get(`/api/v1/pleroma/chats/${chatId}/messages`, { params: { max_id: maxId } }).then(({ data }) => {
dispatch({ type: CHAT_MESSAGES_FETCH_SUCCESS, chatId, maxId, chatMessages: data }); dispatch({ type: CHAT_MESSAGES_FETCH_SUCCESS, chatId, maxId, chatMessages: data });
@ -101,12 +100,11 @@ export function fetchChatMessages(chatId, maxId = null) {
dispatch({ type: CHAT_MESSAGES_FETCH_FAIL, chatId, maxId, error }); dispatch({ type: CHAT_MESSAGES_FETCH_FAIL, chatId, maxId, error });
}); });
}; };
}
export function sendChatMessage(chatId, params) { const sendChatMessage = (chatId: string, params: Record<string, any>) =>
return (dispatch, getState) => { (dispatch: AppDispatch, getState: () => RootState) => {
const uuid = `末_${Date.now()}_${uuidv4()}`; const uuid = `末_${Date.now()}_${uuidv4()}`;
const me = getState().get('me'); const me = getState().me;
dispatch({ type: CHAT_MESSAGE_SEND_REQUEST, chatId, params, uuid, me }); dispatch({ type: CHAT_MESSAGE_SEND_REQUEST, chatId, params, uuid, me });
return api(getState).post(`/api/v1/pleroma/chats/${chatId}/messages`, params).then(({ data }) => { return api(getState).post(`/api/v1/pleroma/chats/${chatId}/messages`, params).then(({ data }) => {
dispatch({ type: CHAT_MESSAGE_SEND_SUCCESS, chatId, chatMessage: data, uuid }); dispatch({ type: CHAT_MESSAGE_SEND_SUCCESS, chatId, chatMessage: data, uuid });
@ -114,28 +112,26 @@ export function sendChatMessage(chatId, params) {
dispatch({ type: CHAT_MESSAGE_SEND_FAIL, chatId, error, uuid }); dispatch({ type: CHAT_MESSAGE_SEND_FAIL, chatId, error, uuid });
}); });
}; };
}
export function openChat(chatId) { const openChat = (chatId: string) =>
return (dispatch, getState) => { (dispatch: AppDispatch, getState: () => RootState) => {
const state = getState(); const state = getState();
const panes = getSettings(state).getIn(['chats', 'panes']); const panes = getSettings(state).getIn(['chats', 'panes']) as ImmutableList<ImmutableMap<string, any>>;
const idx = panes.findIndex(pane => pane.get('chat_id') === chatId); const idx = panes.findIndex(pane => pane.get('chat_id') === chatId);
dispatch(markChatRead(chatId)); dispatch(markChatRead(chatId));
if (idx > -1) { if (idx > -1) {
return dispatch(changeSetting(['chats', 'panes', idx, 'state'], 'open')); return dispatch(changeSetting(['chats', 'panes', idx as any, 'state'], 'open'));
} else { } else {
const newPane = ImmutableMap({ chat_id: chatId, state: 'open' }); const newPane = ImmutableMap({ chat_id: chatId, state: 'open' });
return dispatch(changeSetting(['chats', 'panes'], panes.push(newPane))); return dispatch(changeSetting(['chats', 'panes'], panes.push(newPane)));
} }
}; };
}
export function closeChat(chatId) { const closeChat = (chatId: string) =>
return (dispatch, getState) => { (dispatch: AppDispatch, getState: () => RootState) => {
const panes = getSettings(getState()).getIn(['chats', 'panes']); const panes = getSettings(getState()).getIn(['chats', 'panes']) as ImmutableList<ImmutableMap<string, any>>;
const idx = panes.findIndex(pane => pane.get('chat_id') === chatId); const idx = panes.findIndex(pane => pane.get('chat_id') === chatId);
if (idx > -1) { if (idx > -1) {
@ -144,33 +140,30 @@ export function closeChat(chatId) {
return false; return false;
} }
}; };
}
export function toggleChat(chatId) { const toggleChat = (chatId: string) =>
return (dispatch, getState) => { (dispatch: AppDispatch, getState: () => RootState) => {
const panes = getSettings(getState()).getIn(['chats', 'panes']); const panes = getSettings(getState()).getIn(['chats', 'panes']) as ImmutableList<ImmutableMap<string, any>>;
const [idx, pane] = panes.findEntry(pane => pane.get('chat_id') === chatId); const [idx, pane] = panes.findEntry(pane => pane.get('chat_id') === chatId)!;
if (idx > -1) { if (idx > -1) {
const state = pane.get('state') === 'minimized' ? 'open' : 'minimized'; const state = pane.get('state') === 'minimized' ? 'open' : 'minimized';
if (state === 'open') dispatch(markChatRead(chatId)); if (state === 'open') dispatch(markChatRead(chatId));
return dispatch(changeSetting(['chats', 'panes', idx, 'state'], state)); return dispatch(changeSetting(['chats', 'panes', idx as any, 'state'], state));
} else { } else {
return false; return false;
} }
}; };
}
export function toggleMainWindow() { const toggleMainWindow = () =>
return (dispatch, getState) => { (dispatch: AppDispatch, getState: () => RootState) => {
const main = getSettings(getState()).getIn(['chats', 'mainWindow']); const main = getSettings(getState()).getIn(['chats', 'mainWindow']) as 'minimized' | 'open';
const state = main === 'minimized' ? 'open' : 'minimized'; const state = main === 'minimized' ? 'open' : 'minimized';
return dispatch(changeSetting(['chats', 'mainWindow'], state)); return dispatch(changeSetting(['chats', 'mainWindow'], state));
}; };
}
export function fetchChat(chatId) { const fetchChat = (chatId: string) =>
return (dispatch, getState) => { (dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: CHAT_FETCH_REQUEST, chatId }); dispatch({ type: CHAT_FETCH_REQUEST, chatId });
return api(getState).get(`/api/v1/pleroma/chats/${chatId}`).then(({ data }) => { return api(getState).get(`/api/v1/pleroma/chats/${chatId}`).then(({ data }) => {
dispatch({ type: CHAT_FETCH_SUCCESS, chat: data }); dispatch({ type: CHAT_FETCH_SUCCESS, chat: data });
@ -178,10 +171,9 @@ export function fetchChat(chatId) {
dispatch({ type: CHAT_FETCH_FAIL, chatId, error }); dispatch({ type: CHAT_FETCH_FAIL, chatId, error });
}); });
}; };
}
export function startChat(accountId) { const startChat = (accountId: string) =>
return (dispatch, getState) => { (dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: CHAT_FETCH_REQUEST, accountId }); dispatch({ type: CHAT_FETCH_REQUEST, accountId });
return api(getState).post(`/api/v1/pleroma/chats/by-account-id/${accountId}`).then(({ data }) => { return api(getState).post(`/api/v1/pleroma/chats/by-account-id/${accountId}`).then(({ data }) => {
dispatch({ type: CHAT_FETCH_SUCCESS, chat: data }); dispatch({ type: CHAT_FETCH_SUCCESS, chat: data });
@ -190,12 +182,11 @@ export function startChat(accountId) {
dispatch({ type: CHAT_FETCH_FAIL, accountId, error }); dispatch({ type: CHAT_FETCH_FAIL, accountId, error });
}); });
}; };
}
export function markChatRead(chatId, lastReadId) { const markChatRead = (chatId: string, lastReadId?: string | null) =>
return (dispatch, getState) => { (dispatch: AppDispatch, getState: () => RootState) => {
const chat = getState().getIn(['chats', 'items', chatId]); const chat = getState().chats.items.get(chatId)!;
if (!lastReadId) lastReadId = chat.get('last_message'); if (!lastReadId) lastReadId = chat.last_message;
if (chat.get('unread') < 1) return; if (chat.get('unread') < 1) return;
if (!lastReadId) return; if (!lastReadId) return;
@ -207,10 +198,9 @@ export function markChatRead(chatId, lastReadId) {
dispatch({ type: CHAT_READ_FAIL, chatId, error, lastReadId }); dispatch({ type: CHAT_READ_FAIL, chatId, error, lastReadId });
}); });
}; };
}
export function deleteChatMessage(chatId, messageId) { const deleteChatMessage = (chatId: string, messageId: string) =>
return (dispatch, getState) => { (dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: CHAT_MESSAGE_DELETE_REQUEST, chatId, messageId }); dispatch({ type: CHAT_MESSAGE_DELETE_REQUEST, chatId, messageId });
api(getState).delete(`/api/v1/pleroma/chats/${chatId}/messages/${messageId}`).then(({ data }) => { api(getState).delete(`/api/v1/pleroma/chats/${chatId}/messages/${messageId}`).then(({ data }) => {
dispatch({ type: CHAT_MESSAGE_DELETE_SUCCESS, chatId, messageId, chatMessage: data }); dispatch({ type: CHAT_MESSAGE_DELETE_SUCCESS, chatId, messageId, chatMessage: data });
@ -218,13 +208,12 @@ export function deleteChatMessage(chatId, messageId) {
dispatch({ type: CHAT_MESSAGE_DELETE_FAIL, chatId, messageId, error }); dispatch({ type: CHAT_MESSAGE_DELETE_FAIL, chatId, messageId, error });
}); });
}; };
}
/** Start a chat and launch it in the UI */ /** Start a chat and launch it in the UI */
export function launchChat(accountId, router, forceNavigate = false) { const launchChat = (accountId: string, router: History, forceNavigate = false) => {
const isMobile = width => width <= 1190; const isMobile = (width: number) => width <= 1190;
return (dispatch, getState) => { return (dispatch: AppDispatch) => {
// TODO: make this faster // TODO: make this faster
return dispatch(startChat(accountId)).then(chat => { return dispatch(startChat(accountId)).then(chat => {
if (forceNavigate || isMobile(window.innerWidth)) { if (forceNavigate || isMobile(window.innerWidth)) {
@ -234,4 +223,43 @@ export function launchChat(accountId, router, forceNavigate = false) {
} }
}); });
}; };
} };
export {
CHATS_FETCH_REQUEST,
CHATS_FETCH_SUCCESS,
CHATS_FETCH_FAIL,
CHATS_EXPAND_REQUEST,
CHATS_EXPAND_SUCCESS,
CHATS_EXPAND_FAIL,
CHAT_MESSAGES_FETCH_REQUEST,
CHAT_MESSAGES_FETCH_SUCCESS,
CHAT_MESSAGES_FETCH_FAIL,
CHAT_MESSAGE_SEND_REQUEST,
CHAT_MESSAGE_SEND_SUCCESS,
CHAT_MESSAGE_SEND_FAIL,
CHAT_FETCH_REQUEST,
CHAT_FETCH_SUCCESS,
CHAT_FETCH_FAIL,
CHAT_READ_REQUEST,
CHAT_READ_SUCCESS,
CHAT_READ_FAIL,
CHAT_MESSAGE_DELETE_REQUEST,
CHAT_MESSAGE_DELETE_SUCCESS,
CHAT_MESSAGE_DELETE_FAIL,
fetchChatsV1,
fetchChatsV2,
fetchChats,
expandChats,
fetchChatMessages,
sendChatMessage,
openChat,
closeChat,
toggleChat,
toggleMainWindow,
fetchChat,
startChat,
markChatRead,
deleteChatMessage,
launchChat,
};

View file

@ -1,46 +1,49 @@
import { getSettings } from '../settings'; import { getSettings } from '../settings';
export const ACCOUNT_IMPORT = 'ACCOUNT_IMPORT'; import type { AppDispatch, RootState } from 'soapbox/store';
export const ACCOUNTS_IMPORT = 'ACCOUNTS_IMPORT'; import type { APIEntity } from 'soapbox/types/entities';
export const STATUS_IMPORT = 'STATUS_IMPORT';
export const STATUSES_IMPORT = 'STATUSES_IMPORT';
export const POLLS_IMPORT = 'POLLS_IMPORT';
export const ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP = 'ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP';
export function importAccount(account) { 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';
const ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP = 'ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP';
export function importAccount(account: APIEntity) {
return { type: ACCOUNT_IMPORT, account }; return { type: ACCOUNT_IMPORT, account };
} }
export function importAccounts(accounts) { export function importAccounts(accounts: APIEntity[]) {
return { type: ACCOUNTS_IMPORT, accounts }; return { type: ACCOUNTS_IMPORT, accounts };
} }
export function importStatus(status, idempotencyKey) { export function importStatus(status: APIEntity, idempotencyKey?: string) {
return (dispatch, getState) => { return (dispatch: AppDispatch, getState: () => RootState) => {
const expandSpoilers = getSettings(getState()).get('expandSpoilers'); const expandSpoilers = getSettings(getState()).get('expandSpoilers');
return dispatch({ type: STATUS_IMPORT, status, idempotencyKey, expandSpoilers }); return dispatch({ type: STATUS_IMPORT, status, idempotencyKey, expandSpoilers });
}; };
} }
export function importStatuses(statuses) { export function importStatuses(statuses: APIEntity[]) {
return (dispatch, getState) => { return (dispatch: AppDispatch, getState: () => RootState) => {
const expandSpoilers = getSettings(getState()).get('expandSpoilers'); const expandSpoilers = getSettings(getState()).get('expandSpoilers');
return dispatch({ type: STATUSES_IMPORT, statuses, expandSpoilers }); return dispatch({ type: STATUSES_IMPORT, statuses, expandSpoilers });
}; };
} }
export function importPolls(polls) { export function importPolls(polls: APIEntity[]) {
return { type: POLLS_IMPORT, polls }; return { type: POLLS_IMPORT, polls };
} }
export function importFetchedAccount(account) { export function importFetchedAccount(account: APIEntity) {
return importFetchedAccounts([account]); return importFetchedAccounts([account]);
} }
export function importFetchedAccounts(accounts) { export function importFetchedAccounts(accounts: APIEntity[]) {
const normalAccounts = []; const normalAccounts: APIEntity[] = [];
function processAccount(account) { const processAccount = (account: APIEntity) => {
if (!account.id) return; if (!account.id) return;
normalAccounts.push(account); normalAccounts.push(account);
@ -48,15 +51,15 @@ export function importFetchedAccounts(accounts) {
if (account.moved) { if (account.moved) {
processAccount(account.moved); processAccount(account.moved);
} }
} };
accounts.forEach(processAccount); accounts.forEach(processAccount);
return importAccounts(normalAccounts); return importAccounts(normalAccounts);
} }
export function importFetchedStatus(status, idempotencyKey) { export function importFetchedStatus(status: APIEntity, idempotencyKey?: string) {
return (dispatch, getState) => { return (dispatch: AppDispatch) => {
// Skip broken statuses // Skip broken statuses
if (isBroken(status)) return; if (isBroken(status)) return;
@ -95,7 +98,7 @@ export function importFetchedStatus(status, idempotencyKey) {
// Sometimes Pleroma can return an empty account, // Sometimes Pleroma can return an empty account,
// or a repost can appear of a deleted account. Skip these statuses. // or a repost can appear of a deleted account. Skip these statuses.
const isBroken = status => { const isBroken = (status: APIEntity) => {
try { try {
// Skip empty accounts // Skip empty accounts
// https://gitlab.com/soapbox-pub/soapbox-fe/-/issues/424 // https://gitlab.com/soapbox-pub/soapbox-fe/-/issues/424
@ -109,13 +112,13 @@ const isBroken = status => {
} }
}; };
export function importFetchedStatuses(statuses) { export function importFetchedStatuses(statuses: APIEntity[]) {
return (dispatch, getState) => { return (dispatch: AppDispatch, getState: () => RootState) => {
const accounts = []; const accounts: APIEntity[] = [];
const normalStatuses = []; const normalStatuses: APIEntity[] = [];
const polls = []; const polls: APIEntity[] = [];
function processStatus(status) { function processStatus(status: APIEntity) {
// Skip broken statuses // Skip broken statuses
if (isBroken(status)) return; if (isBroken(status)) return;
@ -148,12 +151,21 @@ export function importFetchedStatuses(statuses) {
}; };
} }
export function importFetchedPoll(poll) { export function importFetchedPoll(poll: APIEntity) {
return dispatch => { return (dispatch: AppDispatch) => {
dispatch(importPolls([poll])); dispatch(importPolls([poll]));
}; };
} }
export function importErrorWhileFetchingAccountByUsername(username) { export function importErrorWhileFetchingAccountByUsername(username: string) {
return { type: ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP, username }; return { type: ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP, username };
} }
export {
ACCOUNT_IMPORT,
ACCOUNTS_IMPORT,
STATUS_IMPORT,
STATUSES_IMPORT,
POLLS_IMPORT,
ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP,
};