From 00d2a512f915e39ee11bb908f166866d3d01f905 Mon Sep 17 00:00:00 2001 From: Thomas Hackl <hackl@data-quest.de> Date: Wed, 16 Oct 2024 12:54:11 +0000 Subject: [PATCH] =?UTF-8?q?Resolve=20"Polishing:=20T=C3=B6ne=20f=C3=BCr=20?= =?UTF-8?q?Notifications=20k=C3=B6nnen=20nicht=20in=20allen=20Browsern=20a?= =?UTF-8?q?bgespielt=20werden"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #4684 Merge request studip/studip!3485 --- ...22_disable_audio_notifications_for_all.php | 82 +++++++++++++++++++ .../assets/javascripts/bootstrap/settings.js | 15 ++++ 2 files changed, 97 insertions(+) create mode 100644 db/migrations/6.0.22_disable_audio_notifications_for_all.php diff --git a/db/migrations/6.0.22_disable_audio_notifications_for_all.php b/db/migrations/6.0.22_disable_audio_notifications_for_all.php new file mode 100644 index 00000000000..049072886c1 --- /dev/null +++ b/db/migrations/6.0.22_disable_audio_notifications_for_all.php @@ -0,0 +1,82 @@ +<?php + +final class DisableAudioNotificationsForAll extends Migration +{ + public function description() + { + return 'Disable audio notifications for all users so that asking for audio permissions is triggered on re-activating'; + } + + protected function up() + { + // Deactive audio feedback per default setting. + DBManager::get()->execute( + "INSERT IGNORE INTO `config` + (`field`, `value`, `type`, `range`, `mkdate`, `chdate`, `description`) + VALUES + (:field, :value, :type, :range, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), :description)", + [ + 'field' => 'PERSONAL_NOTIFICATIONS_AUDIO_DEACTIVATED', + 'value' => 1, + 'type' => 'boolean', + 'range' => 'user', + 'description' => 'Audio-Feedback zu Benachrichtigungen abschalten' + ] + ); + + // Query default language + $query = "SELECT IFNULL(`config_values`.`value`, `config`.`value`) + FROM `config` + LEFT JOIN `config_values` USING (`field`) + WHERE `field` = 'DEFAULT_LANGUAGE'"; + $default_language = DBManager::get()->fetchColumn($query); + + // Send notifications to users to inform of the change + $query = "SELECT IF(`user_info`.`preferred_language` = '', ?, `user_info`.`preferred_language`), + `user_id` + FROM `auth_user_md5` + JOIN `user_info` USING (`user_id`) + LEFT JOIN `config_values` + ON `range_id` = `user_id` + AND `field` = 'PERSONAL_NOTIFICATIONS_AUDIO_DEACTIVATED' + AND `value` = '1' + WHERE `config_values`.`range_id` IS NULL"; + DBManager::get()->fetchGroupedPairs( + $query, + [$default_language], + function ($user_ids, $language) { + $message = 'Aus technischen Gründen wurde das Audio-Feedback zu ' + . 'Benachrichtigungen in Ihrem Konto deaktiviert. Bitte ' + . 'aktivieren Sie dieses erneut, wenn Sie es weiterhin ' + . 'nutzen möchten.'; + if (str_starts_with($language, 'en')) { + $message = 'For technical reasons, the audio feedback for ' + . 'notifications has been deactivated in your account. ' + . 'Please reactivate it if you wish to continue using it.'; + } + + // Create notification + $query = "INSERT INTO `personal_notifications` + (`url`, `text`, `avatar`, `mkdate`) + VALUES (?, ?, ?, UNIX_TIMESTAMP())"; + DBManager::get()->execute($query, [ + URLHelper::getURL('dispatch.php/settings/general'), + $message, + Icon::create('audio2')->asImagePath() + ]); + $id = DBManager::get()->lastInsertId(); + + // Assign users + $query = "INSERT INTO `personal_notifications_user` + (`personal_notification_id`, `user_id`) + VALUES (?, ?)"; + foreach ($user_ids as $user_id) { + DBManager::get()->execute($query, [$id, $user_id]); + } + } + ); + + // Reset all users to default. + DBManager::get()->exec("DELETE FROM `config_values` WHERE `field` = 'PERSONAL_NOTIFICATIONS_AUDIO_DEACTIVATED'"); + } +} diff --git a/resources/assets/javascripts/bootstrap/settings.js b/resources/assets/javascripts/bootstrap/settings.js index a8c7ccdba2a..43387631d71 100644 --- a/resources/assets/javascripts/bootstrap/settings.js +++ b/resources/assets/javascripts/bootstrap/settings.js @@ -15,6 +15,21 @@ STUDIP.domReady(() => { }); $('#edit_userdata .email-change-confirm').hide(); + + const audioActive = $('input[name="personal_notifications_audio_activated"]'); + audioActive.on('change', function() { + if (audioActive.is(':checked')) { + navigator.permissions.query({name: 'autoplay'}) + .then(result => { + if (result.state !== 'granted') { + navigator.mediaDevices.getUserMedia({video: false, audio: true}); + } + }) + .catch(error => { + navigator.mediaDevices.getUserMedia({video: false, audio: true}); + }); + } + }); }); // -- GitLab