From 79b11296f170bbcb1a435388a9838b857f8d0202 Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Wed, 3 Oct 2018 13:45:39 -0700 Subject: [PATCH] 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;