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,
|
avatar: true,
|
||||||
firstName: true,
|
firstName: true,
|
||||||
lastName: true,
|
lastName: true,
|
||||||
|
country: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -535,6 +536,7 @@ router.get('/:slug/messages', authenticate, async (req, res, next) => {
|
|||||||
avatar: msg.user.avatar,
|
avatar: msg.user.avatar,
|
||||||
firstName: msg.user.firstName,
|
firstName: msg.user.firstName,
|
||||||
lastName: msg.user.lastName,
|
lastName: msg.user.lastName,
|
||||||
|
country: msg.user.country,
|
||||||
},
|
},
|
||||||
content: msg.content,
|
content: msg.content,
|
||||||
type: msg.type,
|
type: msg.type,
|
||||||
|
|||||||
@@ -365,8 +365,8 @@ function initializeSocket(httpServer) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Broadcast message to room
|
// Broadcast message to room (including sender)
|
||||||
io.to(roomName).emit('event_message', {
|
io.in(roomName).emit('event_message', {
|
||||||
id: message.id,
|
id: message.id,
|
||||||
roomId: message.roomId,
|
roomId: message.roomId,
|
||||||
userId: message.user.id,
|
userId: message.user.id,
|
||||||
@@ -474,21 +474,27 @@ function initializeSocket(httpServer) {
|
|||||||
id: true,
|
id: true,
|
||||||
username: true,
|
username: true,
|
||||||
avatar: true,
|
avatar: true,
|
||||||
|
country: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Broadcast to match room
|
// Broadcast to match room (including sender)
|
||||||
io.to(roomName).emit('match_message', {
|
io.in(roomName).emit('match_message', {
|
||||||
id: message.id,
|
id: message.id,
|
||||||
roomId: message.roomId,
|
roomId: message.roomId,
|
||||||
userId: message.user.id,
|
userId: message.user.id,
|
||||||
username: message.user.username,
|
|
||||||
avatar: message.user.avatar,
|
|
||||||
content: message.content,
|
content: message.content,
|
||||||
type: message.type,
|
type: message.type,
|
||||||
createdAt: message.createdAt,
|
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}`);
|
console.log(`💬 Private message in match ${matchId} from ${socket.user.username}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user