2
0
Эх сурвалжийг харах

Add support for sound notifications. updates #62

(on incoming messages)
JC Brand 11 жил өмнө
parent
commit
882bbcb02e
6 өөрчлөгдсөн 50 нэмэгдсэн , 13 устгасан
  1. 1 1
      Makefile
  2. 45 4
      converse.js
  3. 2 1
      docs/CHANGES.rst
  4. 2 7
      index.html
  5. BIN
      sounds/ping.mp3
  6. BIN
      sounds/ping.ogg

+ 1 - 1
Makefile

@@ -2,7 +2,7 @@
 BOWER 		?= node_modules/.bin/bower
 BUILDDIR     = ./docs
 PAPER        =
-PHANTOMJS	?= node_modules/.bin/phantomjs
+PHANTOMJS	?= phantomjs
 SPHINXBUILD  = sphinx-build
 SPHINXOPTS   =
 

+ 45 - 4
converse.js

@@ -132,6 +132,12 @@
             'dnd':          2,
             'online':       1
         };
+
+        var INACTIVE = 'inactive';
+        var ACTIVE = 'active';
+        var COMPOSING = 'composing';
+        var PAUSED = 'paused';
+
         var HAS_CSPRNG = ((typeof crypto !== 'undefined') &&
             ((typeof crypto.randomBytes === 'function') ||
                 (typeof crypto.getRandomValues === 'function')
@@ -165,6 +171,7 @@
         this.i18n = locales.en;
         this.message_carbons = false;
         this.no_trimming = false; // Set to true for phantomjs tests (where browser apparently has no width)
+        this.play_sounds = false;
         this.prebind = false;
         this.roster_groups = false;
         this.show_controlbox_by_default = false;
@@ -206,6 +213,7 @@
             'i18n',
             'jid',
             'no_trimming',
+            'play_sounds',
             'prebind',
             'rid',
             'roster_groups',
@@ -814,19 +822,21 @@
                 var body = $message.children('body').text(),
                     from = Strophe.getBareJidFromJid($message.attr('from')),
                     composing = $message.find('composing'),
+                    paused = $message.find('paused'),
                     delayed = $message.find('delay').length > 0,
                     fullname = this.get('fullname'),
                     stamp, time, sender;
                 fullname = (_.isEmpty(fullname)? from: fullname).split(' ')[0];
 
                 if (!body) {
-                    if (composing.length) {
+                    if (composing.length || paused.length) {
                         this.messages.add({
                             fullname: fullname,
                             sender: 'them',
                             delayed: delayed,
                             time: moment().format(),
-                            composing: composing.length
+                            composing: composing.length,
+                            paused: paused.length
                         });
                     }
                 } else {
@@ -1031,8 +1041,11 @@
                         }));
                     }
                 }
-                if (message.get('composing')) {
-                    this.showStatusNotification(message.get('fullname')+' '+'is typing');
+                if (message.get(COMPOSING)) {
+                    this.showStatusNotification(message.get('fullname')+' '+__('is typing'));
+                    return;
+                } else if (message.get(PAUSED)) {
+                    this.showStatusNotification(message.get('fullname')+' '+__('has stopped typing'));
                     return;
                 } else {
                     this.showMessage(_.clone(message.attributes));
@@ -2442,6 +2455,31 @@
                 });
             },
 
+            playNotification: function () {
+                var ping;
+                if (converse.play_sounds && typeof Audio !== "undefined"){
+                    ping = new Audio("sounds/ping.ogg");
+                    if (ping.canPlayType('audio/ogg')) {
+                        ping.play();
+                    } else {
+                        ping = new Audio("sounds/ping.mp3");
+                        ping.play();
+                    }
+                }
+            },
+
+            isOnlyChatStateNotification: function ($msg) {
+                // See XEP-0085 Chat State Notification
+                return (
+                    $msg.find('body').length === 0 && (
+                        $msg.find(ACTIVE).length !== 0 ||
+                        $msg.find(COMPOSING).length !== 0 ||
+                        $msg.find(INACTIVE).length !== 0 ||
+                        $msg.find(PAUSED).length !== 0
+                    )
+                );
+            },
+
             onMessage: function (message) {
                 var buddy_jid, $message = $(message),
                     message_from = $message.attr('from');
@@ -2490,6 +2528,9 @@
                         'url': roster_item.get('url')
                     });
                 }
+                if (!this.isOnlyChatStateNotification($message) && from !== converse.bare_jid) {
+                    this.playNotification();
+                }
                 chatbox.receiveMessage($message);
                 converse.roster.addResource(buddy_jid, resource);
                 converse.emit('message', message);

+ 2 - 1
docs/CHANGES.rst

@@ -4,9 +4,10 @@ Changelog
 0.8.1 (Unreleased)
 ------------------
 
+* Bugfix: Contacts weren't properly sorted according to chat status. [jcbrand]
+* #63 Support for sound notification on message received. [jcbrand]
 * #212 Provide a live filter of the roster contacts. [jcbrand]
 
-
 0.8.0 (2014-08-04)
 ------------------
 

+ 2 - 7
index.html

@@ -12,13 +12,7 @@
     <link type="text/css" rel="stylesheet" media="screen" href="components/fontawesome/css/font-awesome.min.css" />
     <link type="text/css" rel="stylesheet" media="screen" href="css/theme.css" />
     <link type="text/css" rel="stylesheet" media="screen" href="css/converse.css" />
-    <!-- Only for development: <script data-main="main" src="components/requirejs/require.js"></script> -->
-    <![if gte IE 9]>
-        <script src="builds/converse.website.min.js"></script>
-    <![endif]>
-    <!--[if lt IE 9]>
-        <script src="builds/converse.website-no-otr.min.js"></script>
-    <![endif]-->
+    <script data-main="main" src="components/requirejs/require.js"></script>
 </head>
 
 <body id="page-top" data-spy="scroll" data-target=".navbar-custom">
@@ -239,6 +233,7 @@
             hide_muc_server: false,
             i18n: locales['en'], // Refer to ./locale/locales.js to see which locales are supported
             prebind: false,
+            play_sounds: true,
             show_controlbox_by_default: true,
             xhr_user_search: false,
             roster_groups: true

BIN
sounds/ping.mp3


BIN
sounds/ping.ogg