Feature: Ability to mute contacts (#891)

fixes: #867
This commit is contained in:
Abdulkadir Poyraz
2020-05-26 17:43:59 +05:30
committed by GitHub
parent d8d14fc4a4
commit b1aab228ae
16 changed files with 148 additions and 2 deletions
@@ -215,6 +215,15 @@ const actions = {
// Handle error
}
},
muteConversation: async ({ commit }, conversationId) => {
try {
await ConversationApi.mute(conversationId);
commit(types.default.MUTE_CONVERSATION);
} catch (error) {
//
}
},
};
export default actions;
@@ -10,6 +10,7 @@ const initialSelectedChat = {
id: null,
meta: {},
status: null,
muted: false,
seen: false,
agentTyping: 'off',
dataFetched: false,
@@ -116,6 +117,12 @@ const mutations = {
_state.selectedChat.status = status;
},
[types.default.MUTE_CONVERSATION](_state) {
const [chat] = getSelectedChatConversation(_state);
chat.muted = true;
_state.selectedChat.muted = true;
},
[types.default.SEND_MESSAGE](_state, currentMessage) {
const [chat] = getSelectedChatConversation(_state);
const allMessagesExceptCurrent = (chat.messages || []).filter(
@@ -21,4 +21,16 @@ describe('#actions', () => {
expect(commit.mock.calls).toEqual([]);
});
});
describe('#muteConversation', () => {
it('sends correct actions if API is success', async () => {
axios.get.mockResolvedValue(null);
await actions.muteConversation({ commit }, 1);
expect(commit.mock.calls).toEqual([[types.default.MUTE_CONVERSATION]]);
});
it('sends correct actions if API is error', async () => {
axios.get.mockRejectedValue({ message: 'Incorrect header' });
await actions.getConversation({ commit });
expect(commit.mock.calls).toEqual([]);
});
});
});