Notifications for MARKET

This commit is contained in:
Zach Fox 2018-09-18 14:45:14 -07:00
parent 04b44d0594
commit 55a0f77697
4 changed files with 47 additions and 20 deletions

View file

@ -45,14 +45,6 @@ Item {
onHistoryResult : { onHistoryResult : {
transactionHistoryModel.handlePage(null, result); transactionHistoryModel.handlePage(null, result);
} }
onAvailableUpdatesResult: {
if (result.status !== 'success') {
console.log("Failed to get Available Updates", result.data.message);
} else {
sendToScript({method: 'wallet_availableUpdatesReceived', numUpdates: result.data.updates.length });
}
}
} }
Connections { Connections {

View file

@ -163,13 +163,13 @@ function AppUi(properties) {
var url = METAVERSE_BASE + that.notificationPollEndpoint; var url = METAVERSE_BASE + that.notificationPollEndpoint;
if (that.notificationPollCaresAboutSince) { var settingsKey = "notifications/" + that.buttonName + "/lastPoll";
var settingsKey = "notifications/" + that.buttonName + "/lastSince";
var currentTimestamp = new Date().getTime(); var currentTimestamp = new Date().getTime();
var settingsTimestamp = Settings.getValue(settingsKey, currentTimestamp); var lastPollTimestamp = Settings.getValue(settingsKey, currentTimestamp);
url = url + "&since=" + settingsTimestamp; if (that.notificationPollCaresAboutSince) {
Settings.setValue(settingsKey, currentTimestamp); url = url + "&since=" + lastPollTimestamp;
} }
Settings.setValue(settingsKey, currentTimestamp);
console.debug(that.buttonName, 'polling for notifications at endpoint', url); console.debug(that.buttonName, 'polling for notifications at endpoint', url);

View file

@ -474,9 +474,6 @@ function fromQml(message) {
Window.location = "hifi://BankOfHighFidelity"; Window.location = "hifi://BankOfHighFidelity";
} }
break; break;
case 'wallet_availableUpdatesReceived':
// NOP
break;
case 'http.request': case 'http.request':
// Handled elsewhere, don't log. // Handled elsewhere, don't log.
break; break;

View file

@ -908,10 +908,9 @@ var onQmlMessageReceived = function onQmlMessageReceived(message) {
removeOverlays(); removeOverlays();
} }
break; break;
case 'wallet_availableUpdatesReceived':
case 'purchases_availableUpdatesReceived': case 'purchases_availableUpdatesReceived':
userHasUpdates = message.numUpdates > 0; shouldShowDot = message.numUpdates > 0;
ui.messagesWaiting(userHasUpdates); ui.messagesWaiting(shouldShowDot);
break; break;
case 'purchases_updateWearables': case 'purchases_updateWearables':
var currentlyWornWearables = []; var currentlyWornWearables = [];
@ -1030,6 +1029,39 @@ var onTabletScreenChanged = function onTabletScreenChanged(type, url) {
"\nNew screen URL: " + url + "\nCurrent app open status: " + ui.isOpen + "\n"); "\nNew screen URL: " + url + "\nCurrent app open status: " + ui.isOpen + "\n");
}; };
function notificationDataProcessPage(data) {
return data.data.updates;
}
var shouldShowDot = false;
function notificationPollCallback(updatesArray) {
shouldShowDot = shouldShowDot || updatesArray.length > 0;
ui.messagesWaiting(shouldShowDot);
if (updatesArray.length > 0) {
var message;
if (!ui.notificationInitialCallbackMade) {
message = updatesArray.length + " of your purchased items have updates available! " +
"Open MARKET to update.";
ui.notificationDisplayBanner(message);
ui.notificationPollCaresAboutSince = true;
} else {
for (var i = 0; i < updatesArray.length; i++) {
message = "There's an update available for your version of \"" +
updatesArray[i].marketplace_item_name + "\"!" +
"Open MARKET to update.";
ui.notificationDisplayBanner(message);
}
}
}
}
function isReturnedDataEmpty(data) {
var historyArray = data.data.updates;
return historyArray.length === 0;
}
// //
// Manage the connection between the button and the window. // Manage the connection between the button and the window.
// //
@ -1044,7 +1076,13 @@ function startup() {
inject: MARKETPLACES_INJECT_SCRIPT_URL, inject: MARKETPLACES_INJECT_SCRIPT_URL,
home: MARKETPLACE_URL_INITIAL, home: MARKETPLACE_URL_INITIAL,
onScreenChanged: onTabletScreenChanged, onScreenChanged: onTabletScreenChanged,
onMessage: onQmlMessageReceived onMessage: onQmlMessageReceived,
notificationPollEndpoint: "/api/v1/notifications?source=commerce-available_updates&per_page=10",
notificationPollTimeoutMs: 60000,
notificationDataProcessPage: notificationDataProcessPage,
notificationPollCallback: notificationPollCallback,
notificationPollStopPaginatingConditionMet: isReturnedDataEmpty,
notificationPollCaresAboutSince: false // Changes to true after first poll
}); });
ContextOverlay.contextOverlayClicked.connect(openInspectionCertificateQML); ContextOverlay.contextOverlayClicked.connect(openInspectionCertificateQML);
Entities.canWriteAssetsChanged.connect(onCanWriteAssetsChanged); Entities.canWriteAssetsChanged.connect(onCanWriteAssetsChanged);