Finished implementing notification settings for sound and strangers

This commit is contained in:
Kevin Froman 2020-04-05 23:21:21 -05:00
parent 4cd2302bc9
commit ae8d1fc5ea
4 changed files with 55 additions and 8 deletions

View File

@ -62,6 +62,7 @@ def on_insertblock(api, data={}):
def on_processblocks(api, data=None): def on_processblocks(api, data=None):
if data['type'] != 'pm': if data['type'] != 'pm':
return return
notification_func = notifier.notify
data['block'].decrypt() data['block'].decrypt()
metadata = data['block'].bmetadata metadata = data['block'].bmetadata
@ -73,10 +74,14 @@ def on_processblocks(api, data=None):
else: else:
signer = signer[:5] signer = signer[:5]
if data['block'].decrypted: if data['block'].decrypted:
config.reload() config.reload()
if config.get('mail.notificationSound', True):
notification_func = notifier.notification_with_sound
if config.get('mail.notificationSetting', True): if config.get('mail.notificationSetting', True):
if not config.get('mail.strangersNotification', True): if not config.get('mail.strangersNotification', True):
if not user.isFriend(): if not user.isFriend():
return return
notifier.notification_with_sound(title="Onionr Mail - New Message", message="From: %s\n\nSubject: %s" % (signer, metadata['subject'])) notification_func(title="Onionr Mail - New Message", message="From: %s\n\nSubject: %s" % (signer, metadata['subject']))

View File

@ -161,13 +161,13 @@
</div> </div>
<div class="columns notificationSetting"> <div class="columns notificationSetting">
<div class="column"> <div class="column">
Only show notifications for friends Notifications for stranger's messages
</div> </div>
<div class="column is-2"> <div class="column is-2">
<div class="field"> <div class="field">
<input id="friendsOnlyNotifications" type="checkbox" <input id="strangersNotification" type="checkbox"
class="switch is-rounded"> class="switch is-rounded" checked>
<label for="friendsOnlyNotifications"></label> <label for="strangersNotification"></label>
</div> </div>
</div> </div>
</div> </div>
@ -177,9 +177,9 @@
</div> </div>
<div class="column is-2"> <div class="column is-2">
<div class="field"> <div class="field">
<input id="audibleNotificationSetting" type="checkbox" <input id="notificationSound" type="checkbox"
class="switch is-rounded"> class="switch is-rounded" checked>
<label for="audibleNotificationSetting"></label> <label for="notificationSound"></label>
</div> </div>
</div> </div>
</div> </div>

View File

@ -17,7 +17,13 @@ fetch('/config/get/mail', {
if (mailSettings.notificationSetting === false){ if (mailSettings.notificationSetting === false){
document.getElementById('notificationSetting').checked = false document.getElementById('notificationSetting').checked = false
} }
if (mailSettings.notificationSound === false){
document.getElementById('notificationSound').checked = false
}
if (typeof mailSettings.signature != undefined && mailSettings.signature != null && mailSettings.signature != ""){ if (typeof mailSettings.signature != undefined && mailSettings.signature != null && mailSettings.signature != ""){
document.getElementById('mailSignatureSetting').value = mailSettings.signature document.getElementById('mailSignatureSetting').value = mailSettings.signature
} }
if (mailSettings.strangersNotification == false){
document.getElementById('strangersNotification').checked = false
}
}) })

View File

@ -17,6 +17,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
var notificationSetting = document.getElementById('notificationSetting') var notificationSetting = document.getElementById('notificationSetting')
var friendOnlyNotification = document.getElementById('strangersNotification')
var notificationSound = document.getElementById('notificationSound')
var sigSetting = document.getElementById('mailSignatureSetting') var sigSetting = document.getElementById('mailSignatureSetting')
document.getElementById('forwardSecrecySetting').onchange = function(e){ document.getElementById('forwardSecrecySetting').onchange = function(e){
@ -37,6 +39,40 @@ document.getElementById('forwardSecrecySetting').onchange = function(e){
}) })
} }
notificationSound.onchange = function(e){
var postData = JSON.stringify({"notificationSound": e.target.checked})
fetch('/config/set/mail', {
method: 'POST',
body: postData,
headers: {
"content-type": "application/json",
"token": webpass
}})
.then(function(data) {
mailSettings['notificationSound'] = notificationSound.checked
PNotify.success({
text: 'Successfully notification sound'
})
})
}
friendOnlyNotification.onchange = function(e){
var postData = JSON.stringify({"strangersNotification": e.target.checked})
fetch('/config/set/mail', {
method: 'POST',
body: postData,
headers: {
"content-type": "application/json",
"token": webpass
}})
.then(function(data) {
mailSettings['strangersNotification'] = friendOnlyNotification.checked
PNotify.success({
text: 'Successfully toggled notifications from strangers'
})
})
}
notificationSetting.onchange = function(e){ notificationSetting.onchange = function(e){
var notificationSettings = document.getElementsByClassName('notificationSetting') var notificationSettings = document.getElementsByClassName('notificationSetting')