Skip to content

Commit

Permalink
Remove unneeded duplicated requests for statuses (mattermost#5251)
Browse files Browse the repository at this point in the history
  • Loading branch information
jespino committed Apr 7, 2020
1 parent b8862f5 commit a0ad653
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions actions/websocket_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ function addedNewDmUser(preference) {
}

export function handleUserTypingEvent(msg) {
return (doDispatch, doGetState) => {
return async (doDispatch, doGetState) => {
const state = doGetState();
const config = getConfig(state);
const currentUserId = getCurrentUserId(state);
Expand All @@ -969,7 +969,11 @@ export function handleUserTypingEvent(msg) {
}, parseInt(config.TimeBetweenUserTypingUpdatesMilliseconds, 10));

if (userId !== currentUserId) {
doDispatch(getMissingProfilesByIds([userId]));
const result = await doDispatch(getMissingProfilesByIds([userId]));
if (result.data && result.data.length > 0) {
// Already loaded the user status
return;
}
}

const status = getStatusForUserId(state, userId);
Expand Down
14 changes: 11 additions & 3 deletions actions/websocket_actions.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ describe('handleUserTypingEvent', () => {
});
});

test('should possibly load missing users', () => {
test('should possibly load missing users and not get again the state', () => {
const testStore = configureStore(initialState);

const userId = 'otheruser';
Expand All @@ -594,15 +594,23 @@ describe('handleUserTypingEvent', () => {
testStore.dispatch(handleUserTypingEvent(msg));

expect(getMissingProfilesByIds).toHaveBeenCalledWith([userId]);
expect(getStatusesByIds).not.toHaveBeenCalled();
});

test('should load statuses for users that are not online', () => {
test('should load statuses for users that are not online but are in the store', async () => {
const testStore = configureStore({
...initialState,
entities: {
...initialState.entities,
users: {
...initialState.entities.users,
profiles: {
...initialState.entities.users.profiles,
otheruser: {
id: 'otheruser',
roles: 'system_user',
}
},
statuses: {
...initialState.entities.users.statuses,
otheruser: General.AWAY,
Expand All @@ -622,7 +630,7 @@ describe('handleUserTypingEvent', () => {
},
};

testStore.dispatch(handleUserTypingEvent(msg));
await testStore.dispatch(handleUserTypingEvent(msg));

expect(getStatusesByIds).toHaveBeenCalled();
});
Expand Down

0 comments on commit a0ad653

Please sign in to comment.