浏览代码

Notification sound now also plays when nickname is mentioned in chat room.

updates #62
JC Brand 10 年之前
父节点
当前提交
3aaa8df41a
共有 5 个文件被更改,包括 24 次插入14 次删除
  1. 18 14
      converse.js
  2. 1 0
      css/converse.css
  3. 1 0
      docs/CHANGES.rst
  4. 3 0
      docs/source/index.rst
  5. 1 0
      less/converse.less

+ 18 - 14
converse.js

@@ -32,6 +32,7 @@
         console = { log: function () {}, error: function () {} };
         console = { log: function () {}, error: function () {} };
     }
     }
 
 
+    // TODO: these non-backbone methods should all be moved to utils.
     $.fn.addHyperlinks = function() {
     $.fn.addHyperlinks = function() {
         if (this.length > 0) {
         if (this.length > 0) {
             this.each(function(i, obj) {
             this.each(function(i, obj) {
@@ -71,6 +72,19 @@
         };
         };
     };
     };
 
 
+    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();
+            }
+        }
+    };
+
     $.fn.addEmoticons = function() {
     $.fn.addEmoticons = function() {
         if (converse.visible_toolbar_buttons.emoticons) {
         if (converse.visible_toolbar_buttons.emoticons) {
             if (this.length > 0) {
             if (this.length > 0) {
@@ -2438,6 +2452,9 @@
                 }
                 }
                 if (!body) { return true; }
                 if (!body) { return true; }
                 var display_sender = sender === this.model.get('nick') && 'me' || 'room';
                 var display_sender = sender === this.model.get('nick') && 'me' || 'room';
+                if (!delayed && display_sender === 'room' && (new RegExp("\\b"+this.model.get('nick')+"\\b")).test(body)) {
+                    playNotification();
+                }
                 this.showMessage({
                 this.showMessage({
                     'message': body,
                     'message': body,
                     'sender': display_sender,
                     'sender': display_sender,
@@ -2517,19 +2534,6 @@
                 });
                 });
             },
             },
 
 
-            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();
-                    }
-                }
-            },
-
             isOnlyChatStateNotification: function ($msg) {
             isOnlyChatStateNotification: function ($msg) {
                 // See XEP-0085 Chat State Notification
                 // See XEP-0085 Chat State Notification
                 return (
                 return (
@@ -2627,7 +2631,7 @@
                     });
                     });
                 }
                 }
                 if (!this.isOnlyChatStateNotification($message) && from !== converse.bare_jid) {
                 if (!this.isOnlyChatStateNotification($message) && from !== converse.bare_jid) {
-                    this.playNotification();
+                    playNotification();
                 }
                 }
                 chatbox.receiveMessage($message);
                 chatbox.receiveMessage($message);
                 converse.roster.addResource(buddy_jid, resource);
                 converse.roster.addResource(buddy_jid, resource);

+ 1 - 0
css/converse.css

@@ -1199,6 +1199,7 @@ select#select-xmpp-status {
   border-top-left-radius: 0;
   border-top-left-radius: 0;
   border-top-right-radius: 0;
   border-top-right-radius: 0;
   width: 200px;
   width: 200px;
+  height: 84px;
 }
 }
 #conversejs .chatroom form.sendXMPPMessage {
 #conversejs .chatroom form.sendXMPPMessage {
   -webkit-border-bottom-right-radius: 0;
   -webkit-border-bottom-right-radius: 0;

+ 1 - 0
docs/CHANGES.rst

@@ -7,6 +7,7 @@ Changelog
 * Converse.js now responds to XEP-0030: Service Discovery requests. [jcbrand]
 * Converse.js now responds to XEP-0030: Service Discovery requests. [jcbrand]
 * Bugfix. Roster groups all appear offline after page reload (with prebind).
 * Bugfix. Roster groups all appear offline after page reload (with prebind).
   See http://librelist.com/browser//conversejs/2014/8/26/problem-with-contact-list-everyone-is-offline/ [heban and jcbrand]
   See http://librelist.com/browser//conversejs/2014/8/26/problem-with-contact-list-everyone-is-offline/ [heban and jcbrand]
+* #62 Sound notifications will now also play when you are mentioned in a chat room. [jcbrand]
 * #212 Bugfix. Groups weren't being show again after the live filter was cleared. [jcbrand]
 * #212 Bugfix. Groups weren't being show again after the live filter was cleared. [jcbrand]
 * #215 (and also #75) XEP-0249: Direct MUC Invitations. [jcbrand]
 * #215 (and also #75) XEP-0249: Direct MUC Invitations. [jcbrand]
 * #216 Contacts tab empty when using xhr_user_search. [hcderaad and jcbrand]
 * #216 Contacts tab empty when using xhr_user_search. [hcderaad and jcbrand]

+ 3 - 0
docs/source/index.rst

@@ -975,6 +975,9 @@ play_sounds
 
 
 Default:  ``false``
 Default:  ``false``
 
 
+Plays a notification sound when you receive a personal message or when your
+nickname is mentioned in a chat room.
+
 Inside the ``./sounds`` directory of the Converse.js repo, you'll see MP3 and Ogg
 Inside the ``./sounds`` directory of the Converse.js repo, you'll see MP3 and Ogg
 formatted sound files. We need both, because neither format is supported by all browsers.
 formatted sound files. We need both, because neither format is supported by all browsers.
 
 

+ 1 - 0
less/converse.less

@@ -1356,6 +1356,7 @@ select#select-xmpp-status {
     border-top-left-radius: 0;
     border-top-left-radius: 0;
     border-top-right-radius: 0;
     border-top-right-radius: 0;
     width: 200px;
     width: 200px;
+    height: 84px;
 }
 }
 
 
 #conversejs .chatroom form.sendXMPPMessage {
 #conversejs .chatroom form.sendXMPPMessage {