From b2cadbe36af0e7b6c3f238357f33bc43676ff6f8 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 16 Jan 2015 15:24:26 -0800 Subject: [PATCH] Stop notifications of all users at startup --- examples/notifications.js | 43 ++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/examples/notifications.js b/examples/notifications.js index 5527fc35fc..9a6fbbce29 100644 --- a/examples/notifications.js +++ b/examples/notifications.js @@ -259,14 +259,16 @@ function checkSize(){ // Triggers notification if a user logs on or off function onOnlineUsersChanged(users) { - for (user in users) { - if (last_users.indexOf(users[user]) == -1.0) { - createNotification(users[user] + " has joined"); + if (!isStartingUp()) { // Skip user notifications at startup. + for (user in users) { + if (last_users.indexOf(users[user]) == -1.0) { + createNotification(users[user] + " has joined"); + } } - } - for (user in last_users) { - if (users.indexOf(last_users[user]) == -1.0) { - createNotification(last_users[user] + " has left"); + for (user in last_users) { + if (users.indexOf(last_users[user]) == -1.0) { + createNotification(last_users[user] + " has left"); + } } } last_users = users; @@ -348,17 +350,38 @@ function dismiss(firstNoteOut, firstButOut, firstOut) { myAlpha.splice(firstOut,1); } -// This is meant to show users online at startup but currently shows 0 users. -function onConnected() { +// This reports the number of users online at startup +function reportUsers() { var numUsers = GlobalServices.onlineUsers.length; var welcome = "Welcome! There are " + numUsers + " users online now."; createNotification(welcome); } +var STARTUP_TIMEOUT = 500, // ms + startingUp = true, + startupTimer = null; + +function finishStartup() { + startingUp = false; + Script.clearTimeout(startupTimer); + reportUsers(); +} + +function isStartingUp() { + // Is starting up until get no checks that it is starting up for STARTUP_TIMEOUT + if (startingUp) { + if (startupTimer) { + Script.clearTimeout(startupTimer); + } + startupTimer = Script.setTimeout(finishStartup, STARTUP_TIMEOUT); + } + return startingUp; +} + + AudioDevice.muteToggled.connect(onMuteStateChanged); Controller.keyPressEvent.connect(keyPressEvent); Controller.mousePressEvent.connect(mousePressEvent); -GlobalServices.connected.connect(onConnected); GlobalServices.onlineUsersChanged.connect(onOnlineUsersChanged); GlobalServices.incomingMessage.connect(onIncomingMessage); Controller.keyReleaseEvent.connect(keyReleaseEvent);