widget parole 21
This commit is contained in:
parent
e07db4584f
commit
312db59632
@ -146,21 +146,26 @@ 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) => {
|
||||||
// For direct messages (t: 'd'), check if the room ID contains the user's ID
|
// For direct messages, only include if the user is a participant
|
||||||
if (sub.t === 'd') {
|
if (sub.t === 'd') {
|
||||||
|
// Check if the user is actually part of this direct message
|
||||||
return sub.rid.includes(currentUser._id);
|
return sub.rid.includes(currentUser._id);
|
||||||
}
|
}
|
||||||
// For channels (t: 'c'), include all channels
|
// For channels, only include if the user is a member
|
||||||
return sub.t === 'c';
|
if (sub.t === 'c') {
|
||||||
|
return sub.alert !== undefined; // This indicates the user is actually a member
|
||||||
|
}
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Filtered subscriptions:', {
|
console.log('Filtered user subscriptions:', {
|
||||||
total: userSubscriptions.length,
|
userId: currentUser._id,
|
||||||
roomTypes: userSubscriptions.map((sub: any) => ({
|
username: currentUser.username,
|
||||||
|
totalSubscriptions: userSubscriptions.length,
|
||||||
|
subscriptionDetails: userSubscriptions.map((sub: any) => ({
|
||||||
type: sub.t,
|
type: sub.t,
|
||||||
name: sub.fname || sub.name,
|
name: sub.fname || sub.name,
|
||||||
unread: sub.unread,
|
rid: sub.rid,
|
||||||
mentions: sub.userMentions,
|
|
||||||
alert: sub.alert
|
alert: sub.alert
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
@ -170,16 +175,19 @@ export async function GET(request: Request) {
|
|||||||
|
|
||||||
// Step 5: Fetch messages using user token
|
// Step 5: Fetch messages using user token
|
||||||
for (const subscription of userSubscriptions) {
|
for (const subscription of userSubscriptions) {
|
||||||
if (messages.length >= 10 || processedRooms.has(subscription._id)) continue;
|
if (messages.length >= 10 || processedRooms.has(subscription.rid)) continue;
|
||||||
processedRooms.add(subscription._id);
|
processedRooms.add(subscription.rid);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Determine the correct endpoint based on room type
|
// Determine the correct endpoint and parameters based on room type
|
||||||
const endpoint = subscription.t === 'c' ? 'channels.messages' : 'im.messages';
|
const endpoint = subscription.t === 'c' ? 'channels.messages' : 'im.messages';
|
||||||
|
const queryParams = new URLSearchParams({
|
||||||
|
roomId: subscription.rid,
|
||||||
|
count: '3'
|
||||||
|
});
|
||||||
|
|
||||||
// Get more messages from each room
|
|
||||||
const messagesResponse = await fetch(
|
const messagesResponse = await fetch(
|
||||||
`${baseUrl}/api/v1/${endpoint}?roomId=${subscription.rid}&count=3`, {
|
`${baseUrl}/api/v1/${endpoint}?${queryParams}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: userHeaders
|
headers: userHeaders
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user