From 4a0cb1019742e7e8db5778ad240893935e59e621 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Sat, 14 Sep 2013 02:12:57 -0700 Subject: [PATCH] Make notifications smarter with page focus test --- clientapp/app.js | 8 ++++++++ clientapp/models/contact.js | 2 +- clientapp/models/me.js | 4 ++++ public/style.css | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clientapp/app.js b/clientapp/app.js index cae061a..6226e77 100644 --- a/clientapp/app.js +++ b/clientapp/app.js @@ -24,6 +24,14 @@ module.exports = { window.location = '/login'; } + app.hasFocus = false; + $(window).blur(function () { + me.hasFocus = false; + }); + $(window).focus(function () { + me.hasFocus = true; + }); + config = JSON.parse(config); _.extend(this, Backbone.Events); diff --git a/clientapp/models/contact.js b/clientapp/models/contact.js index e457841..d479e33 100644 --- a/clientapp/models/contact.js +++ b/clientapp/models/contact.js @@ -159,7 +159,7 @@ module.exports = HumanModel.define({ addMessage: function (message, notify) { message.owner = me.jid.bare; - if (notify && !this.activeContact && message.from.bare === this.jid) { + if (notify && (!this.activeContact || (this.activeContact && !app.hasFocus)) && message.from.bare === this.jid) { this.unreadCount++; app.notifier.show({ title: this.displayName, diff --git a/clientapp/models/me.js b/clientapp/models/me.js index cc19709..6dcdf38 100644 --- a/clientapp/models/me.js +++ b/clientapp/models/me.js @@ -10,6 +10,9 @@ var uuid = require('node-uuid'); module.exports = HumanModel.define({ initialize: function () { this.bind('change:jid', this.loadContacts, this); + this.bind('change:hasFocus', function () { + this.setActiveContact(this._activeContact); + }, this); }, session: { jid: ['object', true], @@ -17,6 +20,7 @@ module.exports = HumanModel.define({ avatar: ['string', true, ''], connected: ['bool', true, false], shouldAskForAlertsPermission: ['bool', true, false], + hasFocus: ['bool', true, false], _activeContact: ['string', true, ''] }, collections: { diff --git a/public/style.css b/public/style.css index e5a5066..30dcf21 100644 --- a/public/style.css +++ b/public/style.css @@ -303,7 +303,7 @@ nav.main a { #chatInput { position: fixed; bottom: 0px; - left: 176px; + left: 156px; right: 0px; z-index: 100; background: #ecf0f2;