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

Conflicts:
	spec/MainSpec.js
This commit is contained in:
JC Brand 2013-05-08 18:01:03 +02:00
commit c66c7c3f26
2 changed files with 53 additions and 6 deletions

View File

@ -335,7 +335,7 @@
'extra_classes': message.get('delayed') && 'delayed' || ''
}));
}
if (message.get('sender') != 'me') {
if ((message.get('sender') != 'me') && (converse.windowState == 'blur')) {
converse.incrementMsgCounter();
}
this.scrollDown();
@ -480,7 +480,6 @@
if (this.model.get('status')) {
this.showStatusMessage(this.model.get('status'));
}
converse.clearMsgCounter();
},
template: _.template(
@ -956,7 +955,6 @@
this);
this.$el.appendTo(converse.chatboxesview.$el);
this.render().show().model.messages.fetch({add: true});
converse.clearMsgCounter();
},
onLeave: function () {
@ -2121,6 +2119,14 @@
this.xmppstatus.initStatus();
}, 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');
};

View File

@ -136,11 +136,9 @@
});
}, converse));
}, converse));
}, converse));
describe("The Contacts Roster", $.proxy(function () {
describe("Pending Contacts", $.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');
@ -369,7 +367,6 @@
}, converse));
describe("All Contacts", $.proxy(function () {
it("are saved to, and can be retrieved from, localStorage", $.proxy(function () {
var new_attrs, old_attrs, attrs, old_roster;
// One contact was declined, so we have 1 less contact then originally
@ -555,6 +552,50 @@
}, 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 () {
beforeEach($.proxy(function () {
// Close any remaining open chatboxes