From 6cb33ce7743d02938ced2a8646ea0e44c9bbdc0a Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Thu, 11 Jul 2019 15:27:43 +0800 Subject: [PATCH 1/2] MDL-65219 message: add message/pendingcontactrequests.php page back We previously had this page when contact requests were first introduced and unfortunately we created a bunch of notifications that reference this URL directly which now won't work because the page has been removed. I've added it back but set it to redirect to the message/index.php page and load the contact requests page there. --- message/amd/build/message_drawer.min.js | 2 +- .../build/message_drawer_view_contacts.min.js | 2 +- message/amd/src/message_drawer.js | 18 +++---- .../amd/src/message_drawer_view_contacts.js | 49 +++++++++++++++++-- message/classes/helper.php | 28 ++++++++--- message/index.php | 3 +- message/pendingcontactrequests.php | 33 +++++++++++++ message/templates/message_index.mustache | 2 +- 8 files changed, 111 insertions(+), 26 deletions(-) create mode 100644 message/pendingcontactrequests.php diff --git a/message/amd/build/message_drawer.min.js b/message/amd/build/message_drawer.min.js index 4c5809eab13..1049c16704a 100644 --- a/message/amd/build/message_drawer.min.js +++ b/message/amd/build/message_drawer.min.js @@ -1 +1 @@ -define(["jquery","core/custom_interaction_events","core/pubsub","core_message/message_drawer_view_contact","core_message/message_drawer_view_contacts","core_message/message_drawer_view_conversation","core_message/message_drawer_view_group_info","core_message/message_drawer_view_overview","core_message/message_drawer_view_search","core_message/message_drawer_view_settings","core_message/message_drawer_router","core_message/message_drawer_routes","core_message/message_drawer_events"],function(a,b,c,d,e,f,g,h,i,j,k,l,m){var n={PANEL_BODY_CONTAINER:'[data-region="panel-body-container"]',PANEL_HEADER_CONTAINER:'[data-region="panel-header-container"]',VIEW_CONTACT:'[data-region="view-contact"]',VIEW_CONTACTS:'[data-region="view-contacts"]',VIEW_CONVERSATION:'[data-region="view-conversation"]',VIEW_GROUP_INFO:'[data-region="view-group-info"]',VIEW_OVERVIEW:'[data-region="view-overview"]',VIEW_SEARCH:'[data-region="view-search"]',VIEW_SETTINGS:'[data-region="view-settings"]',ROUTES:"[data-route]",ROUTES_BACK:"[data-route-back]",HEADER_CONTAINER:'[data-region="header-container"]',BODY_CONTAINER:'[data-region="body-container"]',FOOTER_CONTAINER:'[data-region="footer-container"]'},o=function(a,b,c){var d=b.find(n.HEADER_CONTAINER).find(c);d.length||(d=b.find(n.PANEL_HEADER_CONTAINER).find(c));var e=b.find(n.BODY_CONTAINER).find(c);e.length||(e=b.find(n.PANEL_BODY_CONTAINER).find(c));var f=b.find(n.FOOTER_CONTAINER).find(c);return[a,d.length?d:null,e.length?e:null,f.length?f:null]},p=[[l.VIEW_CONTACT,n.VIEW_CONTACT,d.show,d.description],[l.VIEW_CONTACTS,n.VIEW_CONTACTS,e.show,e.description],[l.VIEW_CONVERSATION,n.VIEW_CONVERSATION,f.show,f.description],[l.VIEW_GROUP_INFO,n.VIEW_GROUP_INFO,g.show,g.description],[l.VIEW_OVERVIEW,n.VIEW_OVERVIEW,h.show,h.description],[l.VIEW_SEARCH,n.VIEW_SEARCH,i.show,i.description],[l.VIEW_SETTINGS,n.VIEW_SETTINGS,j.show,j.description]],q=function(a,b){p.forEach(function(c){k.add(a,c[0],o(a,b,c[1]),c[2],c[3])})},r=function(a,b){b.attr("data-shown")||(k.go(a,l.VIEW_OVERVIEW),b.attr("data-shown",!0)),b.removeClass("hidden"),b.attr("aria-expanded",!0),b.attr("aria-hidden",!1)},s=function(a){a.addClass("hidden"),a.attr("aria-expanded",!1),a.attr("aria-hidden",!0)},t=function(a){return!a.hasClass("hidden")},u=function(d,e,f){b.define(e,[b.events.activate]);var g=/^data-route-param-?(\d*)$/;e.on(b.events.activate,n.ROUTES,function(b,c){for(var e=a(b.target).closest(n.ROUTES),f=e.attr("data-route"),h=[],i=0;i1?c[1]:0,f=d.length>1?d[1]:0;return e1?c[1]:0,f=d.length>1?d[1]:0;return e $messageurl, 'notification' => $notification ], - 'sendtouser' => false, - 'conversationid' => false, 'isdrawer' => $isdrawer ]; - if ($sendtouser) { - $templatecontext['sendtouser'] = $sendtouser; + if ($sendtouser || $conversationid) { + $route = [ + 'path' => 'view-conversation', + 'params' => $conversationid ? [$conversationid] : [null, 'create', $sendtouser] + ]; + } else if ($view === 'contactrequests') { + $route = [ + 'path' => 'view-contacts', + 'params' => ['requests'] + ]; + } else { + $route = null; } - if ($conversationid) { - $templatecontext['conversationid'] = $conversationid; - } + $templatecontext['route'] = json_encode($route); return $renderer->render_from_template($template, $templatecontext); } diff --git a/message/index.php b/message/index.php index ebc1f2776cb..1fcac5ab2b7 100644 --- a/message/index.php +++ b/message/index.php @@ -36,6 +36,7 @@ if (empty($CFG->messaging)) { // The id of the user we want to view messages from. $id = optional_param('id', 0, PARAM_INT); +$view = optional_param('view', null, PARAM_ALPHANUM); // It's possible a user may come from a link where these parameters are specified. // We no longer support viewing another user's messaging area (that can be achieved // via the 'Log-in as' feature). The 'user2' value takes preference over 'id'. @@ -90,5 +91,5 @@ if (!get_user_preferences('core_message_migrate_data', false)) { \core\output\notification::NOTIFY_WARNING); echo $OUTPUT->render($notify); } -echo \core_message\helper::render_messaging_widget(false, $userid, $conversationid); +echo \core_message\helper::render_messaging_widget(false, $userid, $conversationid, $view); echo $OUTPUT->footer(); diff --git a/message/pendingcontactrequests.php b/message/pendingcontactrequests.php new file mode 100644 index 00000000000..df52d920d44 --- /dev/null +++ b/message/pendingcontactrequests.php @@ -0,0 +1,33 @@ +. + +/** + * This is a placeholder file for a legacy implementation. + * + * @package core + * @copyright 2019 Ryan Wyllie + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +// Disable moodle specific debug messages since we're just redirecting. +define('NO_DEBUG_DISPLAY', true); +require('../config.php'); + +require_login(null, false); + +// We have a bunch of old notifications (both internal and external, e.g. email) that +// reference this URL which means we can't remove it so let's just redirect. +redirect("{$CFG->wwwroot}/message/index.php?view=contactrequests"); diff --git a/message/templates/message_index.mustache b/message/templates/message_index.mustache index 52fc66cae10..65c44fc6288 100644 --- a/message/templates/message_index.mustache +++ b/message/templates/message_index.mustache @@ -79,6 +79,6 @@ {{#js}} require(['jquery', 'core_message/message_drawer'], function($, MessageDrawer) { var root = $('#message-index-{{uniqid}}'); - MessageDrawer.init(root, '{{uniqid}}', true, {{sendtouser}}, {{conversationid}}); + MessageDrawer.init(root, '{{uniqid}}', true, {{{route}}}); }); {{/js}} \ No newline at end of file From 5d61b3b331a87109fa53f6751340c8e11bc796a9 Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Mon, 15 Jul 2019 14:30:58 +0800 Subject: [PATCH 2/2] MDL-65219 message: default disable contact request notifications for web Set the default state to disabled for message contact request notifications for the web process. The user is notified about contact requests in the message drawer so it's unnecessary to also generate a notification in the notification popover for them. --- lib/db/messages.php | 3 ++- lib/db/upgrade.php | 16 ++++++++++++++++ version.php | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/db/messages.php b/lib/db/messages.php index d3473bba7e4..3ae3810c3d4 100644 --- a/lib/db/messages.php +++ b/lib/db/messages.php @@ -121,7 +121,8 @@ $messageproviders = array ( // Message contact requests. 'messagecontactrequests' => [ 'defaults' => [ - 'popup' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF, + // We don't need to notify in the popup output here because the message drawer + // already notifies users of contact requests. 'email' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDOFF, 'airnotifier' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF, ] diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 048ae58cb56..0998df7e91f 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3416,5 +3416,21 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2019070400.01); } + if ($oldversion < 2019071800.01) { + // Remove the "popup" processor from the list of default processors for the messagecontactrequests notification. + $oldloggedinconfig = get_config('message', 'message_provider_moodle_messagecontactrequests_loggedin'); + $oldloggedoffconfig = get_config('message', 'message_provider_moodle_messagecontactrequests_loggedoff'); + $newloggedinconfig = implode(',', array_filter(explode(',', $oldloggedinconfig), function($value) { + return $value != 'popup'; + })); + $newloggedoffconfig = implode(',', array_filter(explode(',', $oldloggedoffconfig), function($value) { + return $value != 'popup'; + })); + set_config('message_provider_moodle_messagecontactrequests_loggedin', $newloggedinconfig, 'message'); + set_config('message_provider_moodle_messagecontactrequests_loggedoff', $newloggedoffconfig, 'message'); + + upgrade_main_savepoint(true, 2019071800.01); + } + return true; } diff --git a/version.php b/version.php index 572c371c5b2..a3edfce2474 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2019071800.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2019071800.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.