mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 08:14:48 +02:00
Notifications for MARKET
This commit is contained in:
parent
04b44d0594
commit
55a0f77697
4 changed files with 47 additions and 20 deletions
|
@ -45,14 +45,6 @@ Item {
|
|||
onHistoryResult : {
|
||||
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 {
|
||||
|
|
|
@ -163,13 +163,13 @@ function AppUi(properties) {
|
|||
|
||||
var url = METAVERSE_BASE + that.notificationPollEndpoint;
|
||||
|
||||
var settingsKey = "notifications/" + that.buttonName + "/lastPoll";
|
||||
var currentTimestamp = new Date().getTime();
|
||||
var lastPollTimestamp = Settings.getValue(settingsKey, currentTimestamp);
|
||||
if (that.notificationPollCaresAboutSince) {
|
||||
var settingsKey = "notifications/" + that.buttonName + "/lastSince";
|
||||
var currentTimestamp = new Date().getTime();
|
||||
var settingsTimestamp = Settings.getValue(settingsKey, currentTimestamp);
|
||||
url = url + "&since=" + settingsTimestamp;
|
||||
Settings.setValue(settingsKey, currentTimestamp);
|
||||
url = url + "&since=" + lastPollTimestamp;
|
||||
}
|
||||
Settings.setValue(settingsKey, currentTimestamp);
|
||||
|
||||
console.debug(that.buttonName, 'polling for notifications at endpoint', url);
|
||||
|
||||
|
|
|
@ -474,9 +474,6 @@ function fromQml(message) {
|
|||
Window.location = "hifi://BankOfHighFidelity";
|
||||
}
|
||||
break;
|
||||
case 'wallet_availableUpdatesReceived':
|
||||
// NOP
|
||||
break;
|
||||
case 'http.request':
|
||||
// Handled elsewhere, don't log.
|
||||
break;
|
||||
|
|
|
@ -908,10 +908,9 @@ var onQmlMessageReceived = function onQmlMessageReceived(message) {
|
|||
removeOverlays();
|
||||
}
|
||||
break;
|
||||
case 'wallet_availableUpdatesReceived':
|
||||
case 'purchases_availableUpdatesReceived':
|
||||
userHasUpdates = message.numUpdates > 0;
|
||||
ui.messagesWaiting(userHasUpdates);
|
||||
shouldShowDot = message.numUpdates > 0;
|
||||
ui.messagesWaiting(shouldShowDot);
|
||||
break;
|
||||
case 'purchases_updateWearables':
|
||||
var currentlyWornWearables = [];
|
||||
|
@ -1030,6 +1029,39 @@ var onTabletScreenChanged = function onTabletScreenChanged(type, url) {
|
|||
"\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.
|
||||
//
|
||||
|
@ -1044,7 +1076,13 @@ function startup() {
|
|||
inject: MARKETPLACES_INJECT_SCRIPT_URL,
|
||||
home: MARKETPLACE_URL_INITIAL,
|
||||
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);
|
||||
Entities.canWriteAssetsChanged.connect(onCanWriteAssetsChanged);
|
||||
|
|
Loading…
Reference in a new issue