2020-12-10 16:51:45 +00:00
|
|
|
import api, { getLinks } from '../api'
|
|
|
|
import { importFetchedAccounts } from './importer'
|
|
|
|
import { me } from '../initial_state'
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
export const CHAT_MESSENGER_BLOCKS_FETCH_REQUEST = 'CHAT_MESSENGER_BLOCKS_FETCH_REQUEST'
|
|
|
|
export const CHAT_MESSENGER_BLOCKS_FETCH_SUCCESS = 'CHAT_MESSENGER_BLOCKS_FETCH_SUCCESS'
|
|
|
|
export const CHAT_MESSENGER_BLOCKS_FETCH_FAIL = 'CHAT_MESSENGER_BLOCKS_FETCH_FAIL'
|
|
|
|
|
|
|
|
export const CHAT_MESSENGER_BLOCKS_EXPAND_REQUEST = 'CHAT_MESSENGER_BLOCKS_EXPAND_REQUEST'
|
|
|
|
export const CHAT_MESSENGER_BLOCKS_EXPAND_SUCCESS = 'CHAT_MESSENGER_BLOCKS_EXPAND_SUCCESS'
|
|
|
|
export const CHAT_MESSENGER_BLOCKS_EXPAND_FAIL = 'CHAT_MESSENGER_BLOCKS_EXPAND_FAIL'
|
|
|
|
|
|
|
|
export const BLOCK_CHAT_MESSAGER_REQUEST = 'BLOCK_CHAT_MESSAGER_REQUEST'
|
|
|
|
export const BLOCK_CHAT_MESSAGER_SUCCESS = 'BLOCK_CHAT_MESSAGER_SUCCESS'
|
|
|
|
export const BLOCK_CHAT_MESSAGER_FAIL = 'BLOCK_CHAT_MESSAGER_FAIL'
|
|
|
|
|
|
|
|
export const UNBLOCK_CHAT_MESSAGER_REQUEST = 'UNBLOCK_CHAT_MESSAGER_REQUEST'
|
|
|
|
export const UNBLOCK_CHAT_MESSAGER_SUCCESS = 'UNBLOCK_CHAT_MESSAGER_SUCCESS'
|
|
|
|
export const UNBLOCK_CHAT_MESSAGER_FAIL = 'UNBLOCK_CHAT_MESSAGER_FAIL'
|
|
|
|
|
2020-12-19 06:33:33 +00:00
|
|
|
export const FETCH_CHAT_MESSENGER_BLOCKING_RELATIONSHIPS_SUCCESS = 'FETCH_CHAT_MESSENGER_BLOCKING_RELATIONSHIPS_SUCCESS'
|
2020-12-10 16:51:45 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
export const MUTE_CHAT_CONVERSATION_REQUEST = 'MUTE_CHAT_CONVERSATION_REQUEST'
|
|
|
|
export const MUTE_CHAT_CONVERSATION_SUCCESS = 'MUTE_CHAT_CONVERSATION_SUCCESS'
|
|
|
|
export const MUTE_CHAT_CONVERSATION_FAIL = 'MUTE_CHAT_CONVERSATION_FAIL'
|
2020-12-10 16:51:45 +00:00
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
export const UNMUTE_CHAT_CONVERSATION_REQUEST = 'UNMUTE_CHAT_CONVERSATION_REQUEST'
|
|
|
|
export const UNMUTE_CHAT_CONVERSATION_SUCCESS = 'UNMUTE_CHAT_CONVERSATION_SUCCESS'
|
|
|
|
export const UNMUTE_CHAT_CONVERSATION_FAIL = 'UNMUTE_CHAT_CONVERSATION_FAIL'
|
2020-12-10 16:51:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const blockChatMessenger = (accountId) => (dispatch, getState) => {
|
|
|
|
if (!me || !accountId) return
|
|
|
|
|
|
|
|
dispatch(blockChatMessengerRequest(accountId))
|
|
|
|
|
2020-12-19 06:33:33 +00:00
|
|
|
api(getState).post(`/api/v1/chat_conversation_accounts/_/block_messenger`, { account_id: accountId }).then((response) => {
|
2020-12-22 06:36:38 +00:00
|
|
|
dispatch(blockChatMessengerSuccess(response))
|
2020-12-10 16:51:45 +00:00
|
|
|
}).catch((error) => {
|
|
|
|
dispatch(blockChatMessengerFail(accountId, error))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const blockChatMessengerRequest = (accountId) => ({
|
|
|
|
type: BLOCK_CHAT_MESSAGER_REQUEST,
|
|
|
|
accountId,
|
|
|
|
})
|
|
|
|
|
2020-12-19 06:33:33 +00:00
|
|
|
const blockChatMessengerSuccess = (data) => ({
|
2020-12-10 16:51:45 +00:00
|
|
|
type: BLOCK_CHAT_MESSAGER_SUCCESS,
|
2020-12-19 06:33:33 +00:00
|
|
|
data,
|
2020-12-10 16:51:45 +00:00
|
|
|
showToast: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
const blockChatMessengerFail = (accountId, error) => ({
|
|
|
|
type: BLOCK_CHAT_MESSAGER_FAIL,
|
|
|
|
showToast: true,
|
|
|
|
accountId,
|
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const unblockChatMessenger = (accountId) => (dispatch, getState) => {
|
|
|
|
if (!me || !accountId) return
|
|
|
|
|
|
|
|
dispatch(unblockChatMessengerRequest(accountId))
|
|
|
|
|
2020-12-19 06:33:33 +00:00
|
|
|
api(getState).post(`/api/v1/chat_conversation_accounts/_/unblock_messenger`, { account_id: accountId }).then((response) => {
|
2020-12-22 06:36:38 +00:00
|
|
|
dispatch(unblockChatMessengerSuccess(response))
|
2020-12-10 16:51:45 +00:00
|
|
|
}).catch((error) => {
|
|
|
|
dispatch(unblockChatMessengerFail(accountId, error))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const unblockChatMessengerRequest = (accountId) => ({
|
|
|
|
type: UNBLOCK_CHAT_MESSAGER_REQUEST,
|
|
|
|
accountId,
|
|
|
|
})
|
|
|
|
|
2020-12-19 06:33:33 +00:00
|
|
|
const unblockChatMessengerSuccess = (data) => ({
|
2020-12-16 07:39:07 +00:00
|
|
|
type: UNBLOCK_CHAT_MESSAGER_SUCCESS,
|
2020-12-19 06:33:33 +00:00
|
|
|
data,
|
2020-12-10 16:51:45 +00:00
|
|
|
showToast: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
const unblockChatMessengerFail = (accountId, error) => ({
|
2020-12-16 07:39:07 +00:00
|
|
|
type: UNBLOCK_CHAT_MESSAGER_FAIL,
|
2020-12-10 16:51:45 +00:00
|
|
|
showToast: true,
|
|
|
|
accountId,
|
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description Check if a chat messenger is blocked by the current user account.
|
|
|
|
* @param {String} accountId
|
|
|
|
*/
|
2020-12-19 06:33:33 +00:00
|
|
|
export const fetchMessengerBlockingRelationships = (accountId) => (dispatch, getState) => {
|
2020-12-10 16:51:45 +00:00
|
|
|
if (!me || !accountId) return
|
|
|
|
|
2020-12-19 06:33:33 +00:00
|
|
|
api(getState).post(`/api/v1/chat_conversation_accounts/_/messenger_block_relationships`, { account_id: accountId }).then((response) => {
|
|
|
|
dispatch(fetchMessengerBlockingRelationshipsSuccess(response.data))
|
2020-12-10 16:51:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-12-19 06:33:33 +00:00
|
|
|
const fetchMessengerBlockingRelationshipsSuccess = (data) => ({
|
|
|
|
type: FETCH_CHAT_MESSENGER_BLOCKING_RELATIONSHIPS_SUCCESS,
|
2020-12-10 16:51:45 +00:00
|
|
|
data,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const fetchChatMessengerBlocks = () => (dispatch, getState) => {
|
|
|
|
if (!me) return
|
|
|
|
|
|
|
|
dispatch(fetchChatMessengerBlocksRequest())
|
|
|
|
|
2020-12-21 23:30:46 +00:00
|
|
|
api(getState).get('/api/v1/chat_conversations/blocked_chat_accounts').then(response => {
|
2020-12-10 16:51:45 +00:00
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next')
|
|
|
|
dispatch(importFetchedAccounts(response.data))
|
|
|
|
dispatch(fetchChatMessengerBlocksSuccess(response.data, next ? next.uri : null))
|
|
|
|
}).catch(error => dispatch(fetchChatMessengerBlocksFail(error)))
|
|
|
|
}
|
|
|
|
|
|
|
|
export const fetchChatMessengerBlocksRequest = () => ({
|
|
|
|
type: CHAT_MESSENGER_BLOCKS_FETCH_REQUEST,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const fetchChatMessengerBlocksSuccess = (accounts, next) => ({
|
|
|
|
type: CHAT_MESSENGER_BLOCKS_FETCH_SUCCESS,
|
|
|
|
accounts,
|
|
|
|
next,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const fetchChatMessengerBlocksFail = (error) => ({
|
|
|
|
type: CHAT_MESSENGER_BLOCKS_FETCH_FAIL,
|
|
|
|
showToast: true,
|
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export const expandChatMessengerBlocks = () => (dispatch, getState) => {
|
|
|
|
if (!me) return
|
|
|
|
|
|
|
|
const url = getState().getIn(['user_lists', 'chat_blocks', me, 'next'])
|
|
|
|
const isLoading = getState().getIn(['user_lists', 'chat_blocks', me, 'isLoading'])
|
|
|
|
|
|
|
|
if (url === null || isLoading) return
|
|
|
|
|
|
|
|
dispatch(expandChatMessengerBlocksRequest())
|
|
|
|
|
|
|
|
api(getState).get(url).then(response => {
|
|
|
|
const next = getLinks(response).refs.find(link => link.rel === 'next')
|
|
|
|
dispatch(importFetchedAccounts(response.data))
|
|
|
|
dispatch(expandChatMessengerBlocksSuccess(response.data, next ? next.uri : null))
|
|
|
|
}).catch(error => dispatch(expandChatMessengerBlocksFail(error)))
|
|
|
|
}
|
|
|
|
|
|
|
|
export const expandChatMessengerBlocksRequest = () => ({
|
|
|
|
type: CHAT_MESSENGER_BLOCKS_EXPAND_REQUEST,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const expandChatMessengerBlocksSuccess = (accounts, next) => ({
|
|
|
|
type: CHAT_MESSENGER_BLOCKS_EXPAND_SUCCESS,
|
|
|
|
accounts,
|
|
|
|
next,
|
|
|
|
})
|
|
|
|
|
|
|
|
export const expandChatMessengerBlocksFail = (error) => ({
|
|
|
|
type: CHAT_MESSENGER_BLOCKS_EXPAND_FAIL,
|
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2020-12-16 07:39:07 +00:00
|
|
|
export const muteChatConversation = (chatConversationId) => (dispatch, getState) => {
|
|
|
|
if (!me || !chatConversationId) return
|
2020-12-10 16:51:45 +00:00
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
dispatch(muteChatConversationRequest(chatConversationId))
|
2020-12-10 16:51:45 +00:00
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
api(getState).post(`/api/v1/chat_conversation_accounts/${chatConversationId}/mute_chat_conversation`).then((response) => {
|
|
|
|
dispatch(muteChatConversationSuccess(response.data))
|
2020-12-10 16:51:45 +00:00
|
|
|
}).catch((error) => {
|
2020-12-19 06:33:33 +00:00
|
|
|
dispatch(muteChatConversationFail(error))
|
2020-12-10 16:51:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
const muteChatConversationRequest = (accountId) => ({
|
|
|
|
type: MUTE_CHAT_CONVERSATION_REQUEST,
|
2020-12-10 16:51:45 +00:00
|
|
|
accountId,
|
|
|
|
})
|
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
const muteChatConversationSuccess = (chatConversation) => ({
|
|
|
|
type: MUTE_CHAT_CONVERSATION_SUCCESS,
|
|
|
|
chatConversation,
|
2020-12-10 16:51:45 +00:00
|
|
|
showToast: true,
|
|
|
|
})
|
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
const muteChatConversationFail = (error) => ({
|
|
|
|
type: MUTE_CHAT_CONVERSATION_FAIL,
|
2020-12-10 16:51:45 +00:00
|
|
|
showToast: true,
|
|
|
|
error,
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2020-12-16 07:39:07 +00:00
|
|
|
export const unmuteChatConversation = (chatConversationId) => (dispatch, getState) => {
|
|
|
|
if (!me || !chatConversationId) return
|
2020-12-10 16:51:45 +00:00
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
dispatch(unmuteChatConversationRequest(chatConversationId))
|
2020-12-10 16:51:45 +00:00
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
api(getState).post(`/api/v1/chat_conversation_accounts/${chatConversationId}/unmute_chat_conversation`).then((response) => {
|
|
|
|
dispatch(unmuteChatConversationSuccess(response.data))
|
2020-12-10 16:51:45 +00:00
|
|
|
}).catch((error) => {
|
2020-12-16 07:39:07 +00:00
|
|
|
dispatch(unmuteChatConversationFail(error))
|
2020-12-10 16:51:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
const unmuteChatConversationRequest = (accountId) => ({
|
|
|
|
type: UNMUTE_CHAT_CONVERSATION_REQUEST,
|
2020-12-10 16:51:45 +00:00
|
|
|
accountId,
|
|
|
|
})
|
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
const unmuteChatConversationSuccess = (chatConversation) => ({
|
|
|
|
type: UNMUTE_CHAT_CONVERSATION_SUCCESS,
|
|
|
|
chatConversation,
|
2020-12-10 16:51:45 +00:00
|
|
|
showToast: true,
|
|
|
|
})
|
|
|
|
|
2020-12-16 07:39:07 +00:00
|
|
|
const unmuteChatConversationFail = (accountId, error) => ({
|
|
|
|
type: UNMUTE_CHAT_CONVERSATION_FAIL,
|
2020-12-10 16:51:45 +00:00
|
|
|
showToast: true,
|
|
|
|
accountId,
|
|
|
|
error,
|
2020-12-22 18:38:52 +00:00
|
|
|
})
|