Commit c66c7c3f authored by JC Brand's avatar JC Brand

Merge branch 'master' of https://github.com/witekdev/converse.js into witekdev-master

Conflicts:
	spec/MainSpec.js
parents be9cd599 b84d4519
...@@ -335,7 +335,7 @@ ...@@ -335,7 +335,7 @@
'extra_classes': message.get('delayed') && 'delayed' || '' 'extra_classes': message.get('delayed') && 'delayed' || ''
})); }));
} }
if (message.get('sender') != 'me') { if ((message.get('sender') != 'me') && (converse.windowState == 'blur')) {
converse.incrementMsgCounter(); converse.incrementMsgCounter();
} }
this.scrollDown(); this.scrollDown();
...@@ -480,7 +480,6 @@ ...@@ -480,7 +480,6 @@
if (this.model.get('status')) { if (this.model.get('status')) {
this.showStatusMessage(this.model.get('status')); this.showStatusMessage(this.model.get('status'));
} }
converse.clearMsgCounter();
}, },
template: _.template( template: _.template(
...@@ -956,7 +955,6 @@ ...@@ -956,7 +955,6 @@
this); this);
this.$el.appendTo(converse.chatboxesview.$el); this.$el.appendTo(converse.chatboxesview.$el);
this.render().show().model.messages.fetch({add: true}); this.render().show().model.messages.fetch({add: true});
converse.clearMsgCounter();
}, },
onLeave: function () { onLeave: function () {
...@@ -2121,6 +2119,14 @@ ...@@ -2121,6 +2119,14 @@
this.xmppstatus.initStatus(); this.xmppstatus.initStatus();
}, this)); }, this));
$(window).on("blur focus", $.proxy(function(e) {
if ((this.windowState != e.type) && (e.type == 'focus')) {
converse.clearMsgCounter();
}
this.windowState = e.type;
},this))
this.giveFeedback('Online Contacts'); this.giveFeedback('Online Contacts');
}; };
......
...@@ -136,11 +136,9 @@ ...@@ -136,11 +136,9 @@
}); });
}, converse)); }, converse));
}, converse)); }, converse));
}, converse)); }, converse));
describe("The Contacts Roster", $.proxy(function () { describe("The Contacts Roster", $.proxy(function () {
describe("Pending Contacts", $.proxy(function () { describe("Pending Contacts", $.proxy(function () {
it("do not have a heading if there aren't any", $.proxy(function () { it("do not have a heading if there aren't any", $.proxy(function () {
expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none'); expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none');
...@@ -369,7 +367,6 @@ ...@@ -369,7 +367,6 @@
}, converse)); }, converse));
describe("All Contacts", $.proxy(function () { describe("All Contacts", $.proxy(function () {
it("are saved to, and can be retrieved from, localStorage", $.proxy(function () { it("are saved to, and can be retrieved from, localStorage", $.proxy(function () {
var new_attrs, old_attrs, attrs, old_roster; var new_attrs, old_attrs, attrs, old_roster;
// One contact was declined, so we have 1 less contact then originally // One contact was declined, so we have 1 less contact then originally
...@@ -555,6 +552,50 @@ ...@@ -555,6 +552,50 @@
}, converse)); }, converse));
}, converse)); }, converse));
describe("A Message Counter", $.proxy(function () {
it("is incremented when the message is received and the window is not focused", $.proxy(function () {
expect(this.msg_counter).toBe(0);
spyOn(converse, 'incrementMsgCounter').andCallThrough();
$(window).trigger('blur');
var message = 'This message will increment the message counter';
var sender_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
msg = $msg({
from: sender_jid,
to: this.connection.jid,
type: 'chat',
id: (new Date()).getTime()
}).c('body').t(message).up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
this.chatboxes.messageReceived(msg);
expect(converse.incrementMsgCounter).toHaveBeenCalled();
expect(this.msg_counter).toBe(1);
}, converse));
it("is cleared when the window is focused", $.proxy(function () {
spyOn(converse, 'clearMsgCounter').andCallThrough();
$(window).trigger('focus');
expect(converse.clearMsgCounter).toHaveBeenCalled();
}, converse));
it("is not incremented when the message is received and the window is focused", $.proxy(function () {
expect(this.msg_counter).toBe(0);
spyOn(converse, 'incrementMsgCounter').andCallThrough();
$(window).trigger('focus');
var message = 'This message will not increment the message counter';
var sender_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
msg = $msg({
from: sender_jid,
to: this.connection.jid,
type: 'chat',
id: (new Date()).getTime()
}).c('body').t(message).up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
this.chatboxes.messageReceived(msg);
expect(converse.incrementMsgCounter).not.toHaveBeenCalled();
expect(this.msg_counter).toBe(0);
}, converse));
}, converse));
describe("The Controlbox Tabs", $.proxy(function () { describe("The Controlbox Tabs", $.proxy(function () {
beforeEach($.proxy(function () { beforeEach($.proxy(function () {
// Close any remaining open chatboxes // Close any remaining open chatboxes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment