mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-22 22:21:09 +08:00
feat: show unread message count
This commit is contained in:
17
open-isle-cli/src/utils/notification.js
Normal file
17
open-isle-cli/src/utils/notification.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { API_BASE_URL } from '../main'
|
||||
import { getToken } from './auth'
|
||||
|
||||
export async function fetchUnreadCount() {
|
||||
try {
|
||||
const token = getToken()
|
||||
if (!token) return 0
|
||||
const res = await fetch(`${API_BASE_URL}/api/notifications/unread-count`, {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
})
|
||||
if (!res.ok) return 0
|
||||
const data = await res.json()
|
||||
return data.count
|
||||
} catch (e) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user