Fix other users status changes (#2491)
This commit is contained in:
parent
8c9fd9d9ac
commit
477dcbb1c5
4 changed files with 40 additions and 5 deletions
|
|
@ -2,7 +2,7 @@
|
|||
// See LICENSE.txt for license information.
|
||||
|
||||
import {UserTypes} from 'mattermost-redux/action_types';
|
||||
import {getStatus} from 'mattermost-redux/actions/users';
|
||||
import {getStatus, getStatusesByIds, startPeriodicStatusUpdates} from 'mattermost-redux/actions/users';
|
||||
import {General} from 'mattermost-redux/constants';
|
||||
import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
|
||||
|
||||
|
|
@ -23,3 +23,16 @@ export function setCurrentUserStatus(isOnline) {
|
|||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function initUserStatuses() {
|
||||
return (dispatch, getState) => {
|
||||
const {statuses} = getState().entities.users || {};
|
||||
const userIds = Object.keys(statuses);
|
||||
|
||||
if (userIds.length) {
|
||||
dispatch(getStatusesByIds(userIds));
|
||||
}
|
||||
|
||||
dispatch(startPeriodicStatusUpdates());
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,14 @@ import thunk from 'redux-thunk';
|
|||
import {UserTypes} from 'mattermost-redux/action_types';
|
||||
import {General} from 'mattermost-redux/constants';
|
||||
|
||||
import {setCurrentUserStatus} from 'app/actions/views/user';
|
||||
import {initUserStatuses, setCurrentUserStatus} from 'app/actions/views/user';
|
||||
|
||||
const mockStore = configureStore([thunk]);
|
||||
|
||||
jest.mock('mattermost-redux/actions/users', () => ({
|
||||
getStatus: (...args) => ({type: 'MOCK_GET_STATUS', args}),
|
||||
getStatusesByIds: (...args) => ({type: 'MOCK_GET_STATUS_BY_IDS', args}),
|
||||
startPeriodicStatusUpdates: () => ({type: 'MOCK_PERIODIC_STATUS_UPDATES'}),
|
||||
}));
|
||||
|
||||
describe('Actions.Views.User', () => {
|
||||
|
|
@ -23,6 +25,11 @@ describe('Actions.Views.User', () => {
|
|||
entities: {
|
||||
users: {
|
||||
currentUserId: 'current-user-id',
|
||||
statuses: {
|
||||
'current-user-id': 'online',
|
||||
'another-user-id1': 'away',
|
||||
'another-user-id2': 'dnd',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
@ -50,4 +57,15 @@ describe('Actions.Views.User', () => {
|
|||
await store.dispatch(setCurrentUserStatus(true));
|
||||
expect(store.getActions()).toEqual([action]);
|
||||
});
|
||||
|
||||
test('should initialize the periodic status updates and get the current user statuses', () => {
|
||||
const actionStatusByIds = {
|
||||
type: 'MOCK_GET_STATUS_BY_IDS',
|
||||
args: [['current-user-id', 'another-user-id1', 'another-user-id2']],
|
||||
};
|
||||
const actionPeriodicUpdates = {type: 'MOCK_PERIODIC_STATUS_UPDATES'};
|
||||
|
||||
store.dispatch(initUserStatuses());
|
||||
expect(store.getActions()).toEqual([actionStatusByIds, actionPeriodicUpdates]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,12 +4,15 @@
|
|||
import {bindActionCreators} from 'redux';
|
||||
import {connect} from 'react-redux';
|
||||
|
||||
import {startPeriodicStatusUpdates, stopPeriodicStatusUpdates, logout} from 'mattermost-redux/actions/users';
|
||||
import {stopPeriodicStatusUpdates, logout} from 'mattermost-redux/actions/users';
|
||||
import {init as initWebSocket, close as closeWebSocket} from 'mattermost-redux/actions/websocket';
|
||||
import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels';
|
||||
|
||||
import {connection} from 'app/actions/device';
|
||||
import {setCurrentUserStatus} from 'app/actions/views/user';
|
||||
import {
|
||||
initUserStatuses as startPeriodicStatusUpdates,
|
||||
setCurrentUserStatus,
|
||||
} from 'app/actions/views/user';
|
||||
import {getConnection, isLandscape} from 'app/selectors/device';
|
||||
|
||||
import NetworkIndicator from './network_indicator';
|
||||
|
|
|
|||
|
|
@ -243,12 +243,13 @@ export default class NetworkIndicator extends PureComponent {
|
|||
};
|
||||
|
||||
handleConnectionChange = ({hasInternet, serverReachable}) => {
|
||||
const {connection} = this.props.actions;
|
||||
const {connection, startPeriodicStatusUpdates} = this.props.actions;
|
||||
|
||||
// On first run always initialize the WebSocket
|
||||
// if we have internet connection
|
||||
if (hasInternet && this.firstRun) {
|
||||
this.initializeWebSocket();
|
||||
startPeriodicStatusUpdates();
|
||||
this.firstRun = false;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue