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.
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.