Skip to content

Commit

Permalink
Merge pull request #138 from jacobrs/chat_filtering
Browse files Browse the repository at this point in the history
fix #131 and fix #76 added new message filtering
  • Loading branch information
Philippe229 committed Apr 11, 2017
2 parents f6c0173 + 70abdba commit f8086f5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions client/modules/User/UserReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ const UserReducer = (state = initialState, action) => {
}
case PREPARE_CHAT_MESSAGE: {
let userIndex = state.chat.users.indexOf(action.message.user);

if (userIndex === -1) {
state.chat.users.push(action.message.user);
userIndex = state.chat.users.length - 1;
}

state.chat.messages.push(<div key={state.chat.messages.length + 1} style={{ color: getColorFromUserIndex(userIndex) }}>{`${action.message.user}: ${action.message.message}`}</div>);

return {
user: state.user,
currentStudyGroup: state.currentStudyGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export class ChatComponent extends Component {
}

onMessageReceive(data) {
this.props.prepareChatMessage(data);
if (this.props.users.user.studyGroups[this.props.users.currentStudyGroup].guid == data.studyGroup) {
this.props.prepareChatMessage(data);
}
}

handleChange(event) {
Expand Down
2 changes: 1 addition & 1 deletion server/socketEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exports = module.exports = function (io) {
throw err;
}
else {
io.sockets.emit('UpdateMessages', { message: data.message, user: socket.nickname });
io.sockets.emit('UpdateMessages', { message: data.message, user: socket.nickname, studyGroup: data.studyGroup });
}
});
});
Expand Down

0 comments on commit f8086f5

Please sign in to comment.