From 3f3e453632801e02ebe86fb53555db008da11bef Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 5 Feb 2018 14:55:10 +0800 Subject: [PATCH] MDL-36941 message_popup: use new WS for marking notifications as read Also changed the observer to listen for the notification_viewed event, rather than the message_viewed event. --- .../output/popup/amd/build/notification_repository.min.js | 2 +- message/output/popup/amd/src/notification_repository.js | 4 ++-- message/output/popup/db/events.php | 6 +++--- message/output/popup/message_output_popup.php | 7 +++---- message/output/popup/version.php | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/message/output/popup/amd/build/notification_repository.min.js b/message/output/popup/amd/build/notification_repository.min.js index 6d076df7bf4..54afde06022 100644 --- a/message/output/popup/amd/build/notification_repository.min.js +++ b/message/output/popup/amd/build/notification_repository.min.js @@ -1 +1 @@ -define(["core/ajax","core/notification"],function(a,b){var c=function(c){"undefined"==typeof c.limit&&(c.limit=20),"undefined"==typeof c.offset&&(c.offset=0);var d={methodname:"message_popup_get_popup_notifications",args:c},e=a.call([d])[0];return e.fail(b.exception),e},d=function(c){var d={methodname:"message_popup_get_unread_popup_notification_count",args:c},e=a.call([d])[0];return e.fail(b.exception),e},e=function(c){var d={methodname:"core_message_mark_all_notifications_as_read",args:c},e=a.call([d])[0];return e.fail(b.exception),e},f=function(c,d){var e={messageid:c};d&&(e.timeread=d);var f={methodname:"core_message_mark_message_read",args:e},g=a.call([f])[0];return g.fail(b.exception),g};return{query:c,countUnread:d,markAllAsRead:e,markAsRead:f}}); \ No newline at end of file +define(["core/ajax","core/notification"],function(a,b){var c=function(c){"undefined"==typeof c.limit&&(c.limit=20),"undefined"==typeof c.offset&&(c.offset=0);var d={methodname:"message_popup_get_popup_notifications",args:c},e=a.call([d])[0];return e.fail(b.exception),e},d=function(c){var d={methodname:"message_popup_get_unread_popup_notification_count",args:c},e=a.call([d])[0];return e.fail(b.exception),e},e=function(c){var d={methodname:"core_message_mark_all_notifications_as_read",args:c},e=a.call([d])[0];return e.fail(b.exception),e},f=function(c,d){var e={notificationid:c};d&&(e.timeread=d);var f={methodname:"core_message_mark_notification_read",args:e},g=a.call([f])[0];return g.fail(b.exception),g};return{query:c,countUnread:d,markAllAsRead:e,markAsRead:f}}); \ No newline at end of file diff --git a/message/output/popup/amd/src/notification_repository.js b/message/output/popup/amd/src/notification_repository.js index 2fdb83ea6d0..801f9b99933 100644 --- a/message/output/popup/amd/src/notification_repository.js +++ b/message/output/popup/amd/src/notification_repository.js @@ -97,7 +97,7 @@ define(['core/ajax', 'core/notification'], function(Ajax, Notification) { */ var markAsRead = function(id, timeread) { var args = { - messageid: id, + notificationid: id, }; if (timeread) { @@ -105,7 +105,7 @@ define(['core/ajax', 'core/notification'], function(Ajax, Notification) { } var request = { - methodname: 'core_message_mark_message_read', + methodname: 'core_message_mark_notification_read', args: args }; diff --git a/message/output/popup/db/events.php b/message/output/popup/db/events.php index 3df04ba306f..b16846055b3 100644 --- a/message/output/popup/db/events.php +++ b/message/output/popup/db/events.php @@ -27,10 +27,10 @@ defined('MOODLE_INTERNAL') || die(); $observers = array( - // Message viewed. + // Notification viewed. array( - 'eventname' => '\core\event\message_viewed', - 'callback' => 'message_output_popup::message_viewed', + 'eventname' => '\core\event\notification_viewed', + 'callback' => 'message_output_popup::notification_viewed', 'includefile' => '/message/output/popup/message_output_popup.php' ) ); diff --git a/message/output/popup/message_output_popup.php b/message/output/popup/message_output_popup.php index 84ecee34e24..af35d54d128 100644 --- a/message/output/popup/message_output_popup.php +++ b/message/output/popup/message_output_popup.php @@ -115,15 +115,14 @@ class message_output_popup extends message_output { } /** - * Handles the message_viewed event to keep data in sync. + * Handles the notification_viewed event to keep data in sync. * * @param \core\event\base $event The event data */ - public static function message_viewed(\core\event\base $event) { + public static function notification_viewed(\core\event\base $event) { global $DB; - if ($record = $DB->get_record('message_popup', ['messageid' => $event->other['messageid']])) { - $record->messageid = $event->objectid; + if ($record = $DB->get_record('message_popup', ['messageid' => $event->objectid])) { $record->isread = 1; $DB->update_record('message_popup', $record); } diff --git a/message/output/popup/version.php b/message/output/popup/version.php index 94b0a2aa08c..1744c7894e9 100644 --- a/message/output/popup/version.php +++ b/message/output/popup/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017111300; // The current plugin version (Date: YYYYMMDDXX) +$plugin->version = 2018020500; // The current plugin version (Date: YYYYMMDDXX) $plugin->requires = 2017110800; // Requires this Moodle version $plugin->component = 'message_popup'; // Full name of the plugin (used for diagnostics)