Skip to content

Commit

Permalink
Closes #606; Allows a user to disable sound notifications for new roo…
Browse files Browse the repository at this point in the history
…ms and new messages
  • Loading branch information
marceloschmidt committed Sep 1, 2015
1 parent 138d6ca commit a7edf3c
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 7 deletions.
4 changes: 2 additions & 2 deletions client/lib/notification.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
, 2000

newMessage: ->
unless Session.equals('user_' + Meteor.userId() + '_status', 'busy')
unless Session.equals('user_' + Meteor.userId() + '_status', 'busy') or Meteor.user()?.settings?.preferences?.disableNewMessageNotification
$('#chatAudioNotification')[0].play()

newRoom: (rid, withSound = true) ->
Expand All @@ -49,7 +49,7 @@

Tracker.autorun ->
if Session.get('newRoomSound')?.length > 0
unless Session.equals('user_' + Meteor.userId() + '_status', 'busy')
unless Session.equals('user_' + Meteor.userId() + '_status', 'busy') or Meteor.user()?.settings?.preferences?.disableNewRoomNotification
$('#chatNewRoomNotification').each ->
this.play()
else
Expand Down
1 change: 1 addition & 0 deletions client/views/account/accountFlex.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ <h4>{{_ "My_Account"}}</h4>
<div class="wrapper">
<ul>
<li>
<a href="{{pathFor 'account' group='preferences'}}" class="account-link">{{_ "Preferences"}}</a>
<a href="{{pathFor 'account' group='profile'}}" class="account-link">{{_ "Profile"}}</a>
{{!-- <a href="{{pathFor 'account' group='account'}}" class="account-link">{{_ "Account_Settings"}}</a> --}}
{{!-- <a href="{{pathFor 'account' group='notification'}}" class="account-link">{{_ "Notification"}}</a> --}}
Expand Down
34 changes: 34 additions & 0 deletions client/views/account/accountPreferences.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Template.accountPreferences.helpers
checked: (property, value) ->
currentValue = !!Meteor.user()?.settings?.preferences?[property]
return currentValue is value

Template.accountPreferences.onCreated ->
settingsTemplate = this.parentTemplate(3)
settingsTemplate.child ?= []
settingsTemplate.child.push this

@clearForm = ->

@save = ->
instance = @
data = {}

data.disableNewRoomNotification = $('input[name=disableNewRoomNotification]:checked').val()
data.disableNewMessageNotification = $('input[name=disableNewMessageNotification]:checked').val()
Meteor.call 'saveUserPreferences', data, (error, results) ->
if results
toastr.success t('Preferences_saved')
instance.clearForm()

if error
toastr.error error.reason

Template.accountPreferences.onRendered ->
Tracker.afterFlush ->
SideNav.setFlex "accountFlex"
SideNav.openFlex()

Template.accountPreferences.events
'click .submit button': (e, t) ->
t.save()
38 changes: 38 additions & 0 deletions client/views/account/accountPreferences.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template name="accountPreferences">
<section class="page-container page-home page-static">
<head class="fixed-title">
{{> burger}}
<h2>
<span class="room-title">{{_ "Preferences"}}</span>
</h2>
</head>
<div class="content">
<div class="rocket-form">
<fieldset>
<div class="section">
<h1>{{_ "Sound"}}</h1>
<div class="section-content">
<div class="input-line double-col">
<label>{{_ "Disable_New_Room_Notification"}}</label>
<div>
<label><input type="radio" name="disableNewRoomNotification" value="1" checked="{{checked 'disableNewRoomNotification' true}}" /> {{_ "True"}}</label>
<label><input type="radio" name="disableNewRoomNotification" value="0" checked="{{checked 'disableNewRoomNotification' false}}" /> {{_ "False"}}</label>
</div>
</div>
<div class="input-line double-col">
<label>{{_ "Disable_New_Message_Notification"}}</label>
<div>
<label><input type="radio" name="disableNewMessageNotification" value="1" checked="{{checked 'disableNewMessageNotification' true}}" /> {{_ "True"}}</label>
<label><input type="radio" name="disableNewMessageNotification" value="0" checked="{{checked 'disableNewMessageNotification' false}}" /> {{_ "False"}}</label>
</div>
</div>
</div>
</div>
</fieldset>
<div class="submit">
<button class="button"><i class="icon-send"></i><span>{{_ "Save_changes"}}</span></button>
</div>
</div>
</div>
</section>
</template>
5 changes: 0 additions & 5 deletions client/views/account/accountProfile.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
Template.accountProfile.helpers
flexOpened: ->
return 'opened' if Session.equals('flexOpened', true)
arrowPosition: ->
console.log 'room.helpers arrowPosition' if window.rocketDebug
return 'left' unless Session.equals('flexOpened', true)
languages: ->
languages = TAPi18n.getLanguages()
result = []
Expand Down
5 changes: 5 additions & 0 deletions i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"Delete_User_Warning": "Deleting a user will delete all messages from that user as well. This cannot be undone.",
"Deleted" : "Deleted!",
"Direct_Messages" : "Direct Messages",
"Disable_New_Message_Notification" : "Disable New Message Notification",
"Disable_New_Room_Notification" : "Disable New Room Notification",
"Drop_to_upload_file" : "Drop to upload file",
"Duplicate_channel_name" : "A Channel with name '%s' exists",
"Duplicate_private_group_name" : "A Private Group with name '%s' exists",
Expand Down Expand Up @@ -191,6 +193,8 @@
"Please_wait_activation" : "Please wait, this can take some time.",
"Please_wait_statistics" : "Please wait, statistics are being generated.",
"Powered_by" : "Powered by",
"Preferences" : "Preferences",
"Preferences_saved" : "Preferences saved",
"Privacy" : "Privacy",
"Private_Groups" : "Private Groups",
"Profile" : "Profile",
Expand Down Expand Up @@ -243,6 +247,7 @@
"SMTP_Password" : "SMTP Password",
"SMTP_Port" : "SMTP Port",
"SMTP_Username" : "SMTP Username",
"Sound" : "Sound",
"Start_of_conversation" : "Start of conversation",
"Stats_Active_Users": "Active Users",
"Stats_Avg_Channel_Users": "Average Channel Users",
Expand Down
16 changes: 16 additions & 0 deletions server/methods/saveUserPreferences.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Meteor.methods
saveUserPreferences: (settings) ->
console.log '[method] saveUserPreferences', settings

if Meteor.userId()
preferences = {}

if settings.disableNewRoomNotification?
preferences.disableNewRoomNotification = if settings.disableNewRoomNotification is "1" then true else false

if settings.disableNewMessageNotification?
preferences.disableNewMessageNotification = if settings.disableNewMessageNotification is "1" then true else false

Meteor.users.update Meteor.userId(), { $set: { "settings.preferences": preferences } }

return true
1 change: 1 addition & 0 deletions server/publications/userData.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Meteor.publish 'userData', ->
admin: 1
utcOffset: 1
language: 1
settings: 1

0 comments on commit a7edf3c

Please sign in to comment.