From fcb5a85cdd21b8a48c16cd02885933bcbdb07ec2 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 17 Jan 2017 20:09:03 +0100 Subject: [PATCH] Add sounds for notifications. Boop by @jk@mastodon.social --- Procfile | 1 + .../components/actions/notifications.jsx | 8 +++- .../components/column_collapsable.jsx | 2 +- .../components/column_settings.jsx | 7 ++- .../components/reducers/settings.jsx | 9 +++- .../components/store/configureStore.jsx | 16 +++++-- config/puma.rb | 44 ++---------------- package.json | 1 + public/sounds/boop.mp3 | Bin 0 -> 12070 bytes yarn.lock | 10 ++++ 10 files changed, 50 insertions(+), 48 deletions(-) create mode 100644 public/sounds/boop.mp3 diff --git a/Procfile b/Procfile index c2c566e8cc..6cdd89518f 100644 --- a/Procfile +++ b/Procfile @@ -1 +1,2 @@ web: bundle exec puma -C config/puma.rb +worker: bundle exec sidekiq -q default -q mailers -q push diff --git a/app/assets/javascripts/components/actions/notifications.jsx b/app/assets/javascripts/components/actions/notifications.jsx index 1e5b2c382c..8688267f4f 100644 --- a/app/assets/javascripts/components/actions/notifications.jsx +++ b/app/assets/javascripts/components/actions/notifications.jsx @@ -24,17 +24,21 @@ const fetchRelatedRelationships = (dispatch, notifications) => { export function updateNotifications(notification, intlMessages, intlLocale) { return (dispatch, getState) => { + const showAlert = getState().getIn(['notifications', 'settings', 'alerts', notification.type], false); + const playSound = getState().getIn(['notifications', 'settings', 'sounds', notification.type], false); + dispatch({ type: NOTIFICATIONS_UPDATE, notification, account: notification.account, - status: notification.status + status: notification.status, + meta: playSound ? { sound: 'boop' } : null }); fetchRelatedRelationships(dispatch, [notification]); // Desktop notifications - if (typeof window.Notification !== 'undefined' && getState().getIn(['notifications', 'settings', 'alerts', notification.type], false)) { + if (typeof window.Notification !== 'undefined' && showAlert) { const title = new IntlMessageFormat(intlMessages[`notification.${notification.type}`], intlLocale).format({ name: notification.account.display_name.length > 0 ? notification.account.display_name : notification.account.username }); const body = $('

').html(notification.status ? notification.status.content : '').text(); diff --git a/app/assets/javascripts/components/components/column_collapsable.jsx b/app/assets/javascripts/components/components/column_collapsable.jsx index 8d74fd8a7a..203dc5e0c8 100644 --- a/app/assets/javascripts/components/components/column_collapsable.jsx +++ b/app/assets/javascripts/components/components/column_collapsable.jsx @@ -45,7 +45,7 @@ const ColumnCollapsable = React.createClass({

- + {({ opacity, height }) =>
{children} diff --git a/app/assets/javascripts/components/features/notifications/components/column_settings.jsx b/app/assets/javascripts/components/features/notifications/components/column_settings.jsx index dfb59713c4..b63c1881ac 100644 --- a/app/assets/javascripts/components/features/notifications/components/column_settings.jsx +++ b/app/assets/javascripts/components/features/notifications/components/column_settings.jsx @@ -36,15 +36,17 @@ const ColumnSettings = React.createClass({ const alertStr = ; const showStr = ; + const soundStr = ; return ( - +
+
@@ -52,6 +54,7 @@ const ColumnSettings = React.createClass({
+
@@ -59,6 +62,7 @@ const ColumnSettings = React.createClass({
+
@@ -66,6 +70,7 @@ const ColumnSettings = React.createClass({
+
diff --git a/app/assets/javascripts/components/reducers/settings.jsx b/app/assets/javascripts/components/reducers/settings.jsx index 8bd9edae21..8acc3facaf 100644 --- a/app/assets/javascripts/components/reducers/settings.jsx +++ b/app/assets/javascripts/components/reducers/settings.jsx @@ -23,6 +23,13 @@ const initialState = Immutable.Map({ favourite: true, reblog: true, mention: true + }), + + sounds: Immutable.Map({ + follow: true, + favourite: true, + reblog: true, + mention: true }) }) }); @@ -30,7 +37,7 @@ const initialState = Immutable.Map({ export default function settings(state = initialState, action) { switch(action.type) { case STORE_HYDRATE: - return state.merge(action.state.get('settings')); + return state.mergeDeep(action.state.get('settings')); case SETTING_CHANGE: return state.setIn(action.key, action.value); default: diff --git a/app/assets/javascripts/components/store/configureStore.jsx b/app/assets/javascripts/components/store/configureStore.jsx index 87f4699990..6f0823bf02 100644 --- a/app/assets/javascripts/components/store/configureStore.jsx +++ b/app/assets/javascripts/components/store/configureStore.jsx @@ -3,10 +3,18 @@ import thunk from 'redux-thunk'; import appReducer from '../reducers'; import loadingBarMiddleware from '../middleware/loading_bar'; import errorsMiddleware from '../middleware/errors'; +import soundsMiddleware from 'redux-sounds'; import Immutable from 'immutable'; -export default function configureStore() { - return createStore(appReducer, compose(applyMiddleware(thunk, loadingBarMiddleware({ - promiseTypeSuffixes: ['REQUEST', 'SUCCESS', 'FAIL'], - }), errorsMiddleware()), window.devToolsExtension ? window.devToolsExtension() : f => f)); +const soundsData = { + boop: '/sounds/boop.mp3' +}; + +export default function configureStore() { + return createStore(appReducer, compose(applyMiddleware( + thunk, + loadingBarMiddleware({ promiseTypeSuffixes: ['REQUEST', 'SUCCESS', 'FAIL'] }), + errorsMiddleware(), + soundsMiddleware(soundsData) + ), window.devToolsExtension ? window.devToolsExtension() : f => f)); }; diff --git a/config/puma.rb b/config/puma.rb index e6b0da91b5..550129bdc6 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,52 +1,18 @@ -# Puma can serve each request in a thread from an internal thread pool. -# The `threads` method setting takes two numbers a minimum and maximum. -# Any libraries that use thread pools should be configured to match -# the maximum value specified for Puma. Default is set to 5 threads for minimum -# and maximum, this matches the default thread size of Active Record. -# -threads_count = ENV.fetch("MAX_THREADS") { 5 }.to_i +threads_count = ENV.fetch('MAX_THREADS') { 5 }.to_i threads threads_count, threads_count -# Specifies the `port` that Puma will listen on to receive requests, default is 3000. -# -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT') { 3000 } +environment ENV.fetch('RAILS_ENV') { 'development' } +workers ENV.fetch('WEB_CONCURRENCY') { 2 } -# Specifies the `environment` that Puma will run in. -# -environment ENV.fetch("RAILS_ENV") { "development" } - -# Specifies the number of `workers` to boot in clustered mode. -# Workers are forked webserver processes. If using threads and workers together -# the concurrency of the application would be max `threads` * `workers`. -# Workers do not work on JRuby or Windows (both of which do not support -# processes). -# -workers ENV.fetch("WEB_CONCURRENCY") { 2 } - -# Use the `preload_app!` method when specifying a `workers` number. -# This directive tells Puma to first boot the application and load code -# before forking the application. This takes advantage of Copy On Write -# process behavior so workers use less memory. If you use this option -# you need to make sure to reconnect any threads in the `on_worker_boot` -# block. -# preload_app! -# The code in the `on_worker_boot` will be called if you are using -# clustered mode by specifying a number of `workers`. After each worker -# process is booted this block will be run, if you are using `preload_app!` -# option you will want to use this block to reconnect to any threads -# or connections that may have been created at application boot, Ruby -# cannot share connections between processes. -# on_worker_boot do - - if ENV["HEROKU"] #Spwan the workers from Puma, to only use one dyno + if ENV['HEROKU'] # Spawn the workers from Puma, to only use one dyno @sidekiq_pid ||= spawn('bundle exec sidekiq -q default -q mailers -q push') end ActiveRecord::Base.establish_connection if defined?(ActiveRecord) end -# Allow puma to be restarted by `rails restart` command. plugin :tmp_restart diff --git a/package.json b/package.json index 194bcfebad..dbcc032c67 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "react-toggle": "^2.1.1", "redux": "^3.6.0", "redux-immutable": "^3.0.8", + "redux-sounds": "^1.1.1", "redux-thunk": "^2.1.0", "reselect": "^2.5.4", "sass-loader": "^4.0.2", diff --git a/public/sounds/boop.mp3 b/public/sounds/boop.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..02a035d91b02049949e92f4116d2a1be6c85a4f1 GIT binary patch literal 12070 zcmeHLcU)6v7rsEifS`hiDEfH`AgE*~1R_%+LqTO&5l{)q4Ft$AgJmUxEjU0%K?Q_T z1sOuw;6hNem5PG1g4BVi6kM&iP{?MAp0ANB20Qk5s0j%vJ`E*7oBmx7WAU4+qb?-nU3S={FP|L{fICs7y6wG#s z7C>Ini@X`pp$sb~%Fb59I+7a6;d3An9gO6JafQ@K8x)<%3xuffciCku3Y43OLTykE zvKt`m40PlPAdrl)Kr?U_6p&(t!ILQz62%-O;P7NDj)*1V&;%ltgrkxO;K)MRYJk=P zCX4Dxa~g35|FS^^i$r`X78?-}fr%huc!D4--pa}fiz8qO1T<`c7DjPJ^hh*UXe5JB zV9+2TL%`;X*gP&M!=wlD#3CCM3ce4%$b`eExxa+x3NiA$Fbp0C3#W|5V{lkn6qn9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