Progress with DMs

Progress with DMs
This commit is contained in:
mgabdev
2020-12-03 17:13:11 -05:00
parent a129b3ce3b
commit 137a36b810
53 changed files with 539 additions and 182 deletions

View File

@@ -13,6 +13,8 @@ export const CHAT_CONVERSATIONS_APPROVED_EXPAND_REQUEST = 'CHAT_CONVERSATIONS_AP
export const CHAT_CONVERSATIONS_APPROVED_EXPAND_SUCCESS = 'CHAT_CONVERSATIONS_APPROVED_EXPAND_SUCCESS'
export const CHAT_CONVERSATIONS_APPROVED_EXPAND_FAIL = 'CHAT_CONVERSATIONS_APPROVED_EXPAND_FAIL'
export const CHAT_CONVERSATION_APPROVED_UNREAD_COUNT_FETCH_SUCCESS = 'CHAT_CONVERSATIONS_APPROVED_EXPAND_FAIL'
//
export const CHAT_CONVERSATIONS_CREATE_REQUEST = 'CHAT_CONVERSATIONS_CREATE_REQUEST'
@@ -437,6 +439,20 @@ export const fetchChatConversationRequestedCount = () => (dispatch, getState) =>
})
}
/**
*
*/
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,
})
})
}
/**
*
*/

View File

@@ -19,7 +19,7 @@ export const sendChatMessage = (text = '', chatConversationId) => (dispatch, get
if (!me || !chatConversationId) return
if (text.length === 0) return
dispatch(sendMessageRequest())
dispatch(sendChatMessageRequest(chatConversationId))
api(getState).post('/api/v1/chat_messages', {
text,
@@ -30,23 +30,23 @@ export const sendChatMessage = (text = '', chatConversationId) => (dispatch, get
// },
}).then((response) => {
dispatch(importFetchedChatMessages([response.data]))
dispatch(sendMessageSuccess(response.data, chatConversationId))
dispatch(sendChatMessageSuccess(response.data))
}).catch((error) => {
dispatch(sendMessageFail(error))
dispatch(sendChatMessageFail(error))
})
}
const sendMessageRequest = () => ({
const sendChatMessageRequest = (chatConversationId) => ({
type: CHAT_MESSAGES_SEND_REQUEST,
})
const sendMessageSuccess = (chatMessage, chatConversationId) => ({
type: CHAT_MESSAGES_SEND_SUCCESS,
chatMessage,
chatConversationId,
})
const sendMessageFail = (error) => ({
export const sendChatMessageSuccess = (chatMessage) => ({
type: CHAT_MESSAGES_SEND_SUCCESS,
chatMessage,
})
const sendChatMessageFail = (error) => ({
type: CHAT_MESSAGES_SEND_FAIL,
error,
})
@@ -54,32 +54,32 @@ const sendMessageFail = (error) => ({
/**
*
*/
const deleteMessage = (chatMessageId) => (dispatch, getState) => {
export const deleteChatMessage = (chatMessageId) => (dispatch, getState) => {
if (!me || !chatMessageId) return
dispatch(deleteMessageRequest(chatMessageId))
dispatch(deleteChatMessageRequest(chatMessageId))
api(getState).delete(`/api/v1/chat_messages/${chatMessageId}`, {}, {
// headers: {
// 'Idempotency-Key': getState().getIn(['chat_compose', 'idempotencyKey']),
// },
}).then((response) => {
deleteMessageSuccess(response)
dispatch(deleteChatMessageSuccess(response.data))
}).catch((error) => {
dispatch(deleteMessageFail(error))
dispatch(deleteChatMessageFail(error))
})
}
const deleteMessageRequest = (chatMessageId) => ({
const deleteChatMessageRequest = (chatMessageId) => ({
type: CHAT_MESSAGES_DELETE_REQUEST,
chatMessageId,
})
const deleteMessageSuccess = () => ({
const deleteChatMessageSuccess = () => ({
type: CHAT_MESSAGES_DELETE_SUCCESS,
})
const deleteMessageFail = (error) => ({
const deleteChatMessageFail = (error) => ({
type: CHAT_MESSAGES_DELETE_FAIL,
error,
})

View File

@@ -6,6 +6,7 @@ import {
updateTimelineQueue,
} from './timelines'
import { updateNotificationsQueue } from './notifications'
import { sendChatMessageSuccess } from './chat_messages'
import { fetchFilters } from './filters'
import { getLocale } from '../locales'
import { handleComposeSubmit } from './compose'
@@ -76,17 +77,15 @@ export const connectUserStream = () => connectTimelineStream('home', 'user')
*
*/
export const connectChatMessagesStream = (accountId) => {
return connectStream(`chat_messages:${accountId}`, null, (dispatch, getState) => {
return connectStream(`chat_messages`, null, (dispatch, getState) => {
return {
onConnect() {
// console.log("chat messages connected")
},
onDisconnect() {
// console.log("chat messages disconnected")
},
onConnect() {},
onDisconnect() {},
onReceive (data) {
// : todo :
console.log("chat messages onReceive:", data)
if (!data['event'] || !data['payload']) return
if (data.event === 'notification') {
dispatch(sendChatMessageSuccess(JSON.parse(data.payload)))
}
},
}
})