From 79b11296f170bbcb1a435388a9838b857f8d0202 Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Wed, 3 Oct 2018 13:45:39 -0700 Subject: [PATCH 1/6] Checkpoint sys tray submenus --- server-console/src/main.js | 29 +++++++++- .../src/modules/hf-notifications.js | 55 +++++++++++++++---- 2 files changed, 72 insertions(+), 12 deletions(-) diff --git a/server-console/src/main.js b/server-console/src/main.js index c26938745b..5a07377a66 100644 --- a/server-console/src/main.js +++ b/server-console/src/main.js @@ -568,7 +568,34 @@ function updateLabels(serverState) { labels.people.icon = pendingNotifications[HifiNotificationType.PEOPLE] ? menuNotificationIcon : null; labels.wallet.icon = pendingNotifications[HifiNotificationType.WALLET] ? menuNotificationIcon : null; labels.marketplace.icon = pendingNotifications[HifiNotificationType.MARKETPLACE] ? menuNotificationIcon : null; - + var onlineUsers = trayNotifications.getOnlineUsers(); + if(onlineUsers) { + labels.people.submenu = []; + for (var name in onlineUsers) { + labels.people.submenu.push({ + label: name, + click: function () { + setNotificationState(HifiNotificationType.GOTO, false); + StartInterface("hifi://" + onlineUsers[name].location.root.name + onlineUsers[name].location.path); + } + }); + } + } + var currentStories = trayNotifications.getCurrentStories(); + console.log("CURRENT STORIES"); + console.log(currentStories); + if(currentStories) { + labels.goto.submenu = []; + for (var location in currentStories) { + labels.goto.submenu.push({ + label: "event in " + location, + click: function () { + setNotificationState(HifiNotificationType.GOTO, false); + StartInterface("hifi://" + location + getCurrentStories[location].path); + } + }); + } + } } function updateTrayMenu(serverState) { diff --git a/server-console/src/modules/hf-notifications.js b/server-console/src/modules/hf-notifications.js index f3b6912c08..266853651a 100644 --- a/server-console/src/modules/hf-notifications.js +++ b/server-console/src/modules/hf-notifications.js @@ -10,8 +10,8 @@ const buildInfo = GetBuildInfo(); const osType = os.type(); const notificationIcon = path.join(__dirname, '../../resources/console-notification.png'); -const STORIES_NOTIFICATION_POLL_TIME_MS = 120 * 1000; -const PEOPLE_NOTIFICATION_POLL_TIME_MS = 120 * 1000; +const STORIES_NOTIFICATION_POLL_TIME_MS = 15 * 1000; +const PEOPLE_NOTIFICATION_POLL_TIME_MS = 15 * 1000; const WALLET_NOTIFICATION_POLL_TIME_MS = 600 * 1000; const MARKETPLACE_NOTIFICATION_POLL_TIME_MS = 600 * 1000; const OSX_CLICK_DELAY_TIMEOUT = 500; @@ -137,7 +137,8 @@ HifiNotification.prototype = { function HifiNotifications(config, menuNotificationCallback) { this.config = config; this.menuNotificationCallback = menuNotificationCallback; - this.onlineUsers = new Set([]); + this.onlineUsers = {}; + this.currentStories = {}; this.storiesSince = new Date(this.config.get("storiesNotifySince", "1970-01-01T00:00:00.000Z")); this.peopleSince = new Date(this.config.get("peopleNotifySince", "1970-01-01T00:00:00.000Z")); this.walletSince = new Date(this.config.get("walletNotifySince", "1970-01-01T00:00:00.000Z")); @@ -214,6 +215,12 @@ HifiNotifications.prototype = { clearInterval(this.marketplacePollTimer); } }, + getOnlineUsers: function () { + return this.onlineUsers; + }, + getCurrentStories: function () { + return this.currentStories; + }, _showNotification: function () { var _this = this; @@ -226,7 +233,7 @@ HifiNotifications.prototype = { // previous notification immediately when a // new one is submitted _this.pendingNotifications.shift(); - if(_this.pendingNotifications.length > 0) { + if (_this.pendingNotifications.length > 0) { _this._showNotification(); } }); @@ -358,7 +365,33 @@ HifiNotifications.prototype = { 'bearer': token } }, function (error, data) { - _this._pollToDisableHighlight(NotificationType.GOTO, error, data); + if (error || !data.body) { + console.log("Error: unable to get " + url); + finished(false); + return; + } + var content = JSON.parse(data.body); + if (!content || content.status != 'success') { + console.log("Error: unable to get " + url); + finished(false); + return; + } + console.log(content); + if (!content.total_entries) { + finished(true, token); + return; + } + if (!content.total_entries) { + this.menuNotificationCallback(NotificationType.GOTO, false); + } + _this.currentStories = {}; + content.user_stories.forEach(function (story) { + // only show a single instance of each story location + // in the menu. This may cause issues with domains + // where the story locations are significantly different + // for each story. + _this.currentStories[story.place_name] = story; + }); }); } }); @@ -404,17 +437,17 @@ HifiNotifications.prototype = { console.log(content); if (!content.total_entries) { _this.menuNotificationCallback(NotificationType.PEOPLE, false); - _this.onlineUsers = new Set([]); + _this.onlineUsers = {}; return; } - var currentUsers = new Set([]); + var currentUsers = {}; var newUsers = new Set([]); content.data.users.forEach(function (user) { - currentUsers.add(user.username); - if (!_this.onlineUsers.has(user.username)) { - newUsers.add(user); - _this.onlineUsers.add(user.username); + currentUsers[user.username] = user; + if (!(user.username in _this.onlineUsers)) { + newUsers.add(user.username); + _this.onlineUsers[user.username] = user; } }); _this.onlineUsers = currentUsers; From 2876338a97d189d07194298aba8f46ebf64fdfbf Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Wed, 3 Oct 2018 15:35:19 -0700 Subject: [PATCH 2/6] Display up to 30 submenus for GOTO --- server-console/src/modules/hf-notifications.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server-console/src/modules/hf-notifications.js b/server-console/src/modules/hf-notifications.js index 266853651a..398a03f427 100644 --- a/server-console/src/modules/hf-notifications.js +++ b/server-console/src/modules/hf-notifications.js @@ -10,8 +10,8 @@ const buildInfo = GetBuildInfo(); const osType = os.type(); const notificationIcon = path.join(__dirname, '../../resources/console-notification.png'); -const STORIES_NOTIFICATION_POLL_TIME_MS = 15 * 1000; -const PEOPLE_NOTIFICATION_POLL_TIME_MS = 15 * 1000; +const STORIES_NOTIFICATION_POLL_TIME_MS = 120 * 1000; +const PEOPLE_NOTIFICATION_POLL_TIME_MS = 120 * 1000; const WALLET_NOTIFICATION_POLL_TIME_MS = 600 * 1000; const MARKETPLACE_NOTIFICATION_POLL_TIME_MS = 600 * 1000; const OSX_CLICK_DELAY_TIMEOUT = 500; @@ -354,7 +354,7 @@ HifiNotifications.prototype = { 'include_actions=announcement', 'restriction=open,hifi', 'require_online=true', - 'per_page=1' + 'per_page=' + MAX_NOTIFICATION_ITEMS ]; var url = METAVERSE_SERVER_URL + STORIES_URL + '?' + options.join('&'); // call a second time to determine if there are no more stories and we should From b052a12d16d07821fc4d33499e692a0beb515082 Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Wed, 10 Oct 2018 11:48:12 -0700 Subject: [PATCH 3/6] Remove unnecessary logging. --- server-console/src/main.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/server-console/src/main.js b/server-console/src/main.js index 5a07377a66..1db5283999 100644 --- a/server-console/src/main.js +++ b/server-console/src/main.js @@ -582,8 +582,6 @@ function updateLabels(serverState) { } } var currentStories = trayNotifications.getCurrentStories(); - console.log("CURRENT STORIES"); - console.log(currentStories); if(currentStories) { labels.goto.submenu = []; for (var location in currentStories) { From f6a8383d539c7544f47d43c3f8ee48cb49ae006d Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Wed, 10 Oct 2018 15:49:22 -0700 Subject: [PATCH 4/6] Bugfixes --- server-console/src/main.js | 11 +++++++---- server-console/src/modules/hf-notifications.js | 17 +++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/server-console/src/main.js b/server-console/src/main.js index 1db5283999..5c77c26270 100644 --- a/server-console/src/main.js +++ b/server-console/src/main.js @@ -569,20 +569,23 @@ function updateLabels(serverState) { labels.wallet.icon = pendingNotifications[HifiNotificationType.WALLET] ? menuNotificationIcon : null; labels.marketplace.icon = pendingNotifications[HifiNotificationType.MARKETPLACE] ? menuNotificationIcon : null; var onlineUsers = trayNotifications.getOnlineUsers(); - if(onlineUsers) { + if (onlineUsers) { labels.people.submenu = []; for (var name in onlineUsers) { labels.people.submenu.push({ label: name, + enabled: (onlineUsers[name].location != undefined), click: function () { - setNotificationState(HifiNotificationType.GOTO, false); - StartInterface("hifi://" + onlineUsers[name].location.root.name + onlineUsers[name].location.path); + setNotificationState(HifiNotificationType.PEOPLE, false); + if(onlineUsers[name] && onlineUsers[name].location) { + StartInterface("hifi://" + onlineUsers[name].location.root.name + onlineUsers[name].location.path); + } } }); } } var currentStories = trayNotifications.getCurrentStories(); - if(currentStories) { + if (currentStories && currentStories.length) { labels.goto.submenu = []; for (var location in currentStories) { labels.goto.submenu.push({ diff --git a/server-console/src/modules/hf-notifications.js b/server-console/src/modules/hf-notifications.js index 85fe3ece15..2b287ba392 100644 --- a/server-console/src/modules/hf-notifications.js +++ b/server-console/src/modules/hf-notifications.js @@ -73,11 +73,17 @@ HifiNotification.prototype = { text = this.data + " of your connections are online." } message = "Click to open PEOPLE."; - url="hifiapp:PEOPLE" + url="hifiapp:PEOPLE"; } else { - text = this.data.username + " is available in " + this.data.location.root.name + "."; - message = "Click to join them."; - url="hifi://" + this.data.location.root.name + this.data.location.path; + if (this.data.location) { + text = this.data.username + " is available in " + this.data.location.root.name + "."; + message = "Click to join them."; + url="hifi://" + this.data.location.root.name + this.data.location.path; + } else { + text = this.data.username + " is online."; + message = "Click to open PEOPLE."; + url="hifiapp:PEOPLE"; + } } break; @@ -433,7 +439,6 @@ HifiNotifications.prototype = { console.log("Error: unable to get " + url); return false; } - console.log(content); if (!content.total_entries) { _this.menuNotificationCallback(NotificationType.PEOPLE, false); _this.onlineUsers = {}; @@ -445,7 +450,7 @@ HifiNotifications.prototype = { content.data.users.forEach(function (user) { currentUsers[user.username] = user; if (!(user.username in _this.onlineUsers)) { - newUsers.add(user.username); + newUsers.add(user); _this.onlineUsers[user.username] = user; } }); From af055bb45c8c7332809936868faaf86601eb7d02 Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Wed, 10 Oct 2018 16:50:07 -0700 Subject: [PATCH 5/6] more bug fixes and cleanup of some console logging --- server-console/src/main.js | 30 ++++++++++++------- .../src/modules/hf-notifications.js | 7 ++--- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/server-console/src/main.js b/server-console/src/main.js index 5c77c26270..bea6504deb 100644 --- a/server-console/src/main.js +++ b/server-console/src/main.js @@ -338,13 +338,15 @@ const HifiNotificationType = hfNotifications.NotificationType; var pendingNotifications = {} var notificationState = NotificationState.UNNOTIFIED; -function setNotificationState (notificationType, pending = true) { - pendingNotifications[notificationType] = pending; - notificationState = NotificationState.UNNOTIFIED; - for (var key in pendingNotifications) { - if (pendingNotifications[key]) { - notificationState = NotificationState.NOTIFIED; - break; +function setNotificationState (notificationType, pending = undefined) { + if (pending !== undefined) { + pendingNotifications[notificationType] = pending; + notificationState = NotificationState.UNNOTIFIED; + for (var key in pendingNotifications) { + if (pendingNotifications[key]) { + notificationState = NotificationState.NOTIFIED; + break; + } } } updateTrayMenu(homeServer ? homeServer.state : ProcessGroupStates.STOPPED); @@ -569,9 +571,12 @@ function updateLabels(serverState) { labels.wallet.icon = pendingNotifications[HifiNotificationType.WALLET] ? menuNotificationIcon : null; labels.marketplace.icon = pendingNotifications[HifiNotificationType.MARKETPLACE] ? menuNotificationIcon : null; var onlineUsers = trayNotifications.getOnlineUsers(); + delete labels.people.submenu; if (onlineUsers) { - labels.people.submenu = []; for (var name in onlineUsers) { + if(labels.people.submenu == undefined) { + labels.people.submenu = []; + } labels.people.submenu.push({ label: name, enabled: (onlineUsers[name].location != undefined), @@ -585,14 +590,17 @@ function updateLabels(serverState) { } } var currentStories = trayNotifications.getCurrentStories(); - if (currentStories && currentStories.length) { - labels.goto.submenu = []; + delete labels.goto.submenu; + if (currentStories) { for (var location in currentStories) { + if(labels.goto.submenu == undefined) { + labels.goto.submenu = []; + } labels.goto.submenu.push({ label: "event in " + location, click: function () { setNotificationState(HifiNotificationType.GOTO, false); - StartInterface("hifi://" + location + getCurrentStories[location].path); + StartInterface("hifi://" + location + currentStories[location].path); } }); } diff --git a/server-console/src/modules/hf-notifications.js b/server-console/src/modules/hf-notifications.js index 2b287ba392..b1f337bbc3 100644 --- a/server-console/src/modules/hf-notifications.js +++ b/server-console/src/modules/hf-notifications.js @@ -302,7 +302,6 @@ HifiNotifications.prototype = { finished(false); return; } - console.log(content); if (!content.total_entries) { finished(true, token); return; @@ -326,7 +325,6 @@ HifiNotifications.prototype = { notifyData = content.data.updates; break; } - notifyData.forEach(function (notifyDataEntry) { _this._addNotification(new HifiNotification(notifyType, notifyDataEntry)); }); @@ -381,13 +379,13 @@ HifiNotifications.prototype = { finished(false); return; } - console.log(content); + if (!content.total_entries) { finished(true, token); return; } if (!content.total_entries) { - this.menuNotificationCallback(NotificationType.GOTO, false); + _this.menuNotificationCallback(NotificationType.GOTO, false); } _this.currentStories = {}; content.user_stories.forEach(function (story) { @@ -397,6 +395,7 @@ HifiNotifications.prototype = { // for each story. _this.currentStories[story.place_name] = story; }); + _this.menuNotificationCallback(NotificationType.GOTO); }); } }); From 6b05f7b030c341e136fc0ba19a16e9eebd2dbce6 Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Wed, 10 Oct 2018 17:16:56 -0700 Subject: [PATCH 6/6] Clicking on a user in the goto menu was taking one to the wrong user --- server-console/src/main.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server-console/src/main.js b/server-console/src/main.js index bea6504deb..91c9c7e31b 100644 --- a/server-console/src/main.js +++ b/server-console/src/main.js @@ -580,10 +580,10 @@ function updateLabels(serverState) { labels.people.submenu.push({ label: name, enabled: (onlineUsers[name].location != undefined), - click: function () { + click: function (item) { setNotificationState(HifiNotificationType.PEOPLE, false); - if(onlineUsers[name] && onlineUsers[name].location) { - StartInterface("hifi://" + onlineUsers[name].location.root.name + onlineUsers[name].location.path); + if(onlineUsers[item.label] && onlineUsers[item.label].location) { + StartInterface("hifi://" + onlineUsers[item.label].location.root.name + onlineUsers[item.label].location.path); } } }); @@ -598,9 +598,10 @@ function updateLabels(serverState) { } labels.goto.submenu.push({ label: "event in " + location, - click: function () { + location: location, + click: function (item) { setNotificationState(HifiNotificationType.GOTO, false); - StartInterface("hifi://" + location + currentStories[location].path); + StartInterface("hifi://" + item.location + currentStories[item.location].path); } }); }