From 9449a00dda19f0b0c773aa982427944226d7a947 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 13 Sep 2013 13:55:46 -0700 Subject: [PATCH] Fix roster and timezone info --- clientapp/helpers/xmppEventHandlers.js | 4 +- clientapp/libraries/stanza.io.js | 39 ++++++------- clientapp/models/contact.js | 77 +++++++++----------------- clientapp/pages/main.js | 5 ++ clientapp/templates.js | 4 +- clientapp/templates/body.jade | 6 +- clientapp/templates/pages/main.jade | 5 +- package.json | 2 +- public/style.css | 14 ++++- 9 files changed, 72 insertions(+), 84 deletions(-) diff --git a/clientapp/helpers/xmppEventHandlers.js b/clientapp/helpers/xmppEventHandlers.js index 0655474..c295b3d 100644 --- a/clientapp/helpers/xmppEventHandlers.js +++ b/clientapp/helpers/xmppEventHandlers.js @@ -230,8 +230,8 @@ module.exports = function (client, app) { contact.addMessage(message, true); if (!contact.lockedResource) { - contact.lockedResource = contact.resources.get(msg.from.full); - } else if (msg.from.full !== contact.lockedResource.id) { + contact.lockedResource = msg.from.full; + } else if (msg.from.full !== contact.lockedResource) { contact.lockedResource = undefined; } } diff --git a/clientapp/libraries/stanza.io.js b/clientapp/libraries/stanza.io.js index 008ea47..3403442 100644 --- a/clientapp/libraries/stanza.io.js +++ b/clientapp/libraries/stanza.io.js @@ -4689,7 +4689,7 @@ EntityTime.prototype = { } if (formatted.charAt(0) === '-') { sign = 1; - formatted.slice(1); + formatted = formatted.slice(1); } split = formatted.split(':'); hrs = parseInt(split[0], 10); @@ -4979,31 +4979,24 @@ WSConnection.prototype.connect = function (opts) { self.parser = new DOMParser(); self.serializer = new XMLSerializer(); - try { - self.conn = new WebSocket(opts.wsURL, 'xmpp'); - self.conn.onerror = function (e) { - e.preventDefault(); - console.log(e); - self.emit('disconnected', self); - return false; - }; + self.conn = new WebSocket(opts.wsURL, 'xmpp'); + self.conn.onerror = function (e) { + e.preventDefault(); + self.emit('disconnected', self); + return false; + }; - self.conn.onclose = function () { - self.emit('disconnected', self); - }; + self.conn.onclose = function () { + self.emit('disconnected', self); + }; - self.conn.onopen = function () { - self.emit('connected', self); - }; + self.conn.onopen = function () { + self.emit('connected', self); + }; - self.conn.onmessage = function (wsMsg) { - self.emit('raw:incoming', wsMsg.data); - }; - } catch (e) { - console.log('Caught exception'); - return self.emit('disconnected', self); - - } + self.conn.onmessage = function (wsMsg) { + self.emit('raw:incoming', wsMsg.data); + }; }; WSConnection.prototype.disconnect = function () { diff --git a/clientapp/models/contact.js b/clientapp/models/contact.js index 0181692..152ba86 100644 --- a/clientapp/models/contact.js +++ b/clientapp/models/contact.js @@ -36,11 +36,15 @@ module.exports = HumanModel.define({ activeContact: ['bool', true, false], avatar: 'string', chatState: ['string', true, 'gone'], + idleSince: 'string', lastInteraction: 'date', lastSentMessage: 'object', - lockedResource: 'object', + lockedResource: 'string', offlineStatus: ['string', true, ''], - topResource: 'object', + show: ['string', true, 'offline'], + status: ['string', true, ''], + timezoneOffset: 'number', + topResource: 'string', unreadCount: ['number', true, 0] }, derived: { @@ -50,58 +54,12 @@ module.exports = HumanModel.define({ return this.name || this.jid; } }, - status: { - deps: ['topResource', 'lockedResource', 'offlineStatus'], - fn: function () { - if (this.lockedResource) { - return this.lockedResource.status; - } - if (this.topResource) { - return this.topResource.status; - } - return this.offlineStatus; - } - }, - show: { - deps: ['topResource', 'lockedResource'], - fn: function () { - if (this.lockedResource) { - return this.lockedResource.show || 'online'; - } - if (this.topResource) { - return this.topResource.show || 'online'; - } - return 'offline'; - } - }, - idleSince: { - deps: ['topResource', 'lockedResource'], - fn: function () { - if (this.lockedResource) { - return this.lockedResource.idleSince; - } - if (this.topResource) { - return this.topResource.idleSince; - } - } - }, - timezoneOffset: { - deps: ['topResource', 'lockedResource'], - fn: function () { - if (this.lockedResource) { - return this.lockedResource.timezoneOffset; - } - if (this.topResource) { - return this.topResource.timezoneOffset; - } - } - }, formattedTZO: { deps: ['timezoneOffset', 'displayName'], fn: function () { if (this.timezoneOffset !== undefined) { var localTZO = (new Date()).getTimezoneOffset(); - var diff = Math.abs(localTZO - this.timezoneOffset) / 60; + var diff = Math.abs(localTZO % (24 * 60) - this.timezoneOffset % (24 * 60)) / 60; if (diff === 0) { return this.displayName + ' is in the same timezone as you'; } @@ -163,6 +121,15 @@ module.exports = HumanModel.define({ } }); }, + onLockedResourceChange: function () { + var res = this.resources.get(this.lockedResource); + if (res) { + this.status = res.status; + this.show = res.show || 'online'; + this.timezoneOffset = res.timezoneOffset; + this.idleSince = res.idleSince; + } + }, onResourceChange: function () { // Manually propagate change events for properties that // depend on the resources collection. @@ -171,10 +138,20 @@ module.exports = HumanModel.define({ var res = this.resources.first(); if (res) { this.offlineStatus = ''; - this.topResource = res; + this.topResource = res.id; + if (!this.lockedResource) { + this.status = res.status; + this.show = res.show || 'online'; + this.timezoneOffset = res.timezoneOffset; + this.idleSince = res.idleSince; + } } else { this.topResource = undefined; this.chatState = 'gone'; + this.status = this.offlineStatus; + this.show = 'offline'; + this.timezoneOffset = undefined; + this.idleSince = undefined; } this.lockedResource = undefined; diff --git a/clientapp/pages/main.js b/clientapp/pages/main.js index 7c7e2d1..0dac7ff 100644 --- a/clientapp/pages/main.js +++ b/clientapp/pages/main.js @@ -27,5 +27,10 @@ module.exports = BasePage.extend({ }); } }); + }, + render: function () { + this.renderAndBind(); + + return this; } }); diff --git a/clientapp/templates.js b/clientapp/templates.js index 0c1e617..c3c4f20 100644 --- a/clientapp/templates.js +++ b/clientapp/templates.js @@ -13,7 +13,7 @@ exports.pages = {}; exports.body = function anonymous(locals) { var buf = []; with (locals || {}) { - buf.push('

'); + buf.push('

'); } return buf.join(""); }; @@ -99,7 +99,7 @@ exports.pages.chat = function anonymous(locals) { exports.pages.main = function anonymous(locals) { var buf = []; with (locals || {}) { - buf.push('

This space intentionally blank

'); + buf.push('

Notifications

    '); } return buf.join(""); }; diff --git a/clientapp/templates/body.jade b/clientapp/templates/body.jade index 397c9a5..ba2a65e 100644 --- a/clientapp/templates/body.jade +++ b/clientapp/templates/body.jade @@ -1,9 +1,9 @@ body .wrap - aside#connectionStatus - button.reconnect Reconnect - span.message disconnected #connectionOverlay + aside#connectionStatus + button.reconnect Reconnect + span.message disconnected header#me img.avatar p.status diff --git a/clientapp/templates/pages/main.jade b/clientapp/templates/pages/main.jade index f4ebb04..cb01d82 100644 --- a/clientapp/templates/pages/main.jade +++ b/clientapp/templates/pages/main.jade @@ -1,3 +1,6 @@ section.page.main - h1 This space intentionally blank button.enableAlerts Enable alerts + + section.notifications + h1 Notifications + ul diff --git a/package.json b/package.json index 484a803..79f2fdd 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "node-uuid": "1.4.1", "semi-static": "0.0.4", "sound-effect-manager": "0.0.5", - "human-model": "1.1.2", + "human-model": "1.1.3", "human-view": "1.1.2", "templatizer": "0.1.2", "underscore": "1.5.1" diff --git a/public/style.css b/public/style.css index 05ffaf2..205a08c 100644 --- a/public/style.css +++ b/public/style.css @@ -197,7 +197,7 @@ nav.main a { overflow-x: hidden; position: relative; margin-top: 50px; - padding-top: 30px; + padding-top: 50px; bottom: 50px; } @@ -372,7 +372,7 @@ nav.main a { border: 1px solid #a7d9eb; outline: 0px; } -#loginbox button, .andyetLogin { +button, .andyetLogin { text-decoration: none; text-align: center; border-radius: 3px; @@ -401,3 +401,13 @@ nav.main a { #logo { margin: auto; } + +.enableAlerts { + display: none; +} +.enableAlerts.shouldAskForAlertsPermission { + display: block; + font-size: 12px; + height: 20px; + line-height: 20px; +}