fix(chat): fix match chat not displaying messages for sender
- Add nested user object with country to match messages (API + Socket.IO) - Change io.to() to io.in() to include sender in broadcast - Apply same broadcast fix to event chat for consistency
This commit is contained in:
@@ -515,6 +515,7 @@ router.get('/:slug/messages', authenticate, async (req, res, next) => {
|
||||
avatar: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
country: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -535,6 +536,7 @@ router.get('/:slug/messages', authenticate, async (req, res, next) => {
|
||||
avatar: msg.user.avatar,
|
||||
firstName: msg.user.firstName,
|
||||
lastName: msg.user.lastName,
|
||||
country: msg.user.country,
|
||||
},
|
||||
content: msg.content,
|
||||
type: msg.type,
|
||||
|
||||
@@ -365,8 +365,8 @@ function initializeSocket(httpServer) {
|
||||
},
|
||||
});
|
||||
|
||||
// Broadcast message to room
|
||||
io.to(roomName).emit('event_message', {
|
||||
// Broadcast message to room (including sender)
|
||||
io.in(roomName).emit('event_message', {
|
||||
id: message.id,
|
||||
roomId: message.roomId,
|
||||
userId: message.user.id,
|
||||
@@ -474,21 +474,27 @@ function initializeSocket(httpServer) {
|
||||
id: true,
|
||||
username: true,
|
||||
avatar: true,
|
||||
country: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Broadcast to match room
|
||||
io.to(roomName).emit('match_message', {
|
||||
// Broadcast to match room (including sender)
|
||||
io.in(roomName).emit('match_message', {
|
||||
id: message.id,
|
||||
roomId: message.roomId,
|
||||
userId: message.user.id,
|
||||
username: message.user.username,
|
||||
avatar: message.user.avatar,
|
||||
content: message.content,
|
||||
type: message.type,
|
||||
createdAt: message.createdAt,
|
||||
// Nested user data (consistent with event_message format)
|
||||
user: {
|
||||
id: message.user.id,
|
||||
username: message.user.username,
|
||||
avatar: message.user.avatar,
|
||||
country: message.user.country,
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`💬 Private message in match ${matchId} from ${socket.user.username}`);
|
||||
|
||||
Reference in New Issue
Block a user