fixed duplicated messages

This commit is contained in:
slawk0
2024-11-30 23:13:14 +01:00
parent 2f48c7423b
commit 0e26a68f1c
2 changed files with 10 additions and 4 deletions

View File

@@ -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);
}
});

View File

@@ -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,