Commit d0b8a387 authored by JC Brand's avatar JC Brand

Add a test to check that notifications are properly sent in chat rooms.

parent 77137a53
......@@ -125,19 +125,6 @@
return this;
};
var playNotification = function () {
var audio;
if (converse.play_sounds && typeof Audio !== "undefined"){
audio = new Audio("sounds/msg_received.ogg");
if (audio.canPlayType('/audio/ogg')) {
audio.play();
} else {
audio = new Audio("/sounds/msg_received.mp3");
audio.play();
}
}
};
var converse = {
plugins: {},
templates: templates,
......@@ -359,6 +346,19 @@
// Module-level functions
// ----------------------
this.playNotification = function () {
var audio;
if (converse.play_sounds && typeof Audio !== "undefined"){
audio = new Audio("sounds/msg_received.ogg");
if (audio.canPlayType('/audio/ogg')) {
audio.play();
} else {
audio = new Audio("/sounds/msg_received.mp3");
audio.play();
}
}
};
this.giveFeedback = function (message, klass) {
$('.conn-feedback').each(function (idx, el) {
var $el = $(el);
......@@ -2972,7 +2972,7 @@
}
this.model.createMessage($message);
if (!delayed && sender !== this.model.get('nick') && (new RegExp("\\b"+this.model.get('nick')+"\\b")).test(body)) {
playNotification();
converse.playNotification();
}
if (sender !== this.model.get('nick')) {
// We only emit an event if it's not our own message
......@@ -3142,7 +3142,7 @@
return true; // We already have this message stored.
}
if (!this.isOnlyChatStateNotification($message) && from !== converse.bare_jid) {
playNotification();
converse.playNotification();
}
chatbox.receiveMessage($message);
converse.roster.addResource(contact_jid, resource);
......
......@@ -7,6 +7,7 @@ Changelog
* Set the JID input field in the login form to ``type=email``. [chatme]
* New configuration setting ``allow_contact_removal``. [jcbrand]
* Document that event handlers receive 'event' obj as first arg. [jcbrand]
* Add a test to check that notifications are played in chat rooms. [jcbrand]
0.9.0 (2015-03-06)
------------------
......
......@@ -176,6 +176,47 @@
expect(converse.emit).toHaveBeenCalledWith('message', message.nodeTree);
}, converse));
it("plays a sound when the current user is mentioned (if configured)", $.proxy(function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy');
spyOn(converse, 'emit');
converse.play_sounds = true;
spyOn(converse, 'playNotification');
var view = this.chatboxviews.get('lounge@localhost');
if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
var nick = mock.chatroom_names[0];
var text = 'This message will play a sound because it mentions dummy';
var message = $msg({
from: 'lounge@localhost/otheruser',
id: '1',
to: 'dummy@localhost',
type: 'groupchat'
}).c('body').t(text);
view.onChatRoomMessage(message.nodeTree);
expect(converse.playNotification).toHaveBeenCalled();
text = "This message won't play a sound";
message = $msg({
from: 'lounge@localhost/otheruser',
id: '2',
to: 'dummy@localhost',
type: 'groupchat'
}).c('body').t(text);
view.onChatRoomMessage(message.nodeTree);
expect(converse.playNotification, 1);
converse.play_sounds = false;
text = "This message won't play a sound because it is sent by dummy";
message = $msg({
from: 'lounge@localhost/dummy',
id: '3',
to: 'dummy@localhost',
type: 'groupchat'
}).c('body').t(text);
view.onChatRoomMessage(message.nodeTree);
expect(converse.playNotification, 1);
converse.play_sounds = false;
}, converse));
it("shows sent groupchat messages", $.proxy(function () {
test_utils.openChatRoom('lounge', 'localhost', 'dummy');
spyOn(converse, 'emit');
......
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