fix: Add a DISCONNECT_DELAY_THRESHOLD while fetching the conversations (#9757)
The disconnect threshold is added to account for delays in identifying disconnections (for example, the websocket disconnection takes up to 3 seconds) while fetching the latest updated conversations or messages. In this case, the cable disconnection event takes about 3 seconds to fire. If there was a conversation which was created in this 3 second, it would not be displayed in the UI until the refresh. Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
@@ -9,6 +9,11 @@ import {
|
|||||||
|
|
||||||
const MAX_DISCONNECT_SECONDS = 10800;
|
const MAX_DISCONNECT_SECONDS = 10800;
|
||||||
|
|
||||||
|
// The disconnect delay threshold is added to account for delays in identifying
|
||||||
|
// disconnections (for example, the websocket disconnection takes up to 3 seconds)
|
||||||
|
// while fetching the latest updated conversations or messages.
|
||||||
|
const DISCONNECT_DELAY_THRESHOLD = 15;
|
||||||
|
|
||||||
class ReconnectService {
|
class ReconnectService {
|
||||||
constructor(store, router) {
|
constructor(store, router) {
|
||||||
this.store = store;
|
this.store = store;
|
||||||
@@ -47,7 +52,8 @@ class ReconnectService {
|
|||||||
fetchConversations = async () => {
|
fetchConversations = async () => {
|
||||||
await this.store.dispatch('updateChatListFilters', {
|
await this.store.dispatch('updateChatListFilters', {
|
||||||
page: null,
|
page: null,
|
||||||
updatedWithin: this.getSecondsSinceDisconnect(),
|
updatedWithin:
|
||||||
|
this.getSecondsSinceDisconnect() + DISCONNECT_DELAY_THRESHOLD,
|
||||||
});
|
});
|
||||||
await this.store.dispatch('fetchAllConversations');
|
await this.store.dispatch('fetchAllConversations');
|
||||||
// Reset the updatedWithin in the store chat list filter after fetching conversations when the user is reconnected
|
// Reset the updatedWithin in the store chat list filter after fetching conversations when the user is reconnected
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ describe('ReconnectService', () => {
|
|||||||
expect(reconnectService.getSecondsSinceDisconnect()).toBe(0);
|
expect(reconnectService.getSecondsSinceDisconnect()).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the number of seconds since disconnect', () => {
|
it('should return the number of seconds + threshold since disconnect', () => {
|
||||||
reconnectService.disconnectTime = new Date();
|
reconnectService.disconnectTime = new Date();
|
||||||
differenceInSeconds.mockReturnValue(100);
|
differenceInSeconds.mockReturnValue(100);
|
||||||
expect(reconnectService.getSecondsSinceDisconnect()).toBe(100);
|
expect(reconnectService.getSecondsSinceDisconnect()).toBe(100);
|
||||||
@@ -128,12 +128,21 @@ describe('ReconnectService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('fetchConversations', () => {
|
describe('fetchConversations', () => {
|
||||||
|
it('should update the filters with disconnected time and the threshold', async () => {
|
||||||
|
reconnectService.getSecondsSinceDisconnect = vi.fn().mockReturnValue(100);
|
||||||
|
await reconnectService.fetchConversations();
|
||||||
|
expect(storeMock.dispatch).toHaveBeenCalledWith('updateChatListFilters', {
|
||||||
|
page: null,
|
||||||
|
updatedWithin: 115,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should dispatch updateChatListFilters and fetchAllConversations', async () => {
|
it('should dispatch updateChatListFilters and fetchAllConversations', async () => {
|
||||||
reconnectService.getSecondsSinceDisconnect = vi.fn().mockReturnValue(100);
|
reconnectService.getSecondsSinceDisconnect = vi.fn().mockReturnValue(100);
|
||||||
await reconnectService.fetchConversations();
|
await reconnectService.fetchConversations();
|
||||||
expect(storeMock.dispatch).toHaveBeenCalledWith('updateChatListFilters', {
|
expect(storeMock.dispatch).toHaveBeenCalledWith('updateChatListFilters', {
|
||||||
page: null,
|
page: null,
|
||||||
updatedWithin: 100,
|
updatedWithin: 115,
|
||||||
});
|
});
|
||||||
expect(storeMock.dispatch).toHaveBeenCalledWith('fetchAllConversations');
|
expect(storeMock.dispatch).toHaveBeenCalledWith('fetchAllConversations');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user