From 783cc19502219705c14bdecbe98790d0abf9f77b Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 7 Jul 2020 22:53:41 +0000 Subject: [PATCH] --- ayanova/src/api/notifypoll.js | 37 +++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/ayanova/src/api/notifypoll.js b/ayanova/src/api/notifypoll.js index 94366938..7616d508 100644 --- a/ayanova/src/api/notifypoll.js +++ b/ayanova/src/api/notifypoll.js @@ -1,5 +1,38 @@ /* xeslint-disable */ -let _timerId = null; +let keepPolling = false; -export default { startPolling() {}, stopPolling() {} }; +export default { + async startPolling() { + console.log("notifypoll::starting polling"); + keepPolling = true; + try { + while (keepPolling == true) { + let status = await window.$gz.api.get("notify/new-count"); + if (status.error) { + throw status.error; + } + console.log("notifypoll::new count ", status); + // window.$gz.store.commit("setNotifyNewCount", status.data); + await window.$gz.util.sleepAsync(10000); + } + } catch (error) { + keepPolling = false; + window.$gz.errorHandler.handleGeneralError( + "Error checking for notifications", + "notifypoll", + null, + null, + error + ); + window.$gz.eventBus.$emit( + "notify-error", + "Error checking for notifications, see about->log for details; log out and back in again to reset" + ); + } + }, + stopPolling() { + keepPolling = false; + console.log("notifypoll::stopping polling"); + } +};