2020-11-25 21:22:37 +00:00
|
|
|
import api, { getLinks } from '../api'
|
2020-12-21 23:30:46 +00:00
|
|
|
import debounce from 'lodash.debounce'
|
2020-11-25 21:22:37 +00:00
|
|
|
import { importFetchedAccounts } from './importer'
|
2020-12-22 06:36:38 +00:00
|
|
|
import { closeModal } from './modal'
|
|
|
|
import { setChatConversationSelected } from './chats'
|
2020-11-25 21:22:37 +00:00
|
|
|
import { me } from '../initial_state'
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
export const CHAT_CONVERSATIONS_APPROVED_FETCH_REQUEST = 'CHAT_CONVERSATIONS_APPROVED_FETCH_REQUEST'
|
|
|
|
export const CHAT_CONVERSATIONS_APPROVED_FETCH_SUCCESS = 'CHAT_CONVERSATIONS_APPROVED_FETCH_SUCCESS'
|
|
|
|
export const CHAT_CONVERSATIONS_APPROVED_FETCH_FAIL = 'CHAT_CONVERSATIONS_APPROVED_FETCH_FAIL'
|
|
|
|
|
|
|
|
export const CHAT_CONVERSATIONS_APPROVED_EXPAND_REQUEST = 'CHAT_CONVERSATIONS_APPROVED_EXPAND_REQUEST'
|
|
|
|
export const CHAT_CONVERSATIONS_APPROVED_EXPAND_SUCCESS = 'CHAT_CONVERSATIONS_APPROVED_EXPAND_SUCCESS'
|
|
|
|
export const CHAT_CONVERSATIONS_APPROVED_EXPAND_FAIL = 'CHAT_CONVERSATIONS_APPROVED_EXPAND_FAIL'
|
|
|
|
|
2020-12-21 23:30:46 +00:00
|
|
|
export const CHAT_CONVERSATION_APPROVED_UNREAD_COUNT_FETCH_SUCCESS = 'CHAT_CONVERSATION_APPROVED_UNREAD_COUNT_FETCH_SUCCESS'
|
|
|
|
|
|
|
|
export const CHAT_CONVERSATION_APPROVED_SEARCH_FETCH_SUCCESS = 'CHAT_CONVERSATION_APPROVED_SEARCH_FETCH_SUCCESS'
|
2020-12-03 22:13:11 +00:00
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
export const CHAT_CONVERSATIONS_CREATE_REQUEST = 'CHAT_CONVERSATIONS_CREATE_REQUEST'
|
|
|
|
export const CHAT_CONVERSATIONS_CREATE_SUCCESS = 'CHAT_CONVERSATIONS_CREATE_SUCCESS'
|
|
|
|
export const CHAT_CONVERSATIONS_CREATE_FAIL = 'CHAT_CONVERSATIONS_CREATE_FAIL'
|
|
|
|
|
|
|
|
export const CHAT_CONVERSATIONS_DELETE_REQUEST = 'CHAT_CONVERSATIONS_DELETE_REQUEST'
|
|
|
|
export const CHAT_CONVERSATIONS_DELETE_SUCCESS = 'CHAT_CONVERSATIONS_DELETE_SUCCESS'
|
|
|
|
export const CHAT_CONVERSATIONS_DELETE_FAIL = 'CHAT_CONVERSATIONS_DELETE_FAIL'
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
export const CHAT_CONVERSATION_REQUESTED_COUNT_FETCH_SUCCESS = 'CHAT_CONVERSATION_REQUESTED_COUNT_FETCH_SUCCESS'
|
2020-11-25 21:22:37 +00:00
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
export const CHAT_CONVERSATIONS_REQUESTED_FETCH_REQUEST = 'CHAT_CONVERSATIONS_REQUESTED_FETCH_REQUEST'
|
|
|
|
export const CHAT_CONVERSATIONS_REQUESTED_FETCH_SUCCESS = 'CHAT_CONVERSATIONS_REQUESTED_FETCH_SUCCESS'
|
|
|
|
export const CHAT_CONVERSATIONS_REQUESTED_FETCH_FAIL = 'CHAT_CONVERSATIONS_REQUESTED_FETCH_FAIL'
|
2020-11-25 21:22:37 +00:00
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
export const CHAT_CONVERSATIONS_REQUESTED_EXPAND_REQUEST = 'CHAT_CONVERSATIONS_REQUESTED_EXPAND_REQUEST'
|
|
|
|
export const CHAT_CONVERSATIONS_REQUESTED_EXPAND_SUCCESS = 'CHAT_CONVERSATIONS_REQUESTED_EXPAND_SUCCESS'
|
|
|
|
export const CHAT_CONVERSATIONS_REQUESTED_EXPAND_FAIL = 'CHAT_CONVERSATIONS_REQUESTED_EXPAND_FAIL'
|
2020-11-25 21:22:37 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
2020-12-21 23:30:46 +00:00
|
|
|
export const CHAT_CONVERSATIONS_MUTED_FETCH_REQUEST = 'CHAT_CONVERSATIONS_MUTED_FETCH_REQUEST'
|
|
|
|
export const CHAT_CONVERSATIONS_MUTED_FETCH_SUCCESS = 'CHAT_CONVERSATIONS_MUTED_FETCH_SUCCESS'
|
|
|
|
export const CHAT_CONVERSATIONS_MUTED_FETCH_FAIL = 'CHAT_CONVERSATIONS_MUTED_FETCH_FAIL'
|
|
|
|
|
|
|
|
export const CHAT_CONVERSATIONS_MUTED_EXPAND_REQUEST = 'CHAT_CONVERSATIONS_MUTED_EXPAND_REQUEST'
|
|
|
|
export const CHAT_CONVERSATIONS_MUTED_EXPAND_SUCCESS = 'CHAT_CONVERSATIONS_MUTED_EXPAND_SUCCESS'
|
|
|
|
export const CHAT_CONVERSATIONS_MUTED_EXPAND_FAIL = 'CHAT_CONVERSATIONS_MUTED_EXPAND_FAIL'
|
|
|
|
|
|
|
|
//
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
export const CHAT_CONVERSATION_REQUEST_APPROVE_SUCCESS = 'CHAT_CONVERSATION_REQUEST_APPROVE_SUCCESS'
|
|
|
|
export const CHAT_CONVERSATION_REQUEST_APPROVE_FAIL = 'CHAT_CONVERSATION_REQUEST_APPROVE_FAIL'
|
|
|
|
|
|
|
|
export const CHAT_CONVERSATION_DELETE_REQUEST = 'CHAT_CONVERSATION_DELETE_REQUEST'
|
|
|
|
export const CHAT_CONVERSATION_DELETE_SUCCESS = 'CHAT_CONVERSATION_DELETE_SUCCESS'
|
|
|
|
export const CHAT_CONVERSATION_DELETE_FAIL = 'CHAT_CONVERSATION_DELETE_FAIL'
|
|
|
|
|
2020-12-16 00:31:30 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
export const CHAT_CONVERSATION_MARK_READ_FETCH = 'CHAT_CONVERSATION_MARK_READ_FETCH'
|
|
|
|
export const CHAT_CONVERSATION_MARK_READ_SUCCESS = 'CHAT_CONVERSATION_MARK_READ_SUCCESS'
|
|
|
|
export const CHAT_CONVERSATION_MARK_READ_FAIL = 'CHAT_CONVERSATION_MARK_READ_FAIL'
|
|
|
|
|
|
|
|
export const CHAT_CONVERSATION_HIDE_FETCH = 'CHAT_CONVERSATION_HIDE_FETCH'
|
|
|
|
export const CHAT_CONVERSATION_HIDE_SUCCESS = 'CHAT_CONVERSATION_HIDE_SUCCESS'
|
|
|
|
export const CHAT_CONVERSATION_HIDE_FAIL = 'CHAT_CONVERSATION_HIDE_FAIL'
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
export const SET_CHAT_CONVERSATION_EXPIRATION_REQUEST = 'SET_CHAT_CONVERSATION_EXPIRATION_REQUEST'
|
|
|
|
export const SET_CHAT_CONVERSATION_EXPIRATION_SUCCESS = 'SET_CHAT_CONVERSATION_EXPIRATION_SUCCESS'
|
|
|
|
export const SET_CHAT_CONVERSATION_EXPIRATION_FAIL = 'SET_CHAT_CONVERSATION_EXPIRATION_FAIL'
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
/**
|
2020-12-10 16:51:45 +00:00
|
|
|
* @description Fetch paginated active chat conversations, import accounts and set chat converations
|
2020-12-03 04:22:51 +00:00
|
|
|
*/
|
|
|
|
export const fetchChatConversations = () => (dispatch, getState) => {
|
|
|
|
if (!me) return
|
|
|
|
|
|
|
|
dispatch(fetchChatConversationsRequest())
|
|
|
|
|
|
|
|
api(getState).get('/api/v1/chat_conversations/approved_conversations').then((response) => {
|
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next')
|
|
|
|
const conversationsAccounts = [].concat.apply([], response.data.map((c) => c.other_accounts))
|
2020-12-10 16:51:45 +00:00
|
|
|
// const conversationsChatMessages = response.data.map((c) => c.last_chat_message)
|
2020-12-03 04:22:51 +00:00
|
|
|
|
|
|
|
dispatch(importFetchedAccounts(conversationsAccounts))
|
|
|
|
// dispatch(importFetchedChatMessages(conversationsChatMessages))
|
|
|
|
dispatch(fetchChatConversationsSuccess(response.data, next ? next.uri : null))
|
|
|
|
}).catch((error) => {
|
|
|
|
dispatch(fetchChatConversationsFail(error))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchChatConversationsRequest = () => ({
|
|
|
|
type: CHAT_CONVERSATIONS_APPROVED_FETCH_REQUEST,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const fetchChatConversationsSuccess = (chatConversations, next) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_APPROVED_FETCH_SUCCESS,
|
|
|
|
chatConversations,
|
|
|
|
next,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const fetchChatConversationsFail = (error) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_APPROVED_FETCH_FAIL,
|
2020-12-10 16:51:45 +00:00
|
|
|
showToast: true,
|
2020-12-03 04:22:51 +00:00
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
2020-12-10 16:51:45 +00:00
|
|
|
* @description Expand paginated active chat conversations, import accounts and set chat converations
|
2020-12-03 04:22:51 +00:00
|
|
|
*/
|
|
|
|
export const expandChatConversations = () => (dispatch, getState) => {
|
|
|
|
if (!me) return
|
|
|
|
|
|
|
|
const url = getState().getIn(['chat_conversations', 'approved', 'next'])
|
|
|
|
const isLoading = getState().getIn(['chat_conversations', 'approved', 'isLoading'])
|
|
|
|
|
|
|
|
if (url === null || isLoading) return
|
|
|
|
|
|
|
|
dispatch(expandChatConversationsRequest())
|
|
|
|
|
|
|
|
api(getState).get(url).then(response => {
|
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next')
|
|
|
|
const conversationsAccounts = [].concat.apply([], response.data.map((c) => c.other_accounts))
|
2020-12-10 16:51:45 +00:00
|
|
|
// const conversationsChatMessages = response.data.map((c) => c.last_chat_message)
|
2020-12-03 04:22:51 +00:00
|
|
|
|
|
|
|
dispatch(importFetchedAccounts(conversationsAccounts))
|
|
|
|
// dispatch(importFetchedChatMessages(conversationsChatMessages))
|
|
|
|
dispatch(expandChatConversationsSuccess(response.data, next ? next.uri : null))
|
2020-12-10 16:51:45 +00:00
|
|
|
}).catch((error) => dispatch(expandChatConversationsFail(error)))
|
2020-12-03 04:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const expandChatConversationsRequest = () => ({
|
|
|
|
type: CHAT_CONVERSATIONS_APPROVED_EXPAND_SUCCESS,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const expandChatConversationsSuccess = (chatConversations, next) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_APPROVED_EXPAND_SUCCESS,
|
|
|
|
chatConversations,
|
|
|
|
next,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const expandChatConversationsFail = (error) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_APPROVED_EXPAND_SUCCESS,
|
2020-12-10 16:51:45 +00:00
|
|
|
showToast: true,
|
2020-12-03 04:22:51 +00:00
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
2020-12-10 16:51:45 +00:00
|
|
|
* @description Fetch paginated requested chat conversations, import accounts and set chat converations
|
2020-12-03 04:22:51 +00:00
|
|
|
*/
|
|
|
|
export const fetchChatConversationRequested = () => (dispatch, getState) => {
|
|
|
|
if (!me) return
|
|
|
|
|
|
|
|
dispatch(fetchChatConversationRequestedRequest())
|
|
|
|
|
|
|
|
api(getState).get('/api/v1/chat_conversations/requested_conversations').then((response) => {
|
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next')
|
|
|
|
const conversationsAccounts = [].concat.apply([], response.data.map((c) => c.other_accounts))
|
2020-12-10 16:51:45 +00:00
|
|
|
// const conversationsChatMessages = response.data.map((c) => c.last_chat_message)
|
2020-12-03 04:22:51 +00:00
|
|
|
|
|
|
|
dispatch(importFetchedAccounts(conversationsAccounts))
|
|
|
|
// dispatch(importFetchedChatMessages(conversationsChatMessages))
|
|
|
|
dispatch(fetchChatConversationRequestedSuccess(response.data, next ? next.uri : null))
|
|
|
|
}).catch((error) => {
|
|
|
|
dispatch(fetchChatConversationRequestedFail(error))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchChatConversationRequestedRequest = () => ({
|
|
|
|
type: CHAT_CONVERSATIONS_REQUESTED_FETCH_REQUEST,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const fetchChatConversationRequestedSuccess = (chatConversations, next) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_REQUESTED_FETCH_SUCCESS,
|
|
|
|
chatConversations,
|
|
|
|
next,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const fetchChatConversationRequestedFail = (error) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_REQUESTED_FETCH_FAIL,
|
2020-12-10 16:51:45 +00:00
|
|
|
showToast: true,
|
2020-12-03 04:22:51 +00:00
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
2020-12-10 16:51:45 +00:00
|
|
|
* @description Expand paginated requested chat conversations, import accounts and set chat converations
|
2020-12-03 04:22:51 +00:00
|
|
|
*/
|
|
|
|
export const expandChatConversationRequested = () => (dispatch, getState) => {
|
|
|
|
if (!me) return
|
|
|
|
|
|
|
|
const url = getState().getIn(['chat_conversations', 'requested', 'next'])
|
|
|
|
const isLoading = getState().getIn(['chat_conversations', 'requested', 'isLoading'])
|
|
|
|
|
|
|
|
if (url === null || isLoading) return
|
|
|
|
|
|
|
|
dispatch(expandChatConversationRequestedRequest())
|
|
|
|
|
|
|
|
api(getState).get(url).then(response => {
|
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next')
|
|
|
|
const conversationsAccounts = [].concat.apply([], response.data.map((c) => c.other_accounts))
|
2020-12-10 16:51:45 +00:00
|
|
|
// const conversationsChatMessages = response.data.map((c) => c.last_chat_message)
|
2020-12-03 04:22:51 +00:00
|
|
|
|
|
|
|
dispatch(importFetchedAccounts(conversationsAccounts))
|
|
|
|
// dispatch(importFetchedChatMessages(conversationsChatMessages))
|
|
|
|
dispatch(expandChatConversationRequestedSuccess(response.data, next ? next.uri : null))
|
|
|
|
}).catch(error => dispatch(expandChatConversationRequestedFail(error)))
|
|
|
|
}
|
|
|
|
|
|
|
|
export const expandChatConversationRequestedRequest = () => ({
|
|
|
|
type: CHAT_CONVERSATIONS_REQUESTED_EXPAND_REQUEST,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const expandChatConversationRequestedSuccess = (chatConversations, next) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_REQUESTED_EXPAND_SUCCESS,
|
|
|
|
chatConversations,
|
|
|
|
next,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const expandChatConversationRequestedFail = (error) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_REQUESTED_EXPAND_FAIL,
|
2020-12-10 16:51:45 +00:00
|
|
|
showToast: true,
|
2020-12-03 04:22:51 +00:00
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
2020-12-21 23:30:46 +00:00
|
|
|
/**
|
|
|
|
* @description Fetch paginated muted chat conversations, import accounts and set chat converations
|
|
|
|
*/
|
|
|
|
export const fetchChatConversationMuted = () => (dispatch, getState) => {
|
|
|
|
if (!me) return
|
|
|
|
|
|
|
|
dispatch(fetchChatConversationMutedRequest())
|
|
|
|
|
|
|
|
api(getState).get('/api/v1/chat_conversations/muted_conversations').then((response) => {
|
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next')
|
|
|
|
const conversationsAccounts = [].concat.apply([], response.data.map((c) => c.other_accounts))
|
|
|
|
// const conversationsChatMessages = response.data.map((c) => c.last_chat_message)
|
|
|
|
|
|
|
|
dispatch(importFetchedAccounts(conversationsAccounts))
|
|
|
|
// dispatch(importFetchedChatMessages(conversationsChatMessages))
|
|
|
|
dispatch(fetchChatConversationMutedSuccess(response.data, next ? next.uri : null))
|
|
|
|
}).catch((error) => {
|
|
|
|
dispatch(fetchChatConversationMutedFail(error))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchChatConversationMutedRequest = () => ({
|
|
|
|
type: CHAT_CONVERSATIONS_MUTED_FETCH_REQUEST,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const fetchChatConversationMutedSuccess = (chatConversations, next) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_MUTED_FETCH_SUCCESS,
|
|
|
|
chatConversations,
|
|
|
|
next,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const fetchChatConversationMutedFail = (error) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_MUTED_FETCH_FAIL,
|
|
|
|
showToast: true,
|
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description Expand paginated muted chat conversations, import accounts and set chat converations
|
|
|
|
*/
|
|
|
|
export const expandChatConversationMuted = () => (dispatch, getState) => {
|
|
|
|
if (!me) return
|
|
|
|
|
|
|
|
const url = getState().getIn(['chat_conversations', 'muted', 'next'])
|
|
|
|
const isLoading = getState().getIn(['chat_conversations', 'muted', 'isLoading'])
|
|
|
|
|
|
|
|
if (url === null || isLoading) return
|
|
|
|
|
|
|
|
dispatch(expandChatConversationMutedRequest())
|
|
|
|
|
|
|
|
api(getState).get(url).then(response => {
|
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next')
|
|
|
|
const conversationsAccounts = [].concat.apply([], response.data.map((c) => c.other_accounts))
|
|
|
|
// const conversationsChatMessages = response.data.map((c) => c.last_chat_message)
|
|
|
|
|
|
|
|
dispatch(importFetchedAccounts(conversationsAccounts))
|
|
|
|
// dispatch(importFetchedChatMessages(conversationsChatMessages))
|
|
|
|
dispatch(expandChatConversationMutedSuccess(response.data, next ? next.uri : null))
|
|
|
|
}).catch(error => dispatch(expandChatConversationMutedFail(error)))
|
|
|
|
}
|
|
|
|
|
|
|
|
export const expandChatConversationMutedRequest = () => ({
|
|
|
|
type: CHAT_CONVERSATIONS_MUTED_EXPAND_REQUEST,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const expandChatConversationMutedSuccess = (chatConversations, next) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_MUTED_EXPAND_SUCCESS,
|
|
|
|
chatConversations,
|
|
|
|
next,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const expandChatConversationMutedFail = (error) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_MUTED_EXPAND_FAIL,
|
|
|
|
showToast: true,
|
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
/**
|
2020-12-10 16:51:45 +00:00
|
|
|
* @description Create a chat conversation with given accountId. May fail because of blocks.
|
|
|
|
* @param {String} accountId
|
2020-12-03 04:22:51 +00:00
|
|
|
*/
|
2020-12-22 06:36:38 +00:00
|
|
|
export const createChatConversation = (accountId, routerHistory) => (dispatch, getState) => {
|
2020-12-03 04:22:51 +00:00
|
|
|
if (!me || !accountId) return
|
|
|
|
|
|
|
|
dispatch(createChatConversationRequest())
|
|
|
|
|
|
|
|
api(getState).post('/api/v1/chat_conversation', { account_id: accountId }).then((response) => {
|
|
|
|
dispatch(createChatConversationSuccess(response.data))
|
2020-12-22 06:36:38 +00:00
|
|
|
dispatch(closeModal())
|
|
|
|
dispatch(setChatConversationSelected(response.data.chat_conversation_id))
|
|
|
|
if (routerHistory) routerHistory.push(`/messages/${response.data.chat_conversation_id}`)
|
2020-12-03 04:22:51 +00:00
|
|
|
}).catch((error) => {
|
|
|
|
dispatch(createChatConversationFail(error))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const createChatConversationRequest = () => ({
|
|
|
|
type: CHAT_CONVERSATIONS_CREATE_REQUEST,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const createChatConversationSuccess = (chatConversation) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_CREATE_SUCCESS,
|
2020-12-10 16:51:45 +00:00
|
|
|
showToast: true,
|
2020-12-03 04:22:51 +00:00
|
|
|
chatConversation,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const createChatConversationFail = (error) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_CREATE_FAIL,
|
2020-12-10 16:51:45 +00:00
|
|
|
showToast: true,
|
2020-12-03 04:22:51 +00:00
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
2020-12-10 16:51:45 +00:00
|
|
|
* @description Delete a chat conversation with given chatConversationId.
|
|
|
|
* @param {String} chatConversationId
|
2020-12-03 04:22:51 +00:00
|
|
|
*/
|
|
|
|
export const deleteChatConversation = (chatConversationId) => (dispatch, getState) => {
|
2020-12-10 16:51:45 +00:00
|
|
|
// : todo :
|
2020-12-03 04:22:51 +00:00
|
|
|
if (!me || !chatConversationId) return
|
|
|
|
|
|
|
|
dispatch(deleteChatConversationRequest(conversationId))
|
|
|
|
|
|
|
|
api(getState).delete(`/api/v1/chat_conversation/${chatConversationId}`).then((response) => {
|
|
|
|
dispatch(deleteChatConversationSuccess())
|
|
|
|
}).catch((error) => {
|
|
|
|
dispatch(deleteChatConversationFail(error))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const deleteChatConversationRequest = (conversationId) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_DELETE_REQUEST,
|
|
|
|
conversationId,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const deleteChatConversationSuccess = () => ({
|
|
|
|
type: CHAT_CONVERSATIONS_DELETE_SUCCESS,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const deleteChatConversationFail = (error) => ({
|
|
|
|
type: CHAT_CONVERSATIONS_DELETE_FAIL,
|
|
|
|
error,
|
|
|
|
})
|
2020-11-25 21:22:37 +00:00
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const fetchChatConversationRequestedCount = () => (dispatch, getState) => {
|
|
|
|
if (!me) return
|
|
|
|
|
|
|
|
api(getState).get('/api/v1/chat_conversations/requested_conversations/count').then(response => {
|
|
|
|
dispatch({
|
|
|
|
type: CHAT_CONVERSATION_REQUESTED_COUNT_FETCH_SUCCESS,
|
|
|
|
count: response.data,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-12-03 22:13:11 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const fetchChatConversationUnreadCount = () => (dispatch, getState) => {
|
|
|
|
if (!me) return
|
|
|
|
|
|
|
|
api(getState).get('/api/v1/chat_conversations/approved_conversations/unread_count').then(response => {
|
|
|
|
dispatch({
|
|
|
|
type: CHAT_CONVERSATION_APPROVED_UNREAD_COUNT_FETCH_SUCCESS,
|
|
|
|
count: response.data,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const approveChatConversationRequest = (chatConversationId) => (dispatch, getState) => {
|
|
|
|
if (!me|| !chatConversationId) return
|
|
|
|
|
|
|
|
api(getState).post(`/api/v1/chat_conversation/${chatConversationId}/mark_chat_conversation_approved`).then((response) => {
|
|
|
|
dispatch(approveChatConversationRequestSuccess(response.data))
|
|
|
|
}).catch((error) => dispatch(approveChatConversationRequestFail(error)))
|
|
|
|
}
|
|
|
|
|
|
|
|
export const approveChatConversationRequestSuccess = (chatConversation) => ({
|
|
|
|
type: CHAT_CONVERSATION_REQUEST_APPROVE_SUCCESS,
|
|
|
|
chatConversation,
|
2020-11-25 21:22:37 +00:00
|
|
|
})
|
2020-12-03 04:22:51 +00:00
|
|
|
|
|
|
|
export const approveChatConversationRequestFail = () => ({
|
|
|
|
type: CHAT_CONVERSATION_REQUEST_APPROVE_FAIL,
|
2020-12-16 00:31:30 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const hideChatConversation = (chatConversationId) => (dispatch, getState) => {
|
|
|
|
if (!me|| !chatConversationId) return
|
|
|
|
|
|
|
|
dispatch(hideChatConversationFetch(chatConversationId))
|
|
|
|
|
|
|
|
api(getState).post(`/api/v1/chat_conversation/${chatConversationId}/mark_chat_conversation_hidden`).then((response) => {
|
|
|
|
dispatch(approveChatConversationRequestSuccess(chatConversationId))
|
|
|
|
}).catch((error) => dispatch(approveChatConversationRequestFail(error)))
|
|
|
|
}
|
|
|
|
|
|
|
|
export const hideChatConversationFetch = (chatConversationId) => ({
|
|
|
|
type: CHAT_CONVERSATION_HIDE_SUCCESS,
|
|
|
|
chatConversationId,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const hideChatConversationSuccess = (chatConversationId) => ({
|
|
|
|
type: CHAT_CONVERSATION_HIDE_SUCCESS,
|
|
|
|
chatConversationId,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const hideChatConversationFail = () => ({
|
|
|
|
type: CHAT_CONVERSATION_HIDE_FAIL,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const readChatConversation = (chatConversationId) => (dispatch, getState) => {
|
|
|
|
if (!me|| !chatConversationId) return
|
|
|
|
|
|
|
|
const chatConversation = getState().getIn(['chat_conversations', chatConversationId])
|
|
|
|
if (!chatConversation) return
|
|
|
|
if (chatConversation.get('unread_count') < 1) return
|
|
|
|
|
|
|
|
dispatch(readChatConversationFetch(chatConversation))
|
|
|
|
|
|
|
|
api(getState).post(`/api/v1/chat_conversation/${chatConversationId}/mark_chat_conversation_read`).then((response) => {
|
|
|
|
dispatch(readChatConversationSuccess(response.data))
|
|
|
|
}).catch((error) => dispatch(readChatConversationFail(error)))
|
|
|
|
}
|
|
|
|
|
|
|
|
export const readChatConversationFetch = (chatConversation) => ({
|
|
|
|
type: CHAT_CONVERSATION_MARK_READ_FETCH,
|
|
|
|
chatConversation,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const readChatConversationSuccess = (chatConversation) => ({
|
|
|
|
type: CHAT_CONVERSATION_MARK_READ_SUCCESS,
|
|
|
|
chatConversation,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const readChatConversationFail = () => ({
|
|
|
|
type: CHAT_CONVERSATION_MARK_READ_FAIL,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const setChatConversationExpiration = (chatConversationId, expiration) => (dispatch, getState) => {
|
2020-12-19 06:33:33 +00:00
|
|
|
if (!me|| !chatConversationId) return
|
2020-12-16 00:31:30 +00:00
|
|
|
|
2020-12-19 06:33:33 +00:00
|
|
|
dispatch(setChatConversationExpirationFetch(chatConversationId))
|
2020-12-16 00:31:30 +00:00
|
|
|
|
|
|
|
api(getState).post(`/api/v1/chat_conversation/${chatConversationId}/set_expiration_policy`, {
|
|
|
|
expiration,
|
|
|
|
}).then((response) => {
|
|
|
|
dispatch(setChatConversationExpirationSuccess(response.data))
|
|
|
|
}).catch((error) => dispatch(setChatConversationExpirationFail(error)))
|
|
|
|
}
|
|
|
|
|
2020-12-19 06:33:33 +00:00
|
|
|
export const setChatConversationExpirationFetch = (chatConversationId) => ({
|
2020-12-16 00:31:30 +00:00
|
|
|
type: SET_CHAT_CONVERSATION_EXPIRATION_REQUEST,
|
2020-12-19 06:33:33 +00:00
|
|
|
chatConversationId,
|
2020-12-16 00:31:30 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
export const setChatConversationExpirationSuccess = (chatConversation) => ({
|
2020-12-19 06:33:33 +00:00
|
|
|
type: SET_CHAT_CONVERSATION_EXPIRATION_SUCCESS,
|
2020-12-16 00:31:30 +00:00
|
|
|
chatConversation,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const setChatConversationExpirationFail = (error) => ({
|
2020-12-19 06:33:33 +00:00
|
|
|
type: SET_CHAT_CONVERSATION_EXPIRATION_FAIL,
|
2020-12-16 00:31:30 +00:00
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
2020-12-21 23:30:46 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const fetchChatConversationAccountSuggestions = (query) => (dispatch, getState) => {
|
|
|
|
if (!query) return
|
|
|
|
debouncedFetchChatConversationAccountSuggestions(query, dispatch, getState)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const debouncedFetchChatConversationAccountSuggestions = debounce((query, dispatch, getState) => {
|
|
|
|
if (!query) return
|
|
|
|
|
|
|
|
api(getState).get('/api/v1/accounts/search', {
|
|
|
|
params: {
|
|
|
|
q: query,
|
|
|
|
resolve: false,
|
|
|
|
limit: 4,
|
|
|
|
},
|
|
|
|
}).then((response) => {
|
|
|
|
// const next = getLinks(response).refs.find(link => link.rel === 'next')
|
|
|
|
// const conversationsAccounts = [].concat.apply([], response.data.map((c) => c.other_accounts))
|
|
|
|
|
|
|
|
dispatch(importFetchedAccounts(response.data))
|
|
|
|
|
|
|
|
// dispatch(importFetchedAccounts(conversationsAccounts))
|
|
|
|
// dispatch(importFetchedChatMessages(conversationsChatMessages))
|
|
|
|
// dispatch(fetchChatConversationsSuccess(response.data, next ? next.uri : null))
|
|
|
|
|
|
|
|
dispatch(fetchChatConversationAccountSuggestionsSuccess(response.data))
|
|
|
|
}).catch((error) => {
|
|
|
|
//
|
|
|
|
})
|
|
|
|
}, 650, { leading: true })
|
|
|
|
|
|
|
|
const fetchChatConversationAccountSuggestionsSuccess = (chatConversations) => ({
|
|
|
|
type: CHAT_CONVERSATION_APPROVED_SEARCH_FETCH_SUCCESS,
|
|
|
|
chatConversations,
|
|
|
|
})
|