From ec604cf76f036bf7d25990e68c20adac06e9254c Mon Sep 17 00:00:00 2001 From: Alma Date: Sun, 13 Apr 2025 00:38:16 +0200 Subject: [PATCH] widget parole 14 --- app/api/rocket-chat/messages/route.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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[] = [];