widget parole 22

This commit is contained in:
Alma 2025-04-13 01:30:54 +02:00
parent 312db59632
commit 7fe27f8b49

View File

@ -137,7 +137,6 @@ export async function GET(request: Request) {
}
const subscriptionsData = await subscriptionsResponse.json();
console.log('Subscriptions response:', subscriptionsData);
if (!subscriptionsData.success || !Array.isArray(subscriptionsData.update)) {
console.error('Invalid subscriptions response structure');
@ -146,16 +145,14 @@ export async function GET(request: Request) {
// Filter subscriptions for the current user
const userSubscriptions = subscriptionsData.update.filter((sub: any) => {
// For direct messages, only include if the user is a participant
// For direct messages (t: 'd')
if (sub.t === 'd') {
// Check if the user is actually part of this direct message
return sub.rid.includes(currentUser._id);
// Make sure the room ID contains the current user's ID
const participants = sub.rid.split('');
return participants.includes(currentUser._id);
}
// For channels, only include if the user is a member
if (sub.t === 'c') {
return sub.alert !== undefined; // This indicates the user is actually a member
}
return false;
// For channels (t: 'c') and private groups (t: 'p')
return ['c', 'p'].includes(sub.t) && sub.u._id === currentUser._id;
});
console.log('Filtered user subscriptions:', {
@ -166,7 +163,8 @@ export async function GET(request: Request) {
type: sub.t,
name: sub.fname || sub.name,
rid: sub.rid,
alert: sub.alert
alert: sub.alert,
isOwn: sub.u._id === currentUser._id
}))
});
@ -179,8 +177,16 @@ export async function GET(request: Request) {
processedRooms.add(subscription.rid);
try {
// Determine the correct endpoint and parameters based on room type
const endpoint = subscription.t === 'c' ? 'channels.messages' : 'im.messages';
// Determine the correct endpoint based on room type
let endpoint;
if (subscription.t === 'c') {
endpoint = 'channels.messages';
} else if (subscription.t === 'p') {
endpoint = 'groups.messages';
} else {
endpoint = 'im.messages';
}
const queryParams = new URLSearchParams({
roomId: subscription.rid,
count: '3'