Skip to content

Commit

Permalink
Fix test, correctly add new messages to private conversations
Browse files Browse the repository at this point in the history
  • Loading branch information
borisyankov committed Jan 9, 2017
1 parent fb04081 commit 7a5da95
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/chat/__tests__/chatReducers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@ describe('chatReducers', () => {
sender_email: '[email protected]',
display_recipient: [
{ email: '[email protected]' },
{ email: 'someone@example.com' },
{ email: 'mark@example.com' },
],
};
const action = {
type: EVENT_NEW_MESSAGE,
message,
selfEmail: '[email protected]',
};
const expectedState = {
messages: {
Expand All @@ -168,7 +169,7 @@ describe('chatReducers', () => {
[streamNarrowStr]: [{ id: 2 }, { id: 3 }],
[topicNarrowStr]: [{ id: 2 }, { id: 3 }],
[privateNarrowStr]: [{ id: 2 }, { id: 4 }, message],
[groupNarrowStr]: [{ id: 2 }, { id: 4 }, message],
[groupNarrowStr]: [{ id: 2 }, { id: 4 }],
},
};

Expand Down
3 changes: 2 additions & 1 deletion src/chat/chatReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export default (state = initialState, action) => {
return {
...state,
messages: Object.keys(state.messages).reduce((msg, key) => {
msg[key] = isMessageInNarrow(action.message, JSON.parse(key)) ? // eslint-disable-line
const isInNarrow = isMessageInNarrow(action.message, JSON.parse(key), action.selfEmail);
msg[key] = isInNarrow ? // eslint-disable-line
[
...state.messages[key],
action.message,
Expand Down
2 changes: 2 additions & 0 deletions src/events/eventActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Auth } from '../types';
import { pollForEvents, registerForEvents } from '../api';
import { getActiveAccount } from '../account/accountSelectors';

import {
REALM_INIT,
Expand All @@ -18,6 +19,7 @@ const processEvent = (dispatch, event, getState) => {
dispatch({
type: EVENT_NEW_MESSAGE,
message: event.message,
selfEmail: getActiveAccount(getState()).email,
});
break;
case 'update_message':
Expand Down

0 comments on commit 7a5da95

Please sign in to comment.