From 9b117165bd21d7a3ff21c47fa5190ab4dcd2590d Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Tue, 2 May 2017 11:44:16 -0700 Subject: [PATCH] expire our announcements when we leave, and turn off messagesWaiting when everything is expired. --- scripts/system/tablet-goto.js | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/scripts/system/tablet-goto.js b/scripts/system/tablet-goto.js index fec7a6de90..b9ca6f7407 100644 --- a/scripts/system/tablet-goto.js +++ b/scripts/system/tablet-goto.js @@ -143,9 +143,22 @@ button.clicked.connect(onClicked); tablet.screenChanged.connect(onScreenChanged); - var stories = {}; - var DEBUG = false; + var stories = {}, pingPong = false; + var DEBUG = true; //fixme + function expire(id) { + request({ + uri: location.metaverseServerUrl + '/api/v1/user_stories/' + id, + method: 'PUT', + body: {expired: true} + }, function (error, response) { + if (error || (response.status !== 'success')) { + print("ERROR expiring story: ", error || response.status); + return; + } + }); + } function pollForAnnouncements() { + // We could bail now if !Account.isLoggedIn(), but what if we someday have system-wide announcments? var actions = DEBUG ? 'snapshot' : 'announcement'; var count = DEBUG ? 10 : 100; var options = [ @@ -164,9 +177,16 @@ print("Error: unable to get", url, error || data.status); return; } - var didNotify = false; + var didNotify = false, key; + pingPong = !pingPong; data.user_stories.forEach(function (story) { - if (stories[story.id]) { // already seen + var stored = stories[story.id], storedOrNew = stored || story; + if ((storedOrNew.username === Account.username) && (storyOrNew.place_name !== location.placename)) { + expire(story.id); + return; // before marking + } + storedOrNew.pingPong = pingPong; + if (stored) { // already seen return; } stories[story.id] = story; @@ -174,12 +194,19 @@ Window.displayAnnouncement(message); didNotify = true; }); + for (key in stories) { // Any story we were tracking that was not marked, has expired. + if (stories[key].pingPong !== pingPong) { + delete stories[key]; + } + } if (didNotify) { messagesWaiting(true); if (HMD.isHandControllerAvailable()) { var STRENGTH = 1.0, DURATION_MS = 60, HAND = 2; // both hands Controller.triggerHapticPulse(STRENGTH, DURATION_MS, HAND); } + } else if (!Object.keys(stories).length) { // If there's nothing being tracked, then any messageWaiting has expired. + messagesWaiting(false); } }); }