burakorkmez / mern-chat-app

Real Time Chat App | MERN && Socket.io && JWT
MIT License
623 stars 175 forks source link

fixed a little bug in useListenMessages.js hook #15

Open deepak-kr-patra opened 2 months ago

deepak-kr-patra commented 2 months ago

I checked that if a person A is online(i.e. his socket.io id is online), and he has opened the chat with person B, then at that time if any person C sends him a message then it gets rendered in the person A and B chat conversation. Because useListenMessages.js hook listens to all the messages sent to person A's socket.io id... So to prevent this while we have a selected conversation, we should add a if statement to check if the newMessage sent to our socket.io id is sent by the person we are chatting with right now, so others message will not be rendered during your ongoing chat with a person.