From 348506c92da2939da50359fc5bc8d4168a7a62af Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Fri, 18 Sep 2020 00:13:58 -0500 Subject: [PATCH 1/7] defaultLimit 20 --- src/js/qmHelpers.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/js/qmHelpers.js b/src/js/qmHelpers.js index 8765d3f2be..d633278a6e 100644 --- a/src/js/qmHelpers.js +++ b/src/js/qmHelpers.js @@ -9458,6 +9458,7 @@ var qm = { } }, userVariables: { + defaultLimit: 20, updateLatestMeasurementTime: function(variableName, lastValue){ qm.storage.getUserVariableByName(variableName, true, lastValue); }, @@ -9470,7 +9471,7 @@ var qm = { params.sort = '-latestMeasurementTime'; } if(!params.limit){ - params.limit = 50; + params.limit = qm.userVariables.defaultLimit; } params = qm.api.addGlobalParams(params); var cacheKey = 'getUserVariablesFromApi'; From 2f6d48881a0f674ff900da825975194096c82c54 Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Sun, 20 Sep 2020 21:00:51 -0500 Subject: [PATCH 2/7] Avoid infinite posting loop --- src/js/qmHelpers.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/js/qmHelpers.js b/src/js/qmHelpers.js index d2ce2a9a9f..6226a303a1 100644 --- a/src/js/qmHelpers.js +++ b/src/js/qmHelpers.js @@ -5856,16 +5856,14 @@ var qm = { if(measurements){qm.measurements.addMeasurementsToMemory(measurements);} if(successHandler){successHandler(response);} }, function(response){ - if(!response.success){ - qm.qmLog.error(response.message) - var newNotificationsSyncQueue = qm.storage.getItem(qm.items.notificationsSyncQueue); - if(newNotificationsSyncQueue){notifications = notifications.concat(newNotificationsSyncQueue);} - qm.storage.setItem(qm.items.notificationsSyncQueue, notifications); - if(errorHandler){errorHandler(response.message || response.error);} - } else{ // This happens when the error is a message saying the notification was already deleted - // so we don't want to put notifications back in queue - qm.qmLog.warn(response.message) - } + qm.qmLog.error(response.message) + // This happens when the error is a message saying the notification was already deleted + // so we don't want to put notifications back in queue + // Don't return to queue or we cause an infinite loop if we get a no changes error + // var newNotificationsSyncQueue = qm.storage.getItem(qm.items.notificationsSyncQueue); + // if(newNotificationsSyncQueue){notifications = notifications.concat(newNotificationsSyncQueue);} + // qm.storage.setItem(qm.items.notificationsSyncQueue, notifications); + if(errorHandler){errorHandler(response.message || response.error);} }); }, skip: function(trackingReminderNotification){ From 75b18bf02d493b9853c44c30557eebb150df0626 Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Tue, 22 Sep 2020 14:04:04 -0500 Subject: [PATCH 3/7] qm.notifications.post instead of get --- src/js/popup.js | 4 ++-- src/js/qmHelpers.js | 35 +++++++---------------------------- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/src/js/popup.js b/src/js/popup.js index ebd31ed167..0e952674c2 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -243,7 +243,7 @@ function updateQuestion(variableName){ qmLog.error("Asking " + questionText + "!", "qmPopup.trackingReminderNotification is: " + JSON.stringify(qmPopup.trackingReminderNotification), {trackingReminderNotification: qmPopup.trackingReminderNotification}); } - if (qmPopup.trackingReminderNotification.valence === "positive" || + if (qmPopup.trackingReminderNotification.valence === "positive" || qmPopup.trackingReminderNotification.valence === "negative") { numericRatingButtons().style.display = "none"; faceRatingButtons().style.display = "block"; @@ -312,7 +312,7 @@ document.addEventListener('DOMContentLoaded', function(){ }else{ qmLog.pushDebug("popup addEventListener: Calling hidePopup..."); hidePopup(); - qm.notifications.refreshNotifications(updateQuestion, qm.notifications.closePopup); + qm.notifications.post(updateQuestion, qm.notifications.closePopup); } qmLog.pushDebug("popup addEventListener: calling setFaceButtonListeners..."); setFaceButtonListeners(); diff --git a/src/js/qmHelpers.js b/src/js/qmHelpers.js index d2ce2a9a9f..3785dbf6f4 100644 --- a/src/js/qmHelpers.js +++ b/src/js/qmHelpers.js @@ -5517,7 +5517,7 @@ var qm = { refreshIfEmpty: function(successHandler, errorHandler){ if(!qm.notifications.getNumberInGlobalsOrLocalStorage()){ qm.qmLog.info('No notifications in local storage'); - qm.notifications.refreshNotifications(successHandler, errorHandler); + qm.notifications.post(successHandler, errorHandler); return true; } qm.qmLog.info(qm.notifications.getNumberInGlobalsOrLocalStorage() + ' notifications in local storage'); @@ -5528,7 +5528,7 @@ var qm = { qm.qmLog.info("qm.notifications.refreshIfEmptyOrStale"); if(!qm.notifications.getNumberInGlobalsOrLocalStorage() || qm.notifications.getSecondsSinceLastNotificationsRefresh() > 3600){ qm.qmLog.info('Refreshing notifications because empty or last refresh was more than an hour ago'); - qm.notifications.refreshNotifications(callback); + qm.notifications.post(callback); }else{ qm.qmLog.info('Not refreshing notifications because last refresh was last than an hour ago and we have notifications in local storage'); if(callback){ @@ -5620,7 +5620,7 @@ var qm = { }else{ console.info('No rating notifications for popup'); qm.notifications.getLastNotificationsRefreshTime(); - qm.notifications.refreshNotifications(); + qm.notifications.post(); return null; } }, @@ -5628,31 +5628,8 @@ var qm = { return qm.storage.deleteByProperty(qm.items.trackingReminderNotifications, 'variableName', variableName); }, promise: null, - refreshNotifications: function(successHandler, errorHandler, options){ - var route = qm.apiPaths.trackingReminderNotificationsPast; - qm.api.getRequestUrl(route, function(url){ - // Can't use QM SDK in service worker - qm.api.getViaXhrOrFetch(url, function(response){ - if(!response){ - qm.qmLog.error("No response from " + url); - if(errorHandler){ - errorHandler("No response from " + url); - } - return; - } - if(response.status === 401){ - qm.chrome.showSignInNotification(); - }else{ - qm.storage.setTrackingReminderNotifications(response.data); - if(successHandler){ - successHandler(response.data); - } - } - }) - }, options); - }, refreshAndShowPopupIfNecessary: function(notificationParams){ - qm.notifications.refreshNotifications(notificationParams, function(trackingReminderNotifications){ + qm.notifications.post(function(response){ var uniqueNotification = qm.notifications.getMostRecentUniqueNotificationNotInSyncQueue(); function objectLength(obj){ var result = 0; @@ -5664,6 +5641,7 @@ var qm = { } return result; } + var trackingReminderNotifications = qm.notifications.getFromGlobalsOrLocalStorage(); var numberOfWaitingNotifications = objectLength(trackingReminderNotifications); if(uniqueNotification){ function getChromeRatingNotificationParams(trackingReminderNotification){ @@ -5769,7 +5747,7 @@ var qm = { if(!successHandler){ return null; } - qm.notifications.refreshNotifications(function(notifications){ + qm.notifications.post(function(response){ var notification = qm.notifications.getMostRecentNotification(); if(notification){ successHandler(notification); @@ -5854,6 +5832,7 @@ var qm = { var measurements = response.measurements; if(!measurements && response.data){measurements = response.data.measurements;} if(measurements){qm.measurements.addMeasurementsToMemory(measurements);} + qm.storage.setTrackingReminderNotifications(response.data.trackingReminderNotifications); if(successHandler){successHandler(response);} }, function(response){ if(!response.success){ From a74400922a913cbb250fd526fdcc7a58ab48e323 Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Tue, 22 Sep 2020 14:27:11 -0500 Subject: [PATCH 4/7] Recent values --- src/templates/input/action-buttons-fragment.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/input/action-buttons-fragment.html b/src/templates/input/action-buttons-fragment.html index 9e3855e0a5..6a8e8b74ec 100644 --- a/src/templates/input/action-buttons-fragment.html +++ b/src/templates/input/action-buttons-fragment.html @@ -1,7 +1,7 @@

Recent Values

From 7760f5ff966f717bc7eb108179df9f17615195f5 Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Tue, 22 Sep 2020 15:24:07 -0500 Subject: [PATCH 6/7] qm.notifications.syncTrackingReminderNotifications --- src/js/controllers/appCtrl.js | 2 +- src/js/controllers/remindersInboxCtrl.js | 2 +- src/js/popup.js | 2 +- src/js/qmHelpers.js | 18 +++++++++--------- src/js/services/qmService.js | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/js/controllers/appCtrl.js b/src/js/controllers/appCtrl.js index e679ed023f..b45c019759 100644 --- a/src/js/controllers/appCtrl.js +++ b/src/js/controllers/appCtrl.js @@ -14,7 +14,7 @@ angular.module('starter')// Parent Controller - This controller runs before ever }); $scope.$on('$ionicView.afterEnter', function(e){ qmLog.debug($scope.controller_name + ".afterEnter so posting queued notifications if any"); - qm.notifications.post(); + qmService.syncTrackingReminderNotifications(); qmService.refreshUserUsingAccessTokenInUrlIfNecessary(); $rootScope.setMicAndSpeechEnabled(qm.mic.getMicEnabled()); qm.chatButton.setZohoChatButtonZIndex(); diff --git a/src/js/controllers/remindersInboxCtrl.js b/src/js/controllers/remindersInboxCtrl.js index 9205e2d304..9c1cc53eb5 100644 --- a/src/js/controllers/remindersInboxCtrl.js +++ b/src/js/controllers/remindersInboxCtrl.js @@ -77,7 +77,7 @@ angular.module('starter').controller('RemindersInboxCtrl', ["$scope", "$state", }); $scope.$on('$ionicView.beforeLeave', function(){ qmLog.debug('RemindersInboxCtrl beforeLeave'); - qm.notifications.post(); + qmService.syncTrackingReminderNotifications(); }); $scope.$on('$ionicView.afterLeave', function(){ qmLog.debug('RemindersInboxCtrl afterLeave'); diff --git a/src/js/popup.js b/src/js/popup.js index 0e952674c2..c383c9859f 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -312,7 +312,7 @@ document.addEventListener('DOMContentLoaded', function(){ }else{ qmLog.pushDebug("popup addEventListener: Calling hidePopup..."); hidePopup(); - qm.notifications.post(updateQuestion, qm.notifications.closePopup); + qm.notifications.syncTrackingReminderNotifications(updateQuestion, qm.notifications.closePopup); } qmLog.pushDebug("popup addEventListener: calling setFaceButtonListeners..."); setFaceButtonListeners(); diff --git a/src/js/qmHelpers.js b/src/js/qmHelpers.js index dced833d16..0d9be39f65 100644 --- a/src/js/qmHelpers.js +++ b/src/js/qmHelpers.js @@ -5517,7 +5517,7 @@ var qm = { refreshIfEmpty: function(successHandler, errorHandler){ if(!qm.notifications.getNumberInGlobalsOrLocalStorage()){ qm.qmLog.info('No notifications in local storage'); - qm.notifications.post(successHandler, errorHandler); + qm.notifications.syncTrackingReminderNotifications(successHandler, errorHandler); return true; } qm.qmLog.info(qm.notifications.getNumberInGlobalsOrLocalStorage() + ' notifications in local storage'); @@ -5528,7 +5528,7 @@ var qm = { qm.qmLog.info("qm.notifications.refreshIfEmptyOrStale"); if(!qm.notifications.getNumberInGlobalsOrLocalStorage() || qm.notifications.getSecondsSinceLastNotificationsRefresh() > 3600){ qm.qmLog.info('Refreshing notifications because empty or last refresh was more than an hour ago'); - qm.notifications.post(callback); + qm.notifications.syncTrackingReminderNotifications(callback); }else{ qm.qmLog.info('Not refreshing notifications because last refresh was last than an hour ago and we have notifications in local storage'); if(callback){ @@ -5620,7 +5620,7 @@ var qm = { }else{ console.info('No rating notifications for popup'); qm.notifications.getLastNotificationsRefreshTime(); - qm.notifications.post(); + qm.notifications.syncTrackingReminderNotifications(); return null; } }, @@ -5629,7 +5629,7 @@ var qm = { }, promise: null, refreshAndShowPopupIfNecessary: function(notificationParams){ - qm.notifications.post(function(response){ + qm.notifications.syncTrackingReminderNotifications(function(response){ var uniqueNotification = qm.notifications.getMostRecentUniqueNotificationNotInSyncQueue(); function objectLength(obj){ var result = 0; @@ -5747,7 +5747,7 @@ var qm = { if(!successHandler){ return null; } - qm.notifications.post(function(response){ + qm.notifications.syncTrackingReminderNotifications(function(response){ var notification = qm.notifications.getMostRecentNotification(); if(notification){ successHandler(notification); @@ -5759,7 +5759,7 @@ var qm = { schedulePost: function(delayInMilliseconds){ var queue = qm.storage.getItem(qm.items.notificationsSyncQueue); if(queue && queue.length > 10){ - qm.notifications.post(); + qm.notifications.syncTrackingReminderNotifications(); return; } if(!delayInMilliseconds){ @@ -5775,7 +5775,7 @@ var qm = { } setTimeout(function(){ qm.qmLog.info("Notifications sync countdown completed. Syncing now... "); - qm.notifications.post(); + qm.notifications.syncTrackingReminderNotifications(); }, delayInMilliseconds); }else{ if(!qm.platform.isMobile()){ // Better performance @@ -5804,8 +5804,8 @@ var qm = { qm.notifications.deleteByVariableName(n.variableName); qm.notifications.addToSyncQueue(n); }, - post: function(successHandler, errorHandler){ - qm.qmLog.debug("Called postNotifications..."); + syncTrackingReminderNotifications: function(successHandler, errorHandler){ + qm.qmLog.debug("Called syncTrackingReminderNotifications..."); var notifications = qm.storage.getItem(qm.items.notificationsSyncQueue); qm.storage.removeItem(qm.items.notificationsSyncQueue); qm.storage.removeItem(qm.items.trackingReminderNotificationSyncScheduled); diff --git a/src/js/services/qmService.js b/src/js/services/qmService.js index f50d8b5efe..4c7fb65a13 100644 --- a/src/js/services/qmService.js +++ b/src/js/services/qmService.js @@ -2890,12 +2890,12 @@ angular.module('starter').factory('qmService', ["$http", "$q", "$rootScope", "$i deferred.reject(error); }); }; - qm.notifications.post(function(){ + qmService.syncTrackingReminderNotifications().then(function(){ postTrackingRemindersToApiAndHandleResponse(); - }, function(error){ + }, function (err){ postTrackingRemindersToApiAndHandleResponse(); deferred.reject(error); - }); + }) }else{ qmLog.info('syncTrackingReminders: trackingReminderSyncQueue empty so just fetching trackingReminders from API', null); qm.reminderHelper.getTrackingRemindersFromApi({force: force}, function(reminders){ @@ -5105,7 +5105,7 @@ angular.module('starter').factory('qmService', ["$http", "$q", "$rootScope", "$i var deferred = $q.defer(); if(params && params.noCache){qmService.notificationsPromise = false;} if(qmService.notificationsPromise){return qmService.notificationsPromise;} - qm.notifications.post(function(response){ + qm.notifications.syncTrackingReminderNotifications(function(response){ var notifications = qm.notifications.getFromGlobalsOrLocalStorage(); if(notifications.length && $rootScope.platform.isMobile && getDeviceTokenToSync()){qmService.registerDeviceToken();} qmService.notifications.broadcastGetTrackingReminderNotifications(); From 45d4bd75bb3bea6c0861a08f8b00fd825f5b809b Mon Sep 17 00:00:00 2001 From: "Mike P. Sinn" Date: Tue, 22 Sep 2020 16:29:48 -0500 Subject: [PATCH 7/7] Handle no response --- src/js/qmHelpers.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/js/qmHelpers.js b/src/js/qmHelpers.js index 0d9be39f65..ed8b0eaba8 100644 --- a/src/js/qmHelpers.js +++ b/src/js/qmHelpers.js @@ -5829,6 +5829,15 @@ var qm = { }) qm.api.postToQuantiModo(body, 'v3/trackingReminderNotifications', function(response){ + if(!response){ + var err = "No response from postToQuantiModo(body, 'v3/trackingReminderNotifications"; + if(errorHandler){ + errorHandler(err); + return; + } else { + throw err; + } + } var measurements = response.measurements || response.data.measurements; if(measurements){qm.measurements.addMeasurementsToMemory(measurements);} var trackingReminderNotifications = response.trackingReminderNotifications || response.data.trackingReminderNotifications;