fixed duplicated messages
This commit is contained in:
@@ -60,7 +60,10 @@ function MessagesArea({
|
||||
|
||||
socket.on('chat message', (msg: ChatMessages) => {
|
||||
console.log('Received message: ', msg);
|
||||
if (msg.sender !== currentContact && msg.sender !== username) {
|
||||
if (
|
||||
msg.conversation_id !== currentContact?.conversation_id ||
|
||||
msg.sender !== username
|
||||
) {
|
||||
setContactsList((prevContacts) => {
|
||||
if (!prevContacts.some((c) => c.username === msg.sender)) {
|
||||
sendContact(msg.sender);
|
||||
@@ -89,7 +92,10 @@ function MessagesArea({
|
||||
);
|
||||
console.log('changed status to false for: ', msg.sender);
|
||||
}
|
||||
if (msg.sender == currentContact?.username && msg.sender !== username) {
|
||||
if (
|
||||
msg.conversation_id == currentContact?.conversation_id &&
|
||||
msg.sender !== username
|
||||
) {
|
||||
messageHandler(msg);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -71,7 +71,7 @@ function initializeSocket(io) {
|
||||
|
||||
socket.on("chat message", async (msg, callback) => {
|
||||
const { message, recipient, attachment_url } = msg;
|
||||
const sender = socket.user_id;
|
||||
const sender = socket.username;
|
||||
|
||||
if (!message && !attachment_url) {
|
||||
callback({
|
||||
@@ -92,7 +92,7 @@ function initializeSocket(io) {
|
||||
|
||||
try {
|
||||
const insertedMessage = await insertMessage(
|
||||
sender,
|
||||
socket.user_id,
|
||||
recipient,
|
||||
message,
|
||||
attachment_url,
|
||||
|
||||
Reference in New Issue
Block a user