diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index e5f72ba2e48..dfa63f77aa7 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -8817,103 +8817,6 @@ function fullclone($thing) {
return unserialize(serialize($thing));
}
- /**
- * If new messages are waiting for the current user, then insert
- * JavaScript to pop up the messaging window into the page
- *
- * @return void
- */
-function message_popup_window() {
- global $USER, $DB, $PAGE, $CFG;
-
- if (!$PAGE->get_popup_notification_allowed() || empty($CFG->messaging)) {
- return;
- }
-
- if (!isloggedin() || isguestuser()) {
- return;
- }
-
- if (!isset($USER->message_lastpopup)) {
- $USER->message_lastpopup = 0;
- } else if ($USER->message_lastpopup > (time()-120)) {
- // Don't run the query to check whether to display a popup if its been run in the last 2 minutes.
- return;
- }
-
- // A quick query to check whether the user has new messages.
- $messagecount = $DB->count_records('message', array('useridto' => $USER->id));
- if ($messagecount < 1) {
- return;
- }
-
- // There are unread messages so now do a more complex but slower query.
- $messagesql = "SELECT m.id, c.blocked
- FROM {message} m
- JOIN {message_working} mw ON m.id=mw.unreadmessageid
- JOIN {message_processors} p ON mw.processorid=p.id
- LEFT JOIN {message_contacts} c ON c.contactid = m.useridfrom
- AND c.userid = m.useridto
- WHERE m.useridto = :userid
- AND p.name='popup'";
-
- // If the user was last notified over an hour ago we can re-notify them of old messages
- // so don't worry about when the new message was sent.
- $lastnotifiedlongago = $USER->message_lastpopup < (time()-3600);
- if (!$lastnotifiedlongago) {
- $messagesql .= 'AND m.timecreated > :lastpopuptime';
- }
-
- $waitingmessages = $DB->get_records_sql($messagesql, array('userid' => $USER->id, 'lastpopuptime' => $USER->message_lastpopup));
-
- $validmessages = 0;
- foreach ($waitingmessages as $messageinfo) {
- if ($messageinfo->blocked) {
- // Message is from a user who has since been blocked so just mark it read.
- // Get the full message to mark as read.
- $messageobject = $DB->get_record('message', array('id' => $messageinfo->id));
- message_mark_message_read($messageobject, time());
- } else {
- $validmessages++;
- }
- }
-
- if ($validmessages > 0) {
- $strmessages = get_string('unreadnewmessages', 'message', $validmessages);
- $strgomessage = get_string('gotomessages', 'message');
- $strstaymessage = get_string('ignore', 'admin');
-
- $notificationsound = null;
- $beep = get_user_preferences('message_beepnewmessage', '');
- if (!empty($beep)) {
- // Browsers will work down this list until they find something they support.
- $sourcetags = html_writer::empty_tag('source', array('src' => $CFG->wwwroot.'/message/bell.wav', 'type' => 'audio/wav'));
- $sourcetags .= html_writer::empty_tag('source', array('src' => $CFG->wwwroot.'/message/bell.ogg', 'type' => 'audio/ogg'));
- $sourcetags .= html_writer::empty_tag('source', array('src' => $CFG->wwwroot.'/message/bell.mp3', 'type' => 'audio/mpeg'));
- $sourcetags .= html_writer::empty_tag('embed', array('src' => $CFG->wwwroot.'/message/bell.wav', 'autostart' => 'true', 'hidden' => 'true'));
-
- $notificationsound = html_writer::tag('audio', $sourcetags, array('preload' => 'auto', 'autoplay' => 'autoplay'));
- }
-
- $url = $CFG->wwwroot.'/message/index.php';
- $content = html_writer::start_tag('div', array('id' => 'newmessageoverlay', 'class' => 'mdl-align')).
- html_writer::start_tag('div', array('id' => 'newmessagetext')).
- $strmessages.
- html_writer::end_tag('div').
-
- $notificationsound.
- html_writer::start_tag('div', array('id' => 'newmessagelinks')).
- html_writer::link($url, $strgomessage, array('id' => 'notificationyes')).' '.
- html_writer::link('', $strstaymessage, array('id' => 'notificationno')).
- html_writer::end_tag('div');
- html_writer::end_tag('div');
-
- $PAGE->requires->js_init_call('M.core_message.init_notification', array('', $content, $url));
-
- $USER->message_lastpopup = time();
- }
-}
-
/**
* Used to make sure that $min <= $value <= $max
*
diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php
index be0a54b4495..095d6f14c33 100644
--- a/lib/outputrenderers.php
+++ b/lib/outputrenderers.php
@@ -3198,9 +3198,11 @@ EOD;
* @return string HTML for the notification menu
*/
public function notification_menu() {
- global $USER;
+ global $USER, $DB;
- if (isloggedin()) {
+ $processor = $DB->get_record('message_processors', array('name' => 'popup'));
+
+ if (isloggedin() && $processor->enabled) {
$context = [
'userid' => $USER->id,
'urls' => [
diff --git a/lib/pagelib.php b/lib/pagelib.php
index 20e85a7196d..061335d9d9e 100644
--- a/lib/pagelib.php
+++ b/lib/pagelib.php
@@ -1501,9 +1501,6 @@ class moodle_page {
$title .= ' - ';
}
$this->set_title($title . get_string('maintenancemode', 'admin'));
- } else {
- // Show the messaging popup if there are messages.
- message_popup_window();
}
$this->initialise_standard_body_classes();
diff --git a/message/module.js b/message/module.js
index bc10ce0e7e7..4c5bd67dd6a 100644
--- a/message/module.js
+++ b/message/module.js
@@ -17,33 +17,6 @@ M.core_message.combinedsearchgotfocus = function(e) {
}
};
-M.core_message.init_notification = function(Y, title, content, url) {
- Y.use('overlay', function() {
- var o = new Y.Overlay({
- headerContent : title,
- bodyContent : content
- });
- o.render(Y.one(document.body));
-
- if (Y.UA.ie > 0 && Y.UA.ie < 7) {
- // Adjust for IE 6 (can't handle fixed pos)
- //align the bottom right corner of the overlay with the bottom right of the viewport
- o.set("align", {
- points:[Y.WidgetPositionAlign.BR, Y.WidgetPositionAlign.BR]
- });
- }
-
- Y.one('#notificationyes').on('click', function(e) {
- window.location.href = url;
- }, o);
- Y.one('#notificationno').on('click', function(e) {
- o.hide();
- e.preventDefault();
- return false;
- }, o);
- });
-};
-
M.core_message.init_defaultoutputs = function(Y) {
var defaultoutputs = {
diff --git a/message/output/popup/message_output_popup.php b/message/output/popup/message_output_popup.php
index a3910cf5258..f504ad1c0af 100644
--- a/message/output/popup/message_output_popup.php
+++ b/message/output/popup/message_output_popup.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see