소스 검색

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 () {} };
     }
 
+    // TODO: these non-backbone methods should all be moved to utils.
     $.fn.addHyperlinks = function() {
         if (this.length > 0) {
             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() {
         if (converse.visible_toolbar_buttons.emoticons) {
             if (this.length > 0) {
@@ -2438,6 +2452,9 @@
                 }
                 if (!body) { return true; }
                 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({
                     'message': body,
                     '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) {
                 // See XEP-0085 Chat State Notification
                 return (
@@ -2627,7 +2631,7 @@
                     });
                 }
                 if (!this.isOnlyChatStateNotification($message) && from !== converse.bare_jid) {
-                    this.playNotification();
+                    playNotification();
                 }
                 chatbox.receiveMessage($message);
                 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-right-radius: 0;
   width: 200px;
+  height: 84px;
 }
 #conversejs .chatroom form.sendXMPPMessage {
   -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]
 * 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]
+* #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]
 * #215 (and also #75) XEP-0249: Direct MUC Invitations. [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``
 
+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
 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-right-radius: 0;
     width: 200px;
+    height: 84px;
 }
 
 #conversejs .chatroom form.sendXMPPMessage {