feature/IO-3000-Migrate-MSG-to-Sockets - Major Progress
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -6,6 +6,9 @@ const INITIAL_STATE = {
|
||||
isSending: false,
|
||||
error: null,
|
||||
message: null,
|
||||
conversations: [], // Holds the list of conversations
|
||||
messages: [], // Holds the list of messages for the selected conversation
|
||||
unreadCount: 0,
|
||||
searchingForConversation: false
|
||||
};
|
||||
|
||||
@@ -13,40 +16,76 @@ const messagingReducer = (state = INITIAL_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case MessagingActionTypes.SET_MESSAGE:
|
||||
return { ...state, message: action.payload };
|
||||
|
||||
case MessagingActionTypes.TOGGLE_CHAT_VISIBLE:
|
||||
return {
|
||||
...state,
|
||||
open: !state.open
|
||||
};
|
||||
|
||||
case MessagingActionTypes.OPEN_CHAT_BY_PHONE:
|
||||
return {
|
||||
...state,
|
||||
searchingForConversation: true
|
||||
};
|
||||
|
||||
case MessagingActionTypes.SET_SELECTED_CONVERSATION:
|
||||
return {
|
||||
...state,
|
||||
open: true,
|
||||
searchingForConversation: false,
|
||||
selectedConversationId: action.payload
|
||||
selectedConversationId: action.payload,
|
||||
messages: [] // Reset messages when a new conversation is selected
|
||||
};
|
||||
|
||||
case MessagingActionTypes.SEND_MESSAGE:
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
isSending: true
|
||||
};
|
||||
|
||||
case MessagingActionTypes.SEND_MESSAGE_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
message: "",
|
||||
isSending: false
|
||||
};
|
||||
|
||||
case MessagingActionTypes.SEND_MESSAGE_FAILURE:
|
||||
return {
|
||||
...state,
|
||||
error: action.payload
|
||||
error: action.payload,
|
||||
isSending: false
|
||||
};
|
||||
|
||||
case MessagingActionTypes.SET_CONVERSATIONS:
|
||||
return {
|
||||
...state,
|
||||
conversations: action.payload
|
||||
};
|
||||
|
||||
case MessagingActionTypes.ADD_MESSAGE:
|
||||
return {
|
||||
...state,
|
||||
messages: [...state.messages, action.payload]
|
||||
};
|
||||
|
||||
case MessagingActionTypes.UPDATE_UNREAD_COUNT:
|
||||
console.log("SKL");
|
||||
console.dir({ action, state });
|
||||
return {
|
||||
...state,
|
||||
conversations: Array.isArray(state.conversations)
|
||||
? state.conversations.map((conversation) =>
|
||||
conversation.id === action.payload
|
||||
? { ...conversation, unreadCount: 0 } // Reset unread count for the selected conversation
|
||||
: conversation
|
||||
)
|
||||
: state.conversations,
|
||||
unreadCount: Math.max(state.unreadCount - 1, 0) // Ensure unreadCount does not go below zero
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user