Skip to content

Commit aef26df

Browse files
authored
Merge pull request #4049 from QuantiModo/feature/refreshNotifications
qm.notifications.post instead of get
2 parents 7587b0d + 75b18bf commit aef26df

File tree

2 files changed

+9
-30
lines changed

2 files changed

+9
-30
lines changed

src/js/popup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ function updateQuestion(variableName){
243243
qmLog.error("Asking " + questionText + "!", "qmPopup.trackingReminderNotification is: " + JSON.stringify(qmPopup.trackingReminderNotification),
244244
{trackingReminderNotification: qmPopup.trackingReminderNotification});
245245
}
246-
if (qmPopup.trackingReminderNotification.valence === "positive" ||
246+
if (qmPopup.trackingReminderNotification.valence === "positive" ||
247247
qmPopup.trackingReminderNotification.valence === "negative") {
248248
numericRatingButtons().style.display = "none";
249249
faceRatingButtons().style.display = "block";
@@ -312,7 +312,7 @@ document.addEventListener('DOMContentLoaded', function(){
312312
}else{
313313
qmLog.pushDebug("popup addEventListener: Calling hidePopup...");
314314
hidePopup();
315-
qm.notifications.refreshNotifications(updateQuestion, qm.notifications.closePopup);
315+
qm.notifications.post(updateQuestion, qm.notifications.closePopup);
316316
}
317317
qmLog.pushDebug("popup addEventListener: calling setFaceButtonListeners...");
318318
setFaceButtonListeners();

src/js/qmHelpers.js

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5517,7 +5517,7 @@ var qm = {
55175517
refreshIfEmpty: function(successHandler, errorHandler){
55185518
if(!qm.notifications.getNumberInGlobalsOrLocalStorage()){
55195519
qm.qmLog.info('No notifications in local storage');
5520-
qm.notifications.refreshNotifications(successHandler, errorHandler);
5520+
qm.notifications.post(successHandler, errorHandler);
55215521
return true;
55225522
}
55235523
qm.qmLog.info(qm.notifications.getNumberInGlobalsOrLocalStorage() + ' notifications in local storage');
@@ -5528,7 +5528,7 @@ var qm = {
55285528
qm.qmLog.info("qm.notifications.refreshIfEmptyOrStale");
55295529
if(!qm.notifications.getNumberInGlobalsOrLocalStorage() || qm.notifications.getSecondsSinceLastNotificationsRefresh() > 3600){
55305530
qm.qmLog.info('Refreshing notifications because empty or last refresh was more than an hour ago');
5531-
qm.notifications.refreshNotifications(callback);
5531+
qm.notifications.post(callback);
55325532
}else{
55335533
qm.qmLog.info('Not refreshing notifications because last refresh was last than an hour ago and we have notifications in local storage');
55345534
if(callback){
@@ -5620,39 +5620,16 @@ var qm = {
56205620
}else{
56215621
console.info('No rating notifications for popup');
56225622
qm.notifications.getLastNotificationsRefreshTime();
5623-
qm.notifications.refreshNotifications();
5623+
qm.notifications.post();
56245624
return null;
56255625
}
56265626
},
56275627
deleteByVariableName: function(variableName){
56285628
return qm.storage.deleteByProperty(qm.items.trackingReminderNotifications, 'variableName', variableName);
56295629
},
56305630
promise: null,
5631-
refreshNotifications: function(successHandler, errorHandler, options){
5632-
var route = qm.apiPaths.trackingReminderNotificationsPast;
5633-
qm.api.getRequestUrl(route, function(url){
5634-
// Can't use QM SDK in service worker
5635-
qm.api.getViaXhrOrFetch(url, function(response){
5636-
if(!response){
5637-
qm.qmLog.error("No response from " + url);
5638-
if(errorHandler){
5639-
errorHandler("No response from " + url);
5640-
}
5641-
return;
5642-
}
5643-
if(response.status === 401){
5644-
qm.chrome.showSignInNotification();
5645-
}else{
5646-
qm.storage.setTrackingReminderNotifications(response.data);
5647-
if(successHandler){
5648-
successHandler(response.data);
5649-
}
5650-
}
5651-
})
5652-
}, options);
5653-
},
56545631
refreshAndShowPopupIfNecessary: function(notificationParams){
5655-
qm.notifications.refreshNotifications(notificationParams, function(trackingReminderNotifications){
5632+
qm.notifications.post(function(response){
56565633
var uniqueNotification = qm.notifications.getMostRecentUniqueNotificationNotInSyncQueue();
56575634
function objectLength(obj){
56585635
var result = 0;
@@ -5664,6 +5641,7 @@ var qm = {
56645641
}
56655642
return result;
56665643
}
5644+
var trackingReminderNotifications = qm.notifications.getFromGlobalsOrLocalStorage();
56675645
var numberOfWaitingNotifications = objectLength(trackingReminderNotifications);
56685646
if(uniqueNotification){
56695647
function getChromeRatingNotificationParams(trackingReminderNotification){
@@ -5769,7 +5747,7 @@ var qm = {
57695747
if(!successHandler){
57705748
return null;
57715749
}
5772-
qm.notifications.refreshNotifications(function(notifications){
5750+
qm.notifications.post(function(response){
57735751
var notification = qm.notifications.getMostRecentNotification();
57745752
if(notification){
57755753
successHandler(notification);
@@ -5854,6 +5832,7 @@ var qm = {
58545832
var measurements = response.measurements;
58555833
if(!measurements && response.data){measurements = response.data.measurements;}
58565834
if(measurements){qm.measurements.addMeasurementsToMemory(measurements);}
5835+
qm.storage.setTrackingReminderNotifications(response.data.trackingReminderNotifications);
58575836
if(successHandler){successHandler(response);}
58585837
}, function(response){
58595838
if(!response.success){

0 commit comments

Comments
 (0)