Finished implementing notification settings for sound and strangers

master
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):
if data['type'] != 'pm':
return
notification_func = notifier.notify
data['block'].decrypt()
metadata = data['block'].bmetadata
@ -73,10 +74,14 @@ def on_processblocks(api, data=None):
else:
signer = signer[:5]
if data['block'].decrypted:
config.reload()
if config.get('mail.notificationSound', True):
notification_func = notifier.notification_with_sound
if config.get('mail.notificationSetting', True):
if not config.get('mail.strangersNotification', True):
if not user.isFriend():
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 class="columns notificationSetting">
<div class="column">
Only show notifications for friends
Notifications for stranger's messages
</div>
<div class="column is-2">
<div class="field">
<input id="friendsOnlyNotifications" type="checkbox"
class="switch is-rounded">
<label for="friendsOnlyNotifications"></label>
<input id="strangersNotification" type="checkbox"
class="switch is-rounded" checked>
<label for="strangersNotification"></label>
</div>
</div>
</div>
@ -177,9 +177,9 @@
</div>
<div class="column is-2">
<div class="field">
<input id="audibleNotificationSetting" type="checkbox"
class="switch is-rounded">
<label for="audibleNotificationSetting"></label>
<input id="notificationSound" type="checkbox"
class="switch is-rounded" checked>
<label for="notificationSound"></label>
</div>
</div>
</div>

View File

@ -17,7 +17,13 @@ fetch('/config/get/mail', {
if (mailSettings.notificationSetting === 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 != ""){
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/>.
*/
var notificationSetting = document.getElementById('notificationSetting')
var friendOnlyNotification = document.getElementById('strangersNotification')
var notificationSound = document.getElementById('notificationSound')
var sigSetting = document.getElementById('mailSignatureSetting')
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){
var notificationSettings = document.getElementsByClassName('notificationSetting')