Fix merge conflict and set proper polling times

This commit is contained in:
Roxanne Skelly 2018-09-27 12:03:37 -07:00
parent 7257a99414
commit 330789471d
2 changed files with 23 additions and 13 deletions

View file

@ -107,7 +107,9 @@ function AppUi(properties) {
that.notificationPollCaresAboutSince = false; that.notificationPollCaresAboutSince = false;
that.notificationInitialCallbackMade = false; that.notificationInitialCallbackMade = false;
that.notificationDisplayBanner = function (message) { that.notificationDisplayBanner = function (message) {
Window.displayAnnouncement(message); if (!that.isOpen) {
Window.displayAnnouncement(message);
}
}; };
// //
// END Notification Handling Defaults // END Notification Handling Defaults
@ -118,6 +120,7 @@ function AppUi(properties) {
// Set isOpen, wireEventBridge, set buttonActive as appropriate, // Set isOpen, wireEventBridge, set buttonActive as appropriate,
// and finally call onOpened() or onClosed() IFF defined. // and finally call onOpened() or onClosed() IFF defined.
that.setCurrentVisibleScreenMetadata(type, url); that.setCurrentVisibleScreenMetadata(type, url);
if (that.checkIsOpen(type, url)) { if (that.checkIsOpen(type, url)) {
that.wireEventBridge(true); that.wireEventBridge(true);
if (!that.isOpen) { if (!that.isOpen) {
@ -155,17 +158,21 @@ function AppUi(properties) {
return; return;
} }
// User is "appearing offline" // User is "appearing offline" or is offline
if (GlobalServices.findableBy === "none") { if (GlobalServices.findableBy === "none" || Account.username === "") {
that.notificationPollTimeout = Script.setTimeout(that.notificationPoll, that.notificationPollTimeoutMs); that.notificationPollTimeout = Script.setTimeout(that.notificationPoll, that.notificationPollTimeoutMs);
return; return;
} }
var url = METAVERSE_BASE + that.notificationPollEndpoint; 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) { if (that.notificationPollCaresAboutSince) {
url = url + "&since=" + (new Date().getTime()); url = url + "&since=" + lastPollTimestamp/1000;
} }
Settings.setValue(settingsKey, currentTimestamp);
console.debug(that.buttonName, 'polling for notifications at endpoint', url); console.debug(that.buttonName, 'polling for notifications at endpoint', url);
@ -193,17 +200,18 @@ function AppUi(properties) {
} else { } else {
concatenatedServerResponse = concatenatedServerResponse.concat(that.notificationDataProcessPage(response)); concatenatedServerResponse = concatenatedServerResponse.concat(that.notificationDataProcessPage(response));
currentDataPageToRetrieve++; currentDataPageToRetrieve++;
request({ uri: (url + "&page=" + currentDataPageToRetrieve) }, requestCallback); request({ json: true, uri: (url + "&page=" + currentDataPageToRetrieve) }, requestCallback);
} }
} }
request({ uri: url }, requestCallback); request({ json: true, uri: url }, requestCallback);
}; };
// This won't do anything if there isn't a notification endpoint set // This won't do anything if there isn't a notification endpoint set
that.notificationPoll(); that.notificationPoll();
function availabilityChanged() { function restartNotificationPoll() {
that.notificationInitialCallbackMade = false;
if (that.notificationPollTimeout) { if (that.notificationPollTimeout) {
Script.clearTimeout(that.notificationPollTimeout); Script.clearTimeout(that.notificationPollTimeout);
that.notificationPollTimeout = false; that.notificationPollTimeout = false;
@ -303,7 +311,8 @@ function AppUi(properties) {
} : that.ignore; } : that.ignore;
that.onScriptEnding = function onScriptEnding() { that.onScriptEnding = function onScriptEnding() {
// Close if necessary, clean up any remaining handlers, and remove the button. // Close if necessary, clean up any remaining handlers, and remove the button.
GlobalServices.findableByChanged.disconnect(availabilityChanged); GlobalServices.myUsernameChanged.disconnect(restartNotificationPoll);
GlobalServices.findableByChanged.disconnect(restartNotificationPoll);
if (that.isOpen) { if (that.isOpen) {
that.close(); that.close();
} }
@ -323,7 +332,8 @@ function AppUi(properties) {
that.tablet.screenChanged.connect(that.onScreenChanged); that.tablet.screenChanged.connect(that.onScreenChanged);
that.button.clicked.connect(that.onClicked); that.button.clicked.connect(that.onClicked);
Script.scriptEnding.connect(that.onScriptEnding); Script.scriptEnding.connect(that.onScriptEnding);
GlobalServices.findableByChanged.connect(availabilityChanged); GlobalServices.findableByChanged.connect(restartNotificationPoll);
GlobalServices.myUsernameChanged.connect(restartNotificationPoll);
if (that.buttonName == Settings.getValue("startUpApp")) { if (that.buttonName == Settings.getValue("startUpApp")) {
Settings.setValue("startUpApp", ""); Settings.setValue("startUpApp", "");
Script.setTimeout(function () { Script.setTimeout(function () {

View file

@ -9,10 +9,10 @@ const GetBuildInfo = hfApp.getBuildInfo;
const buildInfo = GetBuildInfo(); const buildInfo = GetBuildInfo();
const notificationIcon = path.join(__dirname, '../../resources/console-notification.png'); const notificationIcon = path.join(__dirname, '../../resources/console-notification.png');
const STORIES_NOTIFICATION_POLL_TIME_MS = 15 * 1000; // 120 * 1000; const STORIES_NOTIFICATION_POLL_TIME_MS = 120 * 1000;
const PEOPLE_NOTIFICATION_POLL_TIME_MS = 15 * 1000; // 120 * 1000; const PEOPLE_NOTIFICATION_POLL_TIME_MS = 120 * 1000;
const WALLET_NOTIFICATION_POLL_TIME_MS = 15 * 1000; // 600 * 1000; const WALLET_NOTIFICATION_POLL_TIME_MS = 600 * 1000;
const MARKETPLACE_NOTIFICATION_POLL_TIME_MS = 15 * 1000; // 600 * 1000; const MARKETPLACE_NOTIFICATION_POLL_TIME_MS = 600 * 1000;
const METAVERSE_SERVER_URL= process.env.HIFI_METAVERSE_URL ? process.env.HIFI_METAVERSE_URL : 'https://metaverse.highfidelity.com' const METAVERSE_SERVER_URL= process.env.HIFI_METAVERSE_URL ? process.env.HIFI_METAVERSE_URL : 'https://metaverse.highfidelity.com'
const STORIES_URL= '/api/v1/user_stories'; const STORIES_URL= '/api/v1/user_stories';