From 4327ec4258628b5df7feb6852feac81ab6083563 Mon Sep 17 00:00:00 2001 From: Alma Date: Sun, 13 Apr 2025 10:58:04 +0200 Subject: [PATCH] widget parole 28 --- app/api/rocket-chat/messages/route.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/api/rocket-chat/messages/route.ts b/app/api/rocket-chat/messages/route.ts index 5a48c136..e11b27a4 100644 --- a/app/api/rocket-chat/messages/route.ts +++ b/app/api/rocket-chat/messages/route.ts @@ -145,6 +145,10 @@ export async function GET(request: Request) { // Filter subscriptions for the current user const userSubscriptions = subscriptionsData.update.filter((sub: any) => { + // Only include rooms with unread messages or alerts + if (!(sub.unread > 0 || sub.alert)) { + return false; + } // Include all types of rooms the user is subscribed to return ['d', 'c', 'p'].includes(sub.t); }); @@ -157,7 +161,9 @@ export async function GET(request: Request) { type: sub.t, name: sub.fname || sub.name, rid: sub.rid, - alert: sub.alert + alert: sub.alert, + unread: sub.unread, + userMentions: sub.userMentions })) }); @@ -186,7 +192,7 @@ export async function GET(request: Request) { const queryParams = new URLSearchParams({ roomId: subscription.rid, - count: '5' // Keep this to ensure we get the latest message + count: String(Math.max(subscription.unread, 5)) // Fetch at least the number of unread messages }); const messagesResponse = await fetch( @@ -302,7 +308,10 @@ export async function GET(request: Request) { isChannel: subscription.t === 'c', isPrivateGroup: subscription.t === 'p', isDirect: subscription.t === 'd', - link: `${baseUrl}/${subscription.t === 'd' ? 'direct' : subscription.t === 'p' ? 'group' : 'channel'}/${subscription.name}` + link: `${baseUrl}/${subscription.t === 'd' ? 'direct' : subscription.t === 'p' ? 'group' : 'channel'}/${subscription.name}`, + unread: subscription.unread, + alert: subscription.alert, + userMentions: subscription.userMentions } };