widget parole 10
This commit is contained in:
parent
f9b7ef1891
commit
2697471b03
@ -66,30 +66,44 @@ export async function GET(request: Request) {
|
|||||||
return NextResponse.json({ messages: [] }, { status: 200 });
|
return NextResponse.json({ messages: [] }, { status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let userInfo;
|
||||||
|
// Try to get user info by username first
|
||||||
const userInfoResponse = await fetch(`${baseUrl}/api/v1/users.info?username=${encodeURIComponent(username)}`, {
|
const userInfoResponse = await fetch(`${baseUrl}/api/v1/users.info?username=${encodeURIComponent(username)}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: adminHeaders
|
headers: adminHeaders
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!userInfoResponse.ok) {
|
if (!userInfoResponse.ok) {
|
||||||
console.error('Failed to get user info:', userInfoResponse.status);
|
console.error('Failed to get user info by username:', userInfoResponse.status);
|
||||||
const errorData = await userInfoResponse.json();
|
const errorData = await userInfoResponse.json();
|
||||||
console.error('User info error details:', errorData);
|
console.error('User info error details:', errorData);
|
||||||
|
|
||||||
// If user not found, return empty messages instead of error
|
// Try to get user info by email as fallback
|
||||||
if (errorData.error === 'User not found.') {
|
const emailUserInfoResponse = await fetch(`${baseUrl}/api/v1/users.info?email=${encodeURIComponent(session.user.email)}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: adminHeaders
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!emailUserInfoResponse.ok) {
|
||||||
|
console.error('Failed to get user info by email:', emailUserInfoResponse.status);
|
||||||
|
const emailErrorData = await emailUserInfoResponse.json();
|
||||||
|
console.error('Email user info error details:', emailErrorData);
|
||||||
return NextResponse.json({ messages: [] }, { status: 200 });
|
return NextResponse.json({ messages: [] }, { status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.json({ error: 'Failed to get user info' }, { status: userInfoResponse.status });
|
userInfo = await emailUserInfoResponse.json();
|
||||||
|
console.log('Found Rocket.Chat user by email:', {
|
||||||
|
username: userInfo.user?.username,
|
||||||
|
id: userInfo.user?._id
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
userInfo = await userInfoResponse.json();
|
||||||
|
console.log('Found Rocket.Chat user by username:', {
|
||||||
|
username: userInfo.user?.username,
|
||||||
|
id: userInfo.user?._id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const userInfo = await userInfoResponse.json();
|
|
||||||
console.log('Found Rocket.Chat user:', {
|
|
||||||
username: userInfo.user?.username,
|
|
||||||
id: userInfo.user?._id
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get user's subscriptions using admin token
|
// Get user's subscriptions using admin token
|
||||||
const subscriptionsResponse = await fetch(`${baseUrl}/api/v1/subscriptions.get`, {
|
const subscriptionsResponse = await fetch(`${baseUrl}/api/v1/subscriptions.get`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -132,7 +146,7 @@ export async function GET(request: Request) {
|
|||||||
try {
|
try {
|
||||||
// Get the latest messages from the room
|
// Get the latest messages from the room
|
||||||
const messagesResponse = await fetch(
|
const messagesResponse = await fetch(
|
||||||
`${baseUrl}/api/v1/chat.getMessage?roomId=${subscription.rid}`, {
|
`${baseUrl}/api/v1/channels.messages?roomId=${subscription.rid}&count=1`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: adminHeaders
|
headers: adminHeaders
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user