viktor.mozharovskiy
viktor.mozharovskiy
NNovu
Created by viktor.mozharovskiy on 7/11/2024 in #💬│support
@novu/headless: headlessService.fetchNotifications({onSuccess}) constantly receives latest state
@Pawan Jain , hopefully our message didn't dissolve among others 🙂 Your answer is highly awaited by our team. Thank you for your time and support!
12 replies
NNovu
Created by viktor.mozharovskiy on 7/11/2024 in #💬│support
@novu/headless: headlessService.fetchNotifications({onSuccess}) constantly receives latest state
@Pawan Jain did you have a chance to look through the above? It would be very helpful for us to hear your thought on it, then we will be able to move forward with this in our project. Thanks
12 replies
NNovu
Created by viktor.mozharovskiy on 7/11/2024 in #💬│support
@novu/headless: headlessService.fetchNotifications({onSuccess}) constantly receives latest state
sure
const listenNotificationReceiveChange = async (
onPushNotification: (notification: NovuAppNotification | null) => void,
) => {
if (!sessionInitialized) {
throw new Error('Session is not initialized')
}

headlessService?.listenNotificationReceive({
listener: (response: IMessage) => {
const notifications = parseNovuNotification(response)
onPushNotification(notifications)
},
})
}
const listenNotificationReceiveChange = async (
onPushNotification: (notification: NovuAppNotification | null) => void,
) => {
if (!sessionInitialized) {
throw new Error('Session is not initialized')
}

headlessService?.listenNotificationReceive({
listener: (response: IMessage) => {
const notifications = parseNovuNotification(response)
onPushNotification(notifications)
},
})
}
but in the recent version of our codebase we don't use onPushNotification callback, so the usage looks the following (we just pass () => {}) : ``` initializeSession(userId, config.NovuIdentifier, novuSignature.toLocaleLowerCase()) .then(() => { fetchNotifications(onPushNotifications) listenNotificationReceiveChange(() => {}) return null })
12 replies