From c6d37b57e79dd459f67294706055500a5f51d889 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Tue, 23 Aug 2016 08:00:41 +0000 Subject: [PATCH] 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. --- src/converse-core.js | 30 +++++++++++++++++++++--------- src/converse-notification.js | 10 +--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/converse-core.js b/src/converse-core.js index 40c955c21..b6c7370ca 100755 --- a/src/converse-core.js +++ b/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'); - } } }; diff --git a/src/converse-notification.js b/src/converse-notification.js index 8d855f3eb..b46c39460 100644 --- a/src/converse-notification.js +++ b/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'