widget parole 28

This commit is contained in:
Alma 2025-04-13 10:58:04 +02:00
parent ddde73beb8
commit 4327ec4258

View File

@ -145,6 +145,10 @@ export async function GET(request: Request) {
// Filter subscriptions for the current user // Filter subscriptions for the current user
const userSubscriptions = subscriptionsData.update.filter((sub: any) => { 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 // Include all types of rooms the user is subscribed to
return ['d', 'c', 'p'].includes(sub.t); return ['d', 'c', 'p'].includes(sub.t);
}); });
@ -157,7 +161,9 @@ export async function GET(request: Request) {
type: sub.t, type: sub.t,
name: sub.fname || sub.name, name: sub.fname || sub.name,
rid: sub.rid, 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({ const queryParams = new URLSearchParams({
roomId: subscription.rid, 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( const messagesResponse = await fetch(
@ -302,7 +308,10 @@ export async function GET(request: Request) {
isChannel: subscription.t === 'c', isChannel: subscription.t === 'c',
isPrivateGroup: subscription.t === 'p', isPrivateGroup: subscription.t === 'p',
isDirect: subscription.t === 'd', 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
} }
}; };