diff --git a/client/modules/User/UserReducer.js b/client/modules/User/UserReducer.js
index fc30343..fd7d383 100644
--- a/client/modules/User/UserReducer.js
+++ b/client/modules/User/UserReducer.js
@@ -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(
{`${action.message.user}: ${action.message.message}`}
);
+
return {
user: state.user,
currentStudyGroup: state.currentStudyGroup,
diff --git a/client/modules/User/components/ChatComponent/ChatComponent.js b/client/modules/User/components/ChatComponent/ChatComponent.js
index 1c10588..c089887 100644
--- a/client/modules/User/components/ChatComponent/ChatComponent.js
+++ b/client/modules/User/components/ChatComponent/ChatComponent.js
@@ -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) {
diff --git a/server/socketEvents.js b/server/socketEvents.js
index dd4ada3..b95fb88 100644
--- a/server/socketEvents.js
+++ b/server/socketEvents.js
@@ -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 });
}
});
});