From b089fd03b8ba9d3c0dba1cd13daf5cae2ffa61fc Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Thu, 6 Apr 2017 16:48:11 -0700 Subject: [PATCH 1/2] make connection messaging when not logged in --- scripts/system/makeUserConnection.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/system/makeUserConnection.js b/scripts/system/makeUserConnection.js index 0a781a5bb8..674da2d677 100644 --- a/scripts/system/makeUserConnection.js +++ b/scripts/system/makeUserConnection.js @@ -131,7 +131,6 @@ function request(options, callback) { // cb(error, responseOfCorrectContentType) var error = (httpRequest.status !== HTTP_OK) && httpRequest.status.toString() + ':' + httpRequest.statusText, response = !error && httpRequest.responseText, contentType = !error && httpRequest.getResponseHeader('content-type'); - debug('FIXME REMOVE: server response', options, error, response, contentType); if (!error && contentType.indexOf('application/json') === 0) { // ignoring charset, etc. try { response = JSON.parse(response); @@ -139,6 +138,9 @@ function request(options, callback) { // cb(error, responseOfCorrectContentType) error = e; } } + if (error) { + response = {statusCode: httpRequest.status}; + } callback(error, response); } }; @@ -164,7 +166,6 @@ function request(options, callback) { // cb(error, responseOfCorrectContentType) options.headers["Content-type"] = "application/json"; options.body = JSON.stringify(options.body); } - debug("FIXME REMOVE: final options to send", options); for (key in options.headers || {}) { httpRequest.setRequestHeader(key, options.headers[key]); } @@ -574,6 +575,9 @@ function handleConnectionResponseAndMaybeRepeat(error, response) { } } else if (error || (response.status !== 'success')) { debug('server fail', error, response.status); + if (response && (response.statusCode === 401)) { + error = "All participants must be logged in to connect."; + } result = error ? {status: 'error', connection: error} : response; UserActivityLogger.makeUserConnection(connectingId, false, error || response); connectionRequestCompleted(); @@ -603,6 +607,15 @@ function makeConnection(id) { // probably, in which we do this. Controller.triggerHapticPulse(HAPTIC_DATA.background.strength, MAKING_CONNECTION_TIMEOUT, handToHaptic(currentHand)); requestBody = {node_id: cleanId(MyAvatar.sessionUUID), proposed_node_id: cleanId(id)}; // for use when repeating + + // It would be "simpler" to skip this and just look at the response, but: + // 1. We don't want to bother the metaverse with request that we know will fail. + // 2. We don't want our code here to be dependent on precisely how the metaverse responds (400, 401, etc.) + if (!Account.isLoggedIn()) { + handleConnectionResponseAndMaybeRepeat("401:Unauthorized", {statusCode: 401}); + return; + } + // This will immediately set response if successfull (e.g., the other guy got his request in first), or immediate failure, // and will otherwise poll (using the requestBody we just set). request({ // From 5d341778c5d558949a5c88905645dca2a9526483 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Fri, 7 Apr 2017 07:08:19 -0700 Subject: [PATCH 2/2] fix notification word wrapping --- scripts/system/notifications.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/scripts/system/notifications.js b/scripts/system/notifications.js index 3989e8e372..25a5edf3a3 100644 --- a/scripts/system/notifications.js +++ b/scripts/system/notifications.js @@ -427,21 +427,24 @@ function deleteNotification(index) { arrays.splice(index, 1); } -// wraps whole word to newline -function stringDivider(str, slotWidth, spaceReplacer) { - var left, right; - if (str.length > slotWidth && slotWidth > 0) { - left = str.substring(0, slotWidth); - right = str.substring(slotWidth); - return left + spaceReplacer + stringDivider(right, slotWidth, spaceReplacer); +// Trims extra whitespace and breaks into lines of length no more than MAX_LENGTH, breaking at spaces. Trims extra whitespace. +var MAX_LENGTH = 42; +function wordWrap(string) { + var finishedLines = [], currentLine = ''; + string.split(/\s/).forEach(function (word) { + var tail = currentLine ? ' ' + word : word; + if ((currentLine.length + tail.length) <= MAX_LENGTH) { + currentLine += tail; + } else { + finishedLines.push(currentLine); + currentLine = word; + } + }); + if (currentLine) { + finishedLines.push(currentLine); } - return str; -} - -// formats string to add newline every 43 chars -function wordWrap(str) { - return stringDivider(str, 43.0, "\n"); + return finishedLines.join('\n'); } function update() {