From adda6d75471569f3616823c5668d0f995cb5d629 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Sun, 5 Jan 2014 04:19:46 -0800 Subject: [PATCH] Update human-model, fix idle from sticking --- clientapp/app.js | 1 + clientapp/models/contact.js | 20 ++++++++++---------- clientapp/models/me.js | 17 ++++++++++------- clientapp/models/message.js | 20 ++++++++++---------- clientapp/models/muc.js | 10 +++++----- clientapp/models/resource.js | 12 ++++++------ clientapp/models/state.js | 18 +++++++++--------- clientapp/pages/chat.js | 2 +- package.json | 2 +- public/x-manifest.cache | 2 +- 10 files changed, 54 insertions(+), 50 deletions(-) diff --git a/clientapp/app.js b/clientapp/app.js index 884bc6c..9ba5029 100644 --- a/clientapp/app.js +++ b/clientapp/app.js @@ -45,6 +45,7 @@ module.exports = { app.storage.profiles.get(config.jid, function (err, res) { if (res) { profile = res; + profile.jid = {full: config.jid, bare: config.jid}; config.rosterVer = res.rosterVer; } cb(); diff --git a/clientapp/models/contact.js b/clientapp/models/contact.js index 705bb5b..c57786b 100644 --- a/clientapp/models/contact.js +++ b/clientapp/models/contact.js @@ -28,27 +28,27 @@ module.exports = HumanModel.define({ type: 'contact', props: { id: ['string', true, false], - avatarID: ['string', true, ''], - groups: ['array', true, []], + avatarID: ['string', false, ''], + groups: ['array', false, []], inRoster: ['bool', true, false], jid: ['string', true], - name: ['string', true, ''], + name: ['string', false, ''], owner: ['string', true, ''], storageId: ['string', true, ''], - subscription: ['string', true, 'none'] + subscription: ['string', false, 'none'] }, session: { - activeContact: ['bool', true, false], + activeContact: ['bool', false, false], avatar: 'string', avatarSource: 'string', lastInteraction: 'date', lastSentMessage: 'object', lockedResource: 'string', - offlineStatus: ['string', true, ''], + offlineStatus: ['string', false, ''], topResource: 'string', - unreadCount: ['number', true, 0], - _forceUpdate: ['number', true, 0], - onCall: ['boolean', true, false], + unreadCount: ['number', false, 0], + _forceUpdate: ['number', false, 0], + onCall: ['boolean', false, false], stream: 'object' }, derived: { @@ -147,7 +147,7 @@ module.exports = HumanModel.define({ idle: { deps: ['idleSince'], fn: function () { - return !!this.idleSince; + return this.idleSince && !isNaN(this.idleSince.valueOf()); } }, chatState: { diff --git a/clientapp/models/me.js b/clientapp/models/me.js index f068806..8b4aa51 100644 --- a/clientapp/models/me.js +++ b/clientapp/models/me.js @@ -37,11 +37,11 @@ module.exports = HumanModel.define({ nick: 'string' }, session: { - avatar: ['string', true, ''], - connected: ['bool', true, false], - shouldAskForAlertsPermission: ['bool', true, false], - hasFocus: ['bool', true, false], - _activeContact: ['string', true, ''], + avatar: 'string', + connected: ['bool', false, false], + shouldAskForAlertsPermission: ['bool', false, false], + hasFocus: ['bool', false, false], + _activeContact: 'string', stream: 'object' }, collections: { @@ -74,8 +74,8 @@ module.exports = HumanModel.define({ if (curr) { curr.activeContact = true; curr.unreadCount = 0; + this._activeContact = curr.id; } - this._activeContact = jid; }, setAvatar: function (id, type, source) { var self = this; @@ -91,6 +91,9 @@ module.exports = HumanModel.define({ if (this.isMe(jid)) { jid = alt || jid; } + + if (!jid) return; + return this.contacts.get(jid.bare) || this.mucs.get(jid.bare) || this.calls.findWhere('jid', jid); @@ -142,7 +145,7 @@ module.exports = HumanModel.define({ }); }, isMe: function (jid) { - return jid.bare === this.jid.bare; + return jid && (jid.bare === this.jid.bare); }, updateIdlePresence: function () { var update = { diff --git a/clientapp/models/message.js b/clientapp/models/message.js index c057c03..b9bc1eb 100644 --- a/clientapp/models/message.js +++ b/clientapp/models/message.js @@ -15,17 +15,17 @@ var Message = module.exports = HumanModel.define({ }, type: 'message', props: { - mid: ['string', true], + mid: 'string', owner: 'string', - to: ['object', true], - from: ['object', true], - body: ['string', true, ''], - type: ['string', true, 'normal'], - acked: ['bool', true, false], - requestReceipt: ['boo', true, false], - receipt: ['bool', true, false], - archivedId: ['string', true, ''], - oobURIs: ['array', false, []] + to: 'object', + from: 'object', + body: 'string', + type: ['string', false, 'normal'], + acked: ['bool', false, false], + requestReceipt: ['bool', false, false], + receipt: ['bool', false, false], + archivedId: 'string', + oobURIs: 'array' }, derived: { mine: { diff --git a/clientapp/models/muc.js b/clientapp/models/muc.js index ee7a9a5..0547bac 100644 --- a/clientapp/models/muc.js +++ b/clientapp/models/muc.js @@ -19,18 +19,18 @@ module.exports = HumanModel.define({ }, type: 'muc', props: { - id: ['string', true, false], + id: ['string', true], name: 'string', - autoJoin: ['bool', true, false], + autoJoin: ['bool', false, false], nick: 'string', jid: 'object' }, session: { subject: 'string', - activeContact: ['bool', true, false], - lastInteraction: 'data', + activeContact: ['bool', false, false], + lastInteraction: 'date', lastSentMessage: 'object', - unreadCount: ['number', true, 0], + unreadCount: ['number', false, 0], joined: ['bool', true, false] }, derived: { diff --git a/clientapp/models/resource.js b/clientapp/models/resource.js index e58349e..ebfe9f9 100644 --- a/clientapp/models/resource.js +++ b/clientapp/models/resource.js @@ -9,11 +9,11 @@ module.exports = HumanModel.define({ type: 'resource', session: { id: ['string', true], - status: ['string', true, ''], - show: ['string', true, ''], - priority: ['number', true, 0], - chatState: ['string', true, 'gone'], - idleSince: ['date', false, undefined], + status: 'string', + show: 'string', + priority: ['number', false, 0], + chatState: ['string', false, 'gone'], + idleSince: 'date', discoInfo: 'object', timezoneOffset: 'number' }, @@ -27,7 +27,7 @@ module.exports = HumanModel.define({ idle: { deps: ['idleSince'], fn: function () { - return !!this.idleSince; + return this.idleSince && !isNaN(this.idleSince.valueOf()); } }, supportsReceipts: { diff --git a/clientapp/models/state.js b/clientapp/models/state.js index 1c9645a..fbb4e2b 100644 --- a/clientapp/models/state.js +++ b/clientapp/models/state.js @@ -26,16 +26,16 @@ module.exports = HumanModel.define({ this.markActive(); }, session: { - focused: ['bool', true, true], - active: ['bool', true, false], - connected: ['bool', true, false], - hasConnected: ['bool', true, false], - idleTimeout: ['number', true, 600000], + focused: ['bool', false, true], + active: ['bool', false, false], + connected: ['bool', false, false], + hasConnected: ['bool', false, false], + idleTimeout: ['number', false, 600000], idleSince: 'date', - allowAlerts: ['bool', true, false], - badge: ['string', true, ''], - pageTitle: ['string', true, ''], - hasActiveCall: ['boolean', true, false] + allowAlerts: ['bool', false, false], + badge: 'string', + pageTitle: 'string', + hasActiveCall: ['boolean', false, false] }, derived: { title: { diff --git a/clientapp/pages/chat.js b/clientapp/pages/chat.js index 7cd075e..2ec88f4 100644 --- a/clientapp/pages/chat.js +++ b/clientapp/pages/chat.js @@ -159,7 +159,7 @@ module.exports = BasePage.extend({ }); message = { - to: this.model.lockedResource || this.model.jid, + to: client.JID(this.model.lockedResource || this.model.jid), type: 'chat', body: val, requestReceipt: true, diff --git a/package.json b/package.json index 7ddb8a3..5b4ca17 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "getconfig": "0.0.5", "getusermedia": "0.2.1", "helmet": "0.1.0", - "human-model": "1.4.0", + "human-model": "2.6.0", "human-view": "1.2.0", "jade": "0.35.0", "moonboots": "1.0.0", diff --git a/public/x-manifest.cache b/public/x-manifest.cache index aab4f10..5df6f40 100644 --- a/public/x-manifest.cache +++ b/public/x-manifest.cache @@ -1,5 +1,5 @@ CACHE MANIFEST -# 0.0.3 1388920243107 +# 0.0.3 1388923898053 CACHE: /app.js