From 55af4309f7a982ac0abf023c52c414298b6b37b1 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Tue, 25 Oct 2016 13:39:14 +0530 Subject: [PATCH] MDL-56409 messages: Do not fetch notifications if they are disabled --- message/output/popup/classes/api.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/message/output/popup/classes/api.php b/message/output/popup/classes/api.php index cc8e85e5316..66908154612 100644 --- a/message/output/popup/classes/api.php +++ b/message/output/popup/classes/api.php @@ -34,7 +34,7 @@ defined('MOODLE_INTERNAL') || die(); */ class api { /** - * Get popup notifications for the specified users. + * Get popup notifications for the specified users. Nothing is returned if notifications are disabled. * * @param int $useridto the user id who received the notification * @param string $sort the column name to order by including optionally direction @@ -61,6 +61,18 @@ class api { 'useridto2' => $useridto, ]; + // Is notification enabled ? + if ($useridto == $USER->id) { + $disabled = $USER->emailstop; + } else { + $user = \core_user::get_user($useridto, "emailstop", MUST_EXIST); + $disabled = $user->emailstop; + } + if ($disabled) { + // Notifications are disabled, no need to run giant queries. + return array(); + } + $sql = "SELECT * FROM ( SELECT concat('r', r.id) as uniqueid, r.id, r.useridfrom, r.useridto, r.subject, r.fullmessage, r.fullmessageformat,