Notification with Service Workers now is working!
When a Notification arrives, it save into the IndexDb, then in Vue.js call a polling to check in the db if there is a different record count. If is different then call a get to update the notification.
This commit is contained in:
@@ -21,6 +21,7 @@ import { shared_consts } from '@/common/shared_vuejs'
|
||||
import { useI18n } from '@/boot/i18n'
|
||||
import { useQuasar } from 'quasar'
|
||||
import { costanti } from '@costanti'
|
||||
import { waitAndcheckPendingNotif } from '../../../store/Modules/ApiTables'
|
||||
|
||||
const namespace = 'notifModule'
|
||||
|
||||
@@ -50,6 +51,9 @@ export default defineComponent({
|
||||
const userId = ref('')
|
||||
const open = ref(false)
|
||||
|
||||
const polling = ref(<any> null)
|
||||
const eseguipolling = ref(true)
|
||||
|
||||
const notifsel = ref(<INotif>{
|
||||
dest: '',
|
||||
datenotif: new Date()
|
||||
@@ -61,6 +65,30 @@ export default defineComponent({
|
||||
//
|
||||
// }
|
||||
|
||||
function checkIfArrivedSomeNotif() {
|
||||
waitAndcheckPendingNotif()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
function checkifpolling() {
|
||||
console.log('checkifpolling')
|
||||
if (eseguipolling.value) {
|
||||
if (!polling.value) {
|
||||
console.log('esegui POLLING....')
|
||||
polling.value = setInterval(() => {
|
||||
checkIfArrivedSomeNotif()
|
||||
}, 3000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function beforeDestroy() {
|
||||
console.log('beforeDestroy')
|
||||
if (polling.value)
|
||||
clearInterval(polling.value)
|
||||
}
|
||||
|
||||
watch(() => usernotifs.value, async (to: any, from: any) => {
|
||||
|
||||
if (usernotifs.value) {
|
||||
@@ -152,6 +180,7 @@ export default defineComponent({
|
||||
async function mounted() {
|
||||
myuser.value = userStore.my
|
||||
await refreshdata(userStore.my.username)
|
||||
checkifpolling()
|
||||
}
|
||||
|
||||
onMounted(mounted)
|
||||
@@ -177,7 +206,6 @@ export default defineComponent({
|
||||
notifStore,
|
||||
show_all,
|
||||
t,
|
||||
$q,
|
||||
username,
|
||||
userStore,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user