forked from Ivasoft/mattermost-mobile
[MM-30857] request postssince on reconnect (#5000)
* [MM-30857] request postssince on reconnect * [MM-30857] add test * Address CR, add debounce in case of unstable connection * remove leftovers * Address review comments * remove previous changes * fix tests
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {loadChannelsForTeam} from '@actions/views/channel';
|
||||
import {getPosts} from '@actions/views/post';
|
||||
import {getPostsSince} from '@actions/views/post';
|
||||
import {loadMe} from '@actions/views/user';
|
||||
import {WebsocketEvents} from '@constants';
|
||||
import {ChannelTypes, GeneralTypes, PreferenceTypes, TeamTypes, UserTypes, RoleTypes} from '@mm-redux/action_types';
|
||||
@@ -44,6 +44,8 @@ import {handleAddEmoji, handleReactionAddedEvent, handleReactionRemovedEvent} fr
|
||||
import {handleRoleAddedEvent, handleRoleRemovedEvent, handleRoleUpdatedEvent} from './roles';
|
||||
import {handleLeaveTeamEvent, handleUpdateTeamEvent, handleTeamAddedEvent} from './teams';
|
||||
import {handleStatusChangedEvent, handleUserAddedEvent, handleUserRemovedEvent, handleUserRoleUpdated, handleUserUpdatedEvent} from './users';
|
||||
import {getChannelSinceValue} from '@utils/channels';
|
||||
import {getPostIdsInChannel} from '@mm-redux/selectors/entities/posts';
|
||||
|
||||
export function init(additionalOptions: any = {}) {
|
||||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||
@@ -168,7 +170,9 @@ export function doReconnect(now: number) {
|
||||
if (!stillMemberOfCurrentChannel || !channelStillExists || (!viewArchivedChannels && channelStillExists.delete_at !== 0)) {
|
||||
EventEmitter.emit(General.SWITCH_TO_DEFAULT_CHANNEL, currentTeamId);
|
||||
} else {
|
||||
dispatch(getPosts(currentChannelId));
|
||||
const postIds = getPostIdsInChannel(state, currentChannelId);
|
||||
const since = getChannelSinceValue(state, currentChannelId, postIds);
|
||||
dispatch(getPostsSince(currentChannelId, since));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,8 +177,9 @@ describe('Actions.Websocket doReconnect', () => {
|
||||
const timestamp = 1000;
|
||||
const expectedActions = [
|
||||
GeneralTypes.WEBSOCKET_SUCCESS,
|
||||
];
|
||||
const expectedMissingActions = [
|
||||
'BATCH_WS_RECONNECT',
|
||||
'BATCH_GET_POSTS',
|
||||
];
|
||||
|
||||
mockConfigRequest();
|
||||
@@ -197,6 +198,7 @@ describe('Actions.Websocket doReconnect', () => {
|
||||
await TestHelper.wait(300);
|
||||
const actionTypes = testStore.getActions().map((a) => a.type);
|
||||
expect(actionTypes).toEqual(expectedActions);
|
||||
expect(actionTypes).not.toEqual(expect.arrayContaining(expectedMissingActions));
|
||||
});
|
||||
|
||||
it('handle doReconnect after the current channel was archived or the user left it', async () => {
|
||||
@@ -217,7 +219,7 @@ describe('Actions.Websocket doReconnect', () => {
|
||||
'BATCH_WS_RECONNECT',
|
||||
];
|
||||
const expectedMissingActions = [
|
||||
'BATCH_GET_POSTS',
|
||||
'BATCH_GET_POSTS_SINCE',
|
||||
];
|
||||
|
||||
mockConfigRequest();
|
||||
@@ -259,6 +261,8 @@ describe('Actions.Websocket doReconnect', () => {
|
||||
const timestamp = 1000;
|
||||
const expectedActions = [
|
||||
GeneralTypes.WEBSOCKET_SUCCESS,
|
||||
];
|
||||
const expectedMissingActions = [
|
||||
'BATCH_WS_RECONNECT',
|
||||
];
|
||||
|
||||
@@ -279,6 +283,7 @@ describe('Actions.Websocket doReconnect', () => {
|
||||
|
||||
const actions = testStore.getActions().map((a) => a.type);
|
||||
expect(actions).toEqual(expect.arrayContaining(expectedActions));
|
||||
expect(actions).not.toEqual(expect.arrayContaining(expectedMissingActions));
|
||||
});
|
||||
|
||||
it('handle doReconnect after the current channel was archived and setting is off', async () => {
|
||||
@@ -303,7 +308,7 @@ describe('Actions.Websocket doReconnect', () => {
|
||||
'BATCH_WS_RECONNECT',
|
||||
];
|
||||
const expectedMissingActions = [
|
||||
'BATCH_GET_POSTS',
|
||||
'BATCH_GET_POSTS_SINCE',
|
||||
];
|
||||
|
||||
mockConfigRequest({ExperimentalViewArchivedChannels: 'false'});
|
||||
@@ -337,7 +342,7 @@ describe('Actions.Websocket doReconnect', () => {
|
||||
'BATCH_WS_RECONNECT',
|
||||
];
|
||||
const expectedMissingActions = [
|
||||
'BATCH_GET_POSTS',
|
||||
'BATCH_GET_POSTS_SINCE',
|
||||
];
|
||||
|
||||
mockConfigRequest();
|
||||
|
||||
Reference in New Issue
Block a user