From 0b22bb25c1791a25d1f4901cd0acd99bae795f3e Mon Sep 17 00:00:00 2001 From: nickago Date: Wed, 12 Aug 2015 15:27:46 -0700 Subject: [PATCH 1/6] Handed control of notification sounds over to browser for firefox --- web/react/components/user_settings.jsx | 47 +++++++++++++++++--------- web/react/utils/utils.jsx | 6 ++-- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/web/react/components/user_settings.jsx b/web/react/components/user_settings.jsx index 1a0c313d3c..d2d72884bc 100644 --- a/web/react/components/user_settings.jsx +++ b/web/react/components/user_settings.jsx @@ -13,6 +13,7 @@ var assign = require('object-assign'); function getNotificationsStateFromStores() { var user = UserStore.getCurrentUser(); + var soundNeeded = (!navigator || navigator.userAgent.toLowerCase().indexOf("firefox") === -1); var sound = (!user.notify_props || user.notify_props.desktop_sound == undefined) ? "true" : user.notify_props.desktop_sound; var desktop = (!user.notify_props || user.notify_props.desktop == undefined) ? "all" : user.notify_props.desktop; var email = (!user.notify_props || user.notify_props.email == undefined) ? "true" : user.notify_props.email; @@ -58,7 +59,7 @@ function getNotificationsStateFromStores() { } } - return { notify_level: desktop, enable_email: email, enable_sound: sound, username_key: username_key, mention_key: mention_key, custom_keys: custom_keys, custom_keys_checked: custom_keys.length > 0, first_name_key: first_name_key, all_key: all_key, channel_key: channel_key }; + return { notify_level: desktop, enable_email: email, soundNeeded: soundNeeded, enable_sound: sound, username_key: username_key, mention_key: mention_key, custom_keys: custom_keys, custom_keys_checked: custom_keys.length > 0, first_name_key: first_name_key, all_key: all_key, channel_key: channel_key }; } @@ -236,23 +237,35 @@ var NotificationsTab = React.createClass({ var soundSection; if (this.props.activeSection === 'sound') { - var soundActive = ["",""]; - if (this.state.enable_sound === "false") { - soundActive[1] = "active"; - } else { - soundActive[0] = "active"; - } - var inputs = []; - inputs.push( -
-
- - + if(this.state.soundNeeded) { + var soundActive = ["",""]; + if (this.state.enable_sound === "false") { + soundActive[1] = "active"; + } else { + soundActive[0] = "active"; + } + + inputs.push( +
+
+ + +
-
- ); + ); + } else { + inputs.push( +
+
+ + +
+

Please disable notification sounds in your browser settings
+
+ ) + } soundSection = ( Date: Wed, 12 Aug 2015 16:03:36 -0700 Subject: [PATCH 2/6] Added extra uAgent check for weird browser implementations --- web/react/components/user_settings.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/react/components/user_settings.jsx b/web/react/components/user_settings.jsx index d2d72884bc..fa01d62c29 100644 --- a/web/react/components/user_settings.jsx +++ b/web/react/components/user_settings.jsx @@ -13,7 +13,7 @@ var assign = require('object-assign'); function getNotificationsStateFromStores() { var user = UserStore.getCurrentUser(); - var soundNeeded = (!navigator || navigator.userAgent.toLowerCase().indexOf("firefox") === -1); + var soundNeeded = (!navigator || !navigator.userAgent || navigator.userAgent.toLowerCase().indexOf("firefox") === -1); var sound = (!user.notify_props || user.notify_props.desktop_sound == undefined) ? "true" : user.notify_props.desktop_sound; var desktop = (!user.notify_props || user.notify_props.desktop == undefined) ? "all" : user.notify_props.desktop; var email = (!user.notify_props || user.notify_props.email == undefined) ? "true" : user.notify_props.email; From c5ee567bacbc55372d526c668fa138c80545498e Mon Sep 17 00:00:00 2001 From: nickago Date: Thu, 13 Aug 2015 08:50:40 -0700 Subject: [PATCH 3/6] Refactored such that the menu doesn't open for firefox users --- web/react/components/setting_item_min.jsx | 6 ++- web/react/components/user_settings.jsx | 45 +++++++++-------------- web/react/utils/utils.jsx | 2 +- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/web/react/components/setting_item_min.jsx b/web/react/components/setting_item_min.jsx index 2209c74d1c..1352269005 100644 --- a/web/react/components/setting_item_min.jsx +++ b/web/react/components/setting_item_min.jsx @@ -3,10 +3,14 @@ module.exports = React.createClass({ render: function() { + var editButton = ''; + if(!this.props.disableOpen) { + editButton =
  • Edit
  • ; + } return (
    • {this.props.title}
    • -
    • Edit
    • + {editButton}
    • {this.props.describe}
    ); diff --git a/web/react/components/user_settings.jsx b/web/react/components/user_settings.jsx index fa01d62c29..0dfea6543d 100644 --- a/web/react/components/user_settings.jsx +++ b/web/react/components/user_settings.jsx @@ -236,36 +236,24 @@ var NotificationsTab = React.createClass({ } var soundSection; - if (this.props.activeSection === 'sound') { + if (this.props.activeSection === 'sound' && this.state.soundNeeded) { + var soundActive = ["",""]; + if (this.state.enable_sound === "false") { + soundActive[1] = "active"; + } else { + soundActive[0] = "active"; + } + var inputs = []; - if(this.state.soundNeeded) { - var soundActive = ["",""]; - if (this.state.enable_sound === "false") { - soundActive[1] = "active"; - } else { - soundActive[0] = "active"; - } - - inputs.push( -
    -
    - - -
    + inputs.push( +
    +
    + +
    - ); - } else { - inputs.push( -
    -
    - - -
    -

    Please disable notification sounds in your browser settings
    -
    - ) - } +
    + ); soundSection = ( ); } diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index b1832f3f1f..6236e11ddd 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -124,7 +124,7 @@ module.exports.notifyMe = function(title, body, channel) { } module.exports.ding = function() { - if (!navigator || navigator.userAgent.toLowerCase().indexOf("firefox") === -1) { + if (!navigator || !navigator.userAgent || navigator.userAgent.toLowerCase().indexOf("firefox") === -1) { var audio = new Audio('/static/images/ding.mp3'); audio.play(); } From 2f431240a4fcbf8b693e6bc1f80192aae3ff92bf Mon Sep 17 00:00:00 2001 From: nickago Date: Thu, 13 Aug 2015 08:54:05 -0700 Subject: [PATCH 4/6] Cosmetic refactoring --- web/react/components/setting_item_min.jsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/web/react/components/setting_item_min.jsx b/web/react/components/setting_item_min.jsx index 1352269005..3c87e416eb 100644 --- a/web/react/components/setting_item_min.jsx +++ b/web/react/components/setting_item_min.jsx @@ -2,16 +2,23 @@ // See License.txt for license information. module.exports = React.createClass({ + displayName: 'SettingsItemMin', + propTypes: { + title: React.PropTypes.string, + disableOpen: React.PropTypes.bool, + updateSection: React.PropTypes.func, + describe: React.PropTypes.string + }, render: function() { var editButton = ''; - if(!this.props.disableOpen) { - editButton =
  • Edit
  • ; + if (!this.props.disableOpen) { + editButton =
  • Edit
  • ; } return ( -
      -
    • {this.props.title}
    • +
        +
      • {this.props.title}
      • {editButton} -
      • {this.props.describe}
      • +
      • {this.props.describe}
      ); } From 63005366ade33e0c1509fc1517381279b6cbd9ee Mon Sep 17 00:00:00 2001 From: nickago Date: Fri, 14 Aug 2015 14:21:41 -0700 Subject: [PATCH 5/6] move browser check functionality into a method --- web/react/components/user_settings.jsx | 2 +- web/react/utils/utils.jsx | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/web/react/components/user_settings.jsx b/web/react/components/user_settings.jsx index 0dfea6543d..ad7de40bff 100644 --- a/web/react/components/user_settings.jsx +++ b/web/react/components/user_settings.jsx @@ -13,7 +13,7 @@ var assign = require('object-assign'); function getNotificationsStateFromStores() { var user = UserStore.getCurrentUser(); - var soundNeeded = (!navigator || !navigator.userAgent || navigator.userAgent.toLowerCase().indexOf("firefox") === -1); + var soundNeeded = !utils.checkBrowserType('firefox'); var sound = (!user.notify_props || user.notify_props.desktop_sound == undefined) ? "true" : user.notify_props.desktop_sound; var desktop = (!user.notify_props || user.notify_props.desktop == undefined) ? "all" : user.notify_props.desktop; var email = (!user.notify_props || user.notify_props.email == undefined) ? "true" : user.notify_props.email; diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 6236e11ddd..ba48f0b1b1 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -124,7 +124,7 @@ module.exports.notifyMe = function(title, body, channel) { } module.exports.ding = function() { - if (!navigator || !navigator.userAgent || navigator.userAgent.toLowerCase().indexOf("firefox") === -1) { + if (!module.exports.checkBrowserType('firefox')) { var audio = new Audio('/static/images/ding.mp3'); audio.play(); } @@ -936,3 +936,7 @@ module.exports.generateId = function() { return id; }; + +module.exports.checkBrowserType = function(browser) { + return navigator && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf(browser.toLowerCase()) > -1 +} From fb9e891246db3b8b69e70697d29be5b36b8c7578 Mon Sep 17 00:00:00 2001 From: nickago Date: Mon, 17 Aug 2015 08:10:49 -0700 Subject: [PATCH 6/6] Added hardcoded firefox function --- web/react/components/user_settings.jsx | 2 +- web/react/utils/utils.jsx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/web/react/components/user_settings.jsx b/web/react/components/user_settings.jsx index ad7de40bff..66d8c9366d 100644 --- a/web/react/components/user_settings.jsx +++ b/web/react/components/user_settings.jsx @@ -13,7 +13,7 @@ var assign = require('object-assign'); function getNotificationsStateFromStores() { var user = UserStore.getCurrentUser(); - var soundNeeded = !utils.checkBrowserType('firefox'); + var soundNeeded = !utils.isBrowserFirefox(); var sound = (!user.notify_props || user.notify_props.desktop_sound == undefined) ? "true" : user.notify_props.desktop_sound; var desktop = (!user.notify_props || user.notify_props.desktop == undefined) ? "all" : user.notify_props.desktop; var email = (!user.notify_props || user.notify_props.email == undefined) ? "true" : user.notify_props.email; diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index ba48f0b1b1..bc1009135c 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -124,7 +124,7 @@ module.exports.notifyMe = function(title, body, channel) { } module.exports.ding = function() { - if (!module.exports.checkBrowserType('firefox')) { + if (!module.exports.isBrowserFirefox()) { var audio = new Audio('/static/images/ding.mp3'); audio.play(); } @@ -937,6 +937,6 @@ module.exports.generateId = function() { return id; }; -module.exports.checkBrowserType = function(browser) { - return navigator && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf(browser.toLowerCase()) > -1 +module.exports.isBrowserFirefox = function() { + return navigator && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('firefox') > -1; }