fix some bugs
This commit is contained in:
@@ -344,6 +344,42 @@ function handleListPayload(payload: unknown) {
|
||||
applyProductsListFromStream(payload as Product[])
|
||||
}
|
||||
|
||||
function handleAppNotificationPayload(payload: unknown) {
|
||||
if (!payload || typeof payload !== 'object') {
|
||||
return
|
||||
}
|
||||
|
||||
touchStreamActivity()
|
||||
void applyAppNotificationFromStream(payload as Record<string, unknown>)
|
||||
}
|
||||
|
||||
function handleUnreadCountPayload(payload: unknown) {
|
||||
if (!payload || typeof payload !== 'object') {
|
||||
return
|
||||
}
|
||||
|
||||
touchStreamActivity()
|
||||
void applyUnreadCountFromStreamPayload(payload as Record<string, unknown>)
|
||||
}
|
||||
|
||||
async function applyAppNotificationFromStream(payload: Record<string, unknown>) {
|
||||
try {
|
||||
const { bumpUnreadFromStream } = await import('@/composables/useAppNotificationBadge')
|
||||
bumpUnreadFromStream(payload)
|
||||
} catch (error) {
|
||||
console.warn('App notification SSE apply failed', error)
|
||||
}
|
||||
}
|
||||
|
||||
async function applyUnreadCountFromStreamPayload(payload: Record<string, unknown>) {
|
||||
try {
|
||||
const { applyUnreadCountFromStream } = await import('@/composables/useAppNotificationBadge')
|
||||
applyUnreadCountFromStream(payload)
|
||||
} catch (error) {
|
||||
console.warn('Unread-count SSE apply failed', error)
|
||||
}
|
||||
}
|
||||
|
||||
function bindStreamEvents(source: EventSource) {
|
||||
source.addEventListener('last', (event) => {
|
||||
try {
|
||||
@@ -361,6 +397,22 @@ function bindStreamEvents(source: EventSource) {
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('app_notification', (event) => {
|
||||
try {
|
||||
handleAppNotificationPayload(JSON.parse(event.data))
|
||||
} catch (error) {
|
||||
console.warn('App notification SSE parse failed', error)
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('unread-count', (event) => {
|
||||
try {
|
||||
handleUnreadCountPayload(JSON.parse(event.data))
|
||||
} catch (error) {
|
||||
console.warn('Unread-count SSE parse failed', error)
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('ping', () => {
|
||||
touchStreamActivity()
|
||||
})
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
/** toast اعلان درونبرنامه — بالای هدر و ناوبری */
|
||||
export const APP_Z_TOAST = 5050
|
||||
|
||||
/** Overlay dialogs (loading / blocking) */
|
||||
export const APP_Z_OVERLAY = 5600
|
||||
|
||||
Reference in New Issue
Block a user