diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/AniList/notifications.ts | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/lib/AniList/notifications.ts b/src/lib/AniList/notifications.ts index 4fdb9cb5..bebf1b42 100644 --- a/src/lib/AniList/notifications.ts +++ b/src/lib/AniList/notifications.ts @@ -30,7 +30,7 @@ export interface Notification { | 'THREAD_LIKE'; } -export const notifications = async (accessToken: string): Promise<Notification[]> => { +export const notifications = async (accessToken: string): Promise<Notification[] | null> => { const activityNotification = (type: string, extend = '') => `... on ${type} { id user { name avatar { large } } context createdAt type ${extend} }`; @@ -45,18 +45,16 @@ export const notifications = async (accessToken: string): Promise<Notification[] )}`; const threadNotification = (type: string) => `${activityNotification(type, `thread { title id }`)}`; - - return ( - await ( - await fetch('https://graphql.anilist.co', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${accessToken}`, - Accept: 'application/json' - }, - body: JSON.stringify({ - query: `{ Page(page: 1, perPage: 50) { notifications { + const data = await ( + await fetch('https://graphql.anilist.co', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${accessToken}`, + Accept: 'application/json' + }, + body: JSON.stringify({ + query: `{ Page(page: 1, perPage: 50) { notifications { ${activityNotification('FollowingNotification')} ${activityNotification('ActivityMessageNotification')} ${richActivityNotification('ActivityMentionNotification')} @@ -70,8 +68,11 @@ export const notifications = async (accessToken: string): Promise<Notification[] ${threadNotification('ThreadCommentLikeNotification')} ${threadNotification('ThreadLikeNotification')} } } }` - }) }) - ).json() - )['data']['Page']['notifications']; + }) + ).json(); + + if (data['errors']) return null; + + return data['data']['Page']['notifications']; }; |