diff --git a/app/api/rocket-chat/messages/route.ts b/app/api/rocket-chat/messages/route.ts index 966bec19..ecc60e48 100644 --- a/app/api/rocket-chat/messages/route.ts +++ b/app/api/rocket-chat/messages/route.ts @@ -129,14 +129,24 @@ export async function GET(request: Request) { } // Filter subscriptions for the current user - const userSubscriptions = subscriptionsData.update.filter((sub: any) => - sub.u?._id === currentUser._id || - (sub.userMentions > 0 && sub.alert) - ); + const userSubscriptions = subscriptionsData.update.filter((sub: any) => { + // For direct messages (t: 'd'), check if the room ID contains the user's ID + if (sub.t === 'd') { + return sub.rid.includes(currentUser._id); + } + // For channels (t: 'c'), include if user has unread messages or mentions + return sub.t === 'c' && (sub.unread > 0 || sub.userMentions > 0 || sub.alert); + }); console.log('Filtered subscriptions:', { total: userSubscriptions.length, - roomTypes: userSubscriptions.map((sub: any) => sub.t) + roomTypes: userSubscriptions.map((sub: any) => ({ + type: sub.t, + name: sub.fname || sub.name, + unread: sub.unread, + mentions: sub.userMentions, + alert: sub.alert + })) }); const messages: any[] = [];