diff --git a/message/output/popup/amd/build/notification_popover_controller.min.js b/message/output/popup/amd/build/notification_popover_controller.min.js index 00e753760df..4d099a4c171 100644 --- a/message/output/popup/amd/build/notification_popover_controller.min.js +++ b/message/output/popup/amd/build/notification_popover_controller.min.js @@ -1 +1 @@ -define(["jquery","core/ajax","core/templates","core/str","core/url","core/notification","core/custom_interaction_events","core/popover_region_controller","message_popup/notification_repository","message_popup/notification_area_events"],function(a,b,c,d,e,f,g,h,i,j){var k={MARK_ALL_READ_BUTTON:'[data-action="mark-all-read"]',ALL_NOTIFICATIONS_CONTAINER:'[data-region="all-notifications"]',NOTIFICATION:'[data-region="notification-content-item-container"]',UNREAD_NOTIFICATION:'[data-region="notification-content-item-container"].unread',NOTIFICATION_LINK:'[data-action="content-item-link"]',EMPTY_MESSAGE:'[data-region="empty-message"]',COUNT_CONTAINER:'[data-region="count-container"]'},l=function(a){h.call(this,a),this.markAllReadButton=this.root.find(k.MARK_ALL_READ_BUTTON),this.unreadCount=0,this.userId=this.root.attr("data-userid"),this.container=this.root.find(k.ALL_NOTIFICATIONS_CONTAINER),this.limit=20,this.offset=0,this.loadedAll=!1,this.initialLoad=!1,this.loadUnreadNotificationCount()};return l.prototype=Object.create(h.prototype),l.prototype.constructor=l,l.prototype.updateButtonAriaLabel=function(){this.isMenuOpen()?d.get_string("hidenotificationwindow","message").done(function(a){this.menuToggle.attr("aria-label",a)}.bind(this)):this.unreadCount?d.get_string("shownotificationwindowwithcount","message",this.unreadCount).done(function(a){this.menuToggle.attr("aria-label",a)}.bind(this)):d.get_string("shownotificationwindownonew","message").done(function(a){this.menuToggle.attr("aria-label",a)}.bind(this))},l.prototype.getContent=function(){return this.container},l.prototype.getOffset=function(){return this.offset},l.prototype.incrementOffset=function(){this.offset+=this.limit},l.prototype.hasDoneInitialLoad=function(){return this.initialLoad},l.prototype.hasLoadedAllContent=function(){return this.loadedAll},l.prototype.setLoadedAllContent=function(a){this.loadedAll=a},l.prototype.renderUnreadCount=function(){var a=this.root.find(k.COUNT_CONTAINER);this.unreadCount?(a.text(this.unreadCount),a.removeClass("hidden")):a.addClass("hidden")},l.prototype.hideUnreadCount=function(){this.root.find(k.COUNT_CONTAINER).addClass("hidden")},l.prototype.loadUnreadNotificationCount=function(){i.countUnread({useridto:this.userId}).then(function(a){this.unreadCount=a,this.renderUnreadCount(),this.updateButtonAriaLabel()}.bind(this))["catch"](f.exception)},l.prototype.getNotificationElement=function(a){var b=this.root.find(k.NOTIFICATION+'[data-id="'+a+'"]');return 1==b.length?b:null},l.prototype.renderNotifications=function(b,d){var f=[];return a.each(b,function(a,b){var d=this.getOffset()-this.limit;b.viewmoreurl=e.relativeUrl("/message/output/popup/notifications.php",{notificationid:b.id,offset:d});var g=c.render("message_popup/notification_content_item",b).then(function(a,b){return{html:a,js:b}});f.push(g)}.bind(this)),a.when.apply(a,f).then(function(){a.each(arguments,function(a,b){d.append(b.html),c.runTemplateJS(b.js)})})},l.prototype.loadMoreNotifications=function(){if(this.isLoading||this.hasLoadedAllContent())return a.Deferred().resolve();this.startLoading();var b={limit:this.limit,offset:this.getOffset(),useridto:this.userId},c=this.getContent();return i.query(b).then(function(a){var b=a.notifications;return this.unreadCount=a.unreadcount,this.setLoadedAllContent(!b.length||b.length. + +/** + * Mark a notification read and redirect to the relevant content. + * + * @package message_popup + * @copyright 2018 Michael Hawkins + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(__DIR__ . '/../../../config.php'); + +require_login(null, false); + +if (isguestuser()) { + redirect($CFG->wwwroot); +} + +$notificationid = required_param('notificationid', PARAM_INT); +$redirecturl = optional_param('redirecturl', $CFG->wwwroot, PARAM_LOCALURL); +$notification = $DB->get_record('notifications', array('id' => $notificationid)); + +// Check notification belongs to this user. +if ($USER->id != $notification->useridto) { + redirect($CFG->wwwroot); +} + +\core_message\api::mark_notification_as_read($notification); +redirect($redirecturl);