widget chat 12

This commit is contained in:
Alma 2025-04-11 11:57:44 +02:00
parent 56110e25ac
commit fefd75bda6

View File

@ -110,14 +110,30 @@ export async function GET() {
if (messagesData.messages && messagesData.messages.length > 0) {
const message = messagesData.messages[0];
// Only include messages where the user is either the sender or the recipient
if (message.u._id === rocketChatUserId ||
(subscription.t === 'd' && subscription.rid.includes(rocketChatUserId))) {
return {
...message,
roomName: subscription.fname || subscription.name || 'Direct Message',
roomType: subscription.t,
};
// For direct messages, check if the room ID contains the user's ID
if (subscription.t === 'd') {
// Extract the other user's ID from the room ID
const roomIdParts = subscription.rid.split(rocketChatUserId);
const otherUserId = roomIdParts[0] || roomIdParts[1];
// Only include messages where the user is either the sender or the recipient
if (message.u._id === rocketChatUserId || message.u._id === otherUserId) {
return {
...message,
roomName: subscription.fname || subscription.name || 'Direct Message',
roomType: subscription.t,
};
}
} else {
// For channels and groups, only include messages where the user is the sender
if (message.u._id === rocketChatUserId) {
return {
...message,
roomName: subscription.fname || subscription.name || 'Direct Message',
roomType: subscription.t,
};
}
}
}