Переглянути джерело

Ability to specify both subject and message for feedback messages

This allows for better desktop notification messages.
Also improved the wording for some of the feedback messages.
JC Brand 9 роки тому
батько
коміт
c6d37b57e7
2 змінених файлів з 22 додано та 18 видалено
  1. 21 9
      src/converse-core.js
  2. 1 9
      src/converse-notification.js

+ 21 - 9
src/converse-core.js

@@ -373,17 +373,21 @@
             converse.everySecondTrigger = window.setInterval(converse.onEverySecond, 1000);
         };
 
-        this.giveFeedback = function (message, klass) {
+        this.giveFeedback = function (subject, klass, message) {
             $('.conn-feedback').each(function (idx, el) {
                 var $el = $(el);
-                $el.addClass('conn-feedback').text(message);
+                $el.addClass('conn-feedback').text(subject);
                 if (klass) {
                     $el.addClass(klass);
                 } else {
                     $el.removeClass('error');
                 }
             });
-            converse.emit('feedback', {'message': message, 'klass': klass});
+            converse.emit('feedback', {
+                'klass': klass,
+                'message': message,
+                'subject': subject
+            });
         };
 
         this.rejectPresenceSubscription = function (jid, message) {
@@ -405,7 +409,9 @@
             converse.connection.reset();
             converse.log('The connection has dropped, attempting to reconnect.');
             converse.giveFeedback(
-                __('The connection has dropped, attempting to reconnect.'), 'warn');
+                __("Reconnecting"), 'warn',
+                __('The connection has dropped, attempting to reconnect.')
+            );
             converse.clearSession();
             converse._tearDown();
             if (converse.authentication !== "prebind") {
@@ -464,22 +470,28 @@
             } else if (status === Strophe.Status.DISCONNECTED) {
                 converse.setDisconnectionCause(status);
                 converse.onDisconnected(condition);
+                if (status === Strophe.Status.DISCONNECTING && condition) {
+                    converse.giveFeedback(
+                        __("Disconnected"), 'warn',
+                        __("The connection to the chat server has dropped")
+                    );
+                }
             } else if (status === Strophe.Status.ERROR) {
-                converse.giveFeedback(__('Error'), 'error');
+                converse.giveFeedback(
+                    __('Connection error'), 'error',
+                    __('An error occurred while connecting to the chat server.')
+                );
             } else if (status === Strophe.Status.CONNECTING) {
                 converse.giveFeedback(__('Connecting'));
             } else if (status === Strophe.Status.AUTHENTICATING) {
                 converse.giveFeedback(__('Authenticating'));
             } else if (status === Strophe.Status.AUTHFAIL) {
-                converse.giveFeedback(__('Authentication Failed'), 'error');
+                converse.giveFeedback(__('Authentication failed.'), 'error');
                 converse.connection.disconnect(__('Authentication Failed'));
                 converse.disconnection_cause = Strophe.Status.AUTHFAIL;
             } else if (status === Strophe.Status.CONNFAIL ||
                        status === Strophe.Status.DISCONNECTING) {
                 converse.setDisconnectionCause(status);
-                if (status === Strophe.Status.DISCONNECTING && condition) {
-                    converse.giveFeedback(condition, 'error');
-                }
             }
         };
 

+ 1 - 9
src/converse-notification.js

@@ -195,15 +195,7 @@
             };
 
             converse.showFeedbackNotification = function (data) {
-                var subject;
-                if (data.klass === 'error') {
-                    subject = __('An error has occured');
-                } else if (data.klass === 'warn') {
-                    subject = __('Please be aware');
-                } else {
-                    return;
-                }
-                var n = new Notification(subject, {
+                var n = new Notification(data.subject, {
                         body: data.message,
                         lang: converse.i18n.locale_data.converse[""].lang,
                         icon: 'logo/conversejs.png'