HH-598: hide unavailable AI takeover (#155)
* fix(HH-598): hide unavailable AI takeover * fix: isolate inbox assistant availability --------- Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
@@ -44,6 +44,8 @@ const getStoredMessage = (conversation, message) => {
|
||||
const isNewerMessage = (currentMessage, message) =>
|
||||
isNewerTimestamp(currentMessage?.updated_at, message.updated_at);
|
||||
|
||||
let inboxAssistantRequestId = 0;
|
||||
|
||||
// actions
|
||||
const actions = {
|
||||
getConversation: async ({ commit }, conversationId) => {
|
||||
@@ -56,7 +58,10 @@ const actions = {
|
||||
}
|
||||
},
|
||||
|
||||
fetchAllConversations: async ({ commit, state, dispatch }, explicitFilters) => {
|
||||
fetchAllConversations: async (
|
||||
{ commit, state, dispatch },
|
||||
explicitFilters
|
||||
) => {
|
||||
commit(types.CLEAR_LIST_ERROR_STATUS);
|
||||
commit(types.SET_LIST_LOADING_STATUS);
|
||||
try {
|
||||
@@ -574,9 +579,14 @@ const actions = {
|
||||
},
|
||||
|
||||
getInboxCaptainAssistantById: async ({ commit }, conversationId) => {
|
||||
inboxAssistantRequestId += 1;
|
||||
const requestId = inboxAssistantRequestId;
|
||||
commit(types.SET_INBOX_CAPTAIN_ASSISTANT, { assistant: null });
|
||||
try {
|
||||
const response = await ConversationApi.getInboxAssistant(conversationId);
|
||||
commit(types.SET_INBOX_CAPTAIN_ASSISTANT, response.data);
|
||||
if (requestId === inboxAssistantRequestId) {
|
||||
commit(types.SET_INBOX_CAPTAIN_ASSISTANT, response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
+35
-10
@@ -1002,22 +1002,47 @@ describe('#addMentions', () => {
|
||||
it('fetches inbox assistant by id', async () => {
|
||||
axios.get.mockResolvedValue({
|
||||
data: {
|
||||
id: 1,
|
||||
name: 'Assistant',
|
||||
description: 'Assistant description',
|
||||
},
|
||||
});
|
||||
await actions.getInboxCaptainAssistantById({ commit }, 1);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[
|
||||
types.SET_INBOX_CAPTAIN_ASSISTANT,
|
||||
{
|
||||
assistant: {
|
||||
id: 1,
|
||||
name: 'Assistant',
|
||||
description: 'Assistant description',
|
||||
},
|
||||
},
|
||||
});
|
||||
await actions.getInboxCaptainAssistantById({ commit }, 1);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_INBOX_CAPTAIN_ASSISTANT, { assistant: null }],
|
||||
[
|
||||
types.SET_INBOX_CAPTAIN_ASSISTANT,
|
||||
{
|
||||
assistant: {
|
||||
id: 1,
|
||||
name: 'Assistant',
|
||||
description: 'Assistant description',
|
||||
},
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
it('ignores an older response after switching conversations', async () => {
|
||||
const resolvers = [];
|
||||
axios.get.mockImplementation(
|
||||
() => new Promise(resolve => resolvers.push(resolve))
|
||||
);
|
||||
|
||||
const requestA = actions.getInboxCaptainAssistantById({ commit }, 1);
|
||||
const requestB = actions.getInboxCaptainAssistantById({ commit }, 2);
|
||||
resolvers[1]({ data: { assistant: null } });
|
||||
await requestB;
|
||||
resolvers[0]({ data: { assistant: { id: 1, name: 'Assistant A' } } });
|
||||
await requestA;
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_INBOX_CAPTAIN_ASSISTANT, { assistant: null }],
|
||||
[types.SET_INBOX_CAPTAIN_ASSISTANT, { assistant: null }],
|
||||
[types.SET_INBOX_CAPTAIN_ASSISTANT, { assistant: null }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user