fix: Add a check for 24 hour window before sending a message (#1084)
Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import Vue from 'vue';
|
||||
import * as types from '../../mutation-types';
|
||||
import ConversationApi from '../../../api/inbox/conversation';
|
||||
import MessageApi from '../../../api/inbox/message';
|
||||
import { MESSAGE_TYPE } from 'widget/helpers/constants';
|
||||
|
||||
// actions
|
||||
const actions = {
|
||||
@@ -136,6 +137,12 @@ const actions = {
|
||||
|
||||
addMessage({ commit }, message) {
|
||||
commit(types.default.ADD_MESSAGE, message);
|
||||
if (message.message_type === MESSAGE_TYPE.INCOMING) {
|
||||
commit(types.default.SET_CONVERSATION_CAN_REPLY, {
|
||||
conversationId: message.conversation_id,
|
||||
canReply: true,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
updateMessage({ commit }, message) {
|
||||
|
||||
@@ -160,6 +160,16 @@ export const mutations = {
|
||||
[types.default.SET_ACTIVE_INBOX](_state, inboxId) {
|
||||
_state.currentInbox = inboxId ? parseInt(inboxId, 10) : null;
|
||||
},
|
||||
|
||||
[types.default.SET_CONVERSATION_CAN_REPLY](
|
||||
_state,
|
||||
{ conversationId, canReply }
|
||||
) {
|
||||
const [chat] = _state.allConversations.filter(c => c.id === conversationId);
|
||||
if (chat) {
|
||||
Vue.set(chat, 'can_reply', canReply);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
@@ -127,4 +127,30 @@ describe('#actions', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
describe('#addMessage', () => {
|
||||
it('sends correct mutations if message is incoming', () => {
|
||||
const message = {
|
||||
id: 1,
|
||||
message_type: 0,
|
||||
conversation_id: 1,
|
||||
};
|
||||
actions.addMessage({ commit }, message);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.ADD_MESSAGE, message],
|
||||
[
|
||||
types.default.SET_CONVERSATION_CAN_REPLY,
|
||||
{ conversationId: 1, canReply: true },
|
||||
],
|
||||
]);
|
||||
});
|
||||
it('sends correct mutations if message is not an incoming message', () => {
|
||||
const message = {
|
||||
id: 1,
|
||||
message_type: 1,
|
||||
conversation_id: 1,
|
||||
};
|
||||
actions.addMessage({ commit }, message);
|
||||
expect(commit.mock.calls).toEqual([[types.default.ADD_MESSAGE, message]]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -43,4 +43,15 @@ describe('#mutations', () => {
|
||||
expect(state.selectedChatId).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_CONVERSATION_CAN_REPLY', () => {
|
||||
it('set canReply flag', () => {
|
||||
const state = { allConversations: [{ id: 1, can_reply: false }] };
|
||||
mutations[types.SET_CONVERSATION_CAN_REPLY](state, {
|
||||
conversationId: 1,
|
||||
canReply: true,
|
||||
});
|
||||
expect(state.allConversations[0].can_reply).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user