feat: Reconnect logic (#9453)
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
This commit is contained in:
@@ -109,6 +109,10 @@ export const actions = {
|
||||
// silent error
|
||||
}
|
||||
},
|
||||
|
||||
getCacheKeys: async () => {
|
||||
return AccountAPI.getCacheKeys();
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
|
||||
@@ -41,11 +41,14 @@ export const mutations = {
|
||||
newAllConversations[indexInCurrentList] = conversation;
|
||||
} else {
|
||||
// If the conversation is already in the list and selectedChatId is the same,
|
||||
// replace all data except the messages array
|
||||
// replace all data except the messages array, attachments, dataFetched, allMessagesLoaded
|
||||
const existingConversation = newAllConversations[indexInCurrentList];
|
||||
newAllConversations[indexInCurrentList] = {
|
||||
...conversation,
|
||||
allMessagesLoaded: existingConversation.allMessagesLoaded,
|
||||
messages: existingConversation.messages,
|
||||
dataFetched: existingConversation.dataFetched,
|
||||
attachments: existingConversation.attachments,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -307,9 +307,17 @@ describe('#mutations', () => {
|
||||
expect(state.allConversations).toEqual(data);
|
||||
});
|
||||
|
||||
it('set all conversation in reconnect if selected chat id and conversation id is the same then do not update messages', () => {
|
||||
it('set all conversation in reconnect if selected chat id and conversation id is the same then do not update messages, attachments, dataFetched, allMessagesLoaded', () => {
|
||||
const state = {
|
||||
allConversations: [{ id: 1, messages: [{ id: 1, content: 'test' }] }],
|
||||
allConversations: [
|
||||
{
|
||||
id: 1,
|
||||
messages: [{ id: 1, content: 'test' }],
|
||||
attachments: [{ id: 1, name: 'test1.png' }],
|
||||
dataFetched: true,
|
||||
allMessagesLoaded: true,
|
||||
},
|
||||
],
|
||||
selectedChatId: 1,
|
||||
};
|
||||
const data = [
|
||||
@@ -317,10 +325,20 @@ describe('#mutations', () => {
|
||||
id: 1,
|
||||
name: 'test',
|
||||
messages: [{ id: 1, content: 'updated message' }],
|
||||
attachments: [{ id: 1, name: 'test.png' }],
|
||||
dataFetched: true,
|
||||
allMessagesLoaded: true,
|
||||
},
|
||||
];
|
||||
const expected = [
|
||||
{ id: 1, name: 'test', messages: [{ id: 1, content: 'test' }] },
|
||||
{
|
||||
id: 1,
|
||||
name: 'test',
|
||||
messages: [{ id: 1, content: 'test' }],
|
||||
attachments: [{ id: 1, name: 'test1.png' }],
|
||||
dataFetched: true,
|
||||
allMessagesLoaded: true,
|
||||
},
|
||||
];
|
||||
mutations[types.SET_ALL_CONVERSATION](state, data);
|
||||
expect(state.allConversations).toEqual(expected);
|
||||
|
||||
Reference in New Issue
Block a user