socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

last message is not emitting

Open santhanakumar45 opened this issue 7 months ago • 0 comments

socket.on("join chat", (chatId) => { socket.join("room"+chatId); console.log("User Joined Room:", socket.rooms); });

i connected the room using chatId.

User Joined Room: Set(3) { 'koyFwiJ2_7V5Cc1nAAAP', '96467dec-cf46-4890-b6f0-b5f116eb8158', 'room652' }

This is the console for connecting the room. "room652" is my room id.

socket.on("new message", (newMessageReceived) => { console.log("newMessageReceived", newMessageReceived); // new message

const chat = newMessageReceived.chat;
console.log("chat", chat);

if (!chat.users) return console.log("chat.users not defined");

chat.users.forEach((user) => {
  if (user.user_id !== newMessageReceived.sender.user_id) {
    console.log("user**user_id", user.user_id);
    console.log("message received before emit", newMessageReceived);
    // socket.to(user.user_id).emit('message received', newMessageReceived);
    socket.to(user.user_id).emit("message received", newMessageReceived);

    console.log("message received", `room`+chat.id);
    socket.to(`room`+chat.id).emit("update last message", newMessageReceived); // last message emit to client 
  }
});

});

This socket "new message" is created for new message emit from client. That new message is received server. after that server emit the new message to client that is working like "socket.to(user.user_id).emit("message received", newMessageReceived);" this line. but when i emit update last message that not receive to client. i want update that last message in the chat list for particular chat.

santhanakumar45 avatar Apr 28 '25 10:04 santhanakumar45