2020-12-16 22:29:06 +00:00
|
|
|
import debounce from 'lodash.debounce'
|
2020-12-03 04:22:51 +00:00
|
|
|
import api, { getLinks } from '../api'
|
|
|
|
import { importFetchedAccounts } from './importer'
|
|
|
|
import { me } from '../initial_state'
|
|
|
|
|
|
|
|
export const CHAT_CONVERSATION_CREATE_SEARCH_ACCOUNTS_SUCCESS = 'CHAT_CONVERSATION_CREATE_SEARCH_ACCOUNTS_SUCCESS'
|
|
|
|
|
2020-12-16 22:29:06 +00:00
|
|
|
export const CLEAR_CHAT_CONVERSATION_CREATE_SEARCH_ACCOUNTS = 'CLEAR_CHAT_CONVERSATION_CREATE_SEARCH_ACCOUNTS'
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
export const SET_CHAT_CONVERSATION_SELECTED = 'SET_CHAT_CONVERSATION_SELECTED'
|
|
|
|
|
2020-12-22 18:38:52 +00:00
|
|
|
export const SET_CHAT_CONVERSATION_SEARCH_VALUE = 'SET_CHAT_CONVERSATION_SEARCH_VALUE'
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2020-12-16 22:29:06 +00:00
|
|
|
export const fetchChatConversationAccountSuggestions = (query) => (dispatch, getState) => {
|
|
|
|
if (!query) return
|
|
|
|
debouncedFetchChatConversationAccountSuggestions(query, dispatch, getState)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const debouncedFetchChatConversationAccountSuggestions = debounce((query, dispatch, getState) => {
|
2020-12-16 07:39:07 +00:00
|
|
|
if (!query) return
|
2021-01-09 02:46:03 +00:00
|
|
|
return false
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
api(getState).get('/api/v1/accounts/search', {
|
|
|
|
params: {
|
|
|
|
q: query,
|
|
|
|
resolve: false,
|
|
|
|
limit: 4,
|
|
|
|
},
|
|
|
|
}).then((response) => {
|
|
|
|
dispatch(importFetchedAccounts(response.data))
|
|
|
|
dispatch(fetchChatConversationAccountSuggestionsSuccess(response.data))
|
|
|
|
}).catch((error) => {
|
|
|
|
//
|
|
|
|
})
|
2020-12-16 22:29:06 +00:00
|
|
|
}, 650, { leading: true })
|
2020-12-03 04:22:51 +00:00
|
|
|
|
|
|
|
const fetchChatConversationAccountSuggestionsSuccess = (accounts) => ({
|
|
|
|
type: CHAT_CONVERSATION_CREATE_SEARCH_ACCOUNTS_SUCCESS,
|
|
|
|
accounts,
|
|
|
|
})
|
|
|
|
|
2020-12-16 22:29:06 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const clearChatConversationAccountSuggestions = () => (dispatch) => {
|
|
|
|
dispatch({ type: CLEAR_CHAT_CONVERSATION_CREATE_SEARCH_ACCOUNTS })
|
|
|
|
}
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const setChatConversationSelected = (chatConversationId) => (dispatch) => {
|
|
|
|
dispatch({
|
|
|
|
type: SET_CHAT_CONVERSATION_SELECTED,
|
|
|
|
chatConversationId,
|
|
|
|
})
|
2020-12-22 18:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const onChangeSearch = (value) => (dispatch) => {
|
|
|
|
dispatch({
|
|
|
|
type: SET_CHAT_CONVERSATION_SEARCH_VALUE,
|
|
|
|
value,
|
|
|
|
})
|
2020-12-03 04:22:51 +00:00
|
|
|
}
|