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.
This commit is contained in:
Ryan Wyllie
2019-07-23 11:37:55 +08:00
parent 8d9614b341
commit 6cb33ce774
8 changed files with 111 additions and 26 deletions
+1 -1
View File
@@ -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;i<e[0].attributes.length;i++)h.push(e[0].attributes[i]);var j=h.filter(function(a){var b=a.nodeName,c=g.test(b);return c});j.sort(function(a,b){var c=g.exec(a.nodeName),d=g.exec(b.nodeName),e=c.length>1?c[1]:0,f=d.length>1?d[1]:0;return e<f?-1:f<e?1:0});var l=j.map(function(a){return a.nodeValue}),m=[d,f].concat(l);k.go.apply(null,m),c.originalEvent.preventDefault()}),e.on(b.events.activate,n.ROUTES_BACK,function(a,b){k.back(d),b.originalEvent.preventDefault()}),f||(c.subscribe(m.SHOW,function(){r(d,e)}),c.subscribe(m.HIDE,function(){s(e)}),c.subscribe(m.TOGGLE_VISIBILITY,function(){t(e)?s(e):r(d,e)})),c.subscribe(m.SHOW_CONVERSATION,function(a){r(d,e),k.go(d,l.VIEW_CONVERSATION,a)}),c.subscribe(m.CREATE_CONVERSATION_WITH_USER,function(a){r(d,e),k.go(d,l.VIEW_CONVERSATION,null,"create",a)}),c.subscribe(m.SHOW_SETTINGS,function(){r(d,e),k.go(d,l.VIEW_SETTINGS)}),c.subscribe(m.PREFERENCES_UPDATED,function(a){var b=a.filter(function(a){return"message_entertosend"==a.type}),c=b.length?b[0]:null;if(c){var d=e.find(n.FOOTER_CONTAINER).find(n.VIEW_CONVERSATION);d.attr("data-enter-to-send",c.value)}})},v=function(b,c,d,e,f){b=a(b),q(c,b),u(c,b,d),d&&(r(c,b),e?f?k.go(c,l.VIEW_CONVERSATION,f):k.go(c,l.VIEW_CONVERSATION,null,"create",e):f&&k.go(c,l.VIEW_CONVERSATION,f))};return{init:v}});
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;i<e[0].attributes.length;i++)h.push(e[0].attributes[i]);var j=h.filter(function(a){var b=a.nodeName,c=g.test(b);return c});j.sort(function(a,b){var c=g.exec(a.nodeName),d=g.exec(b.nodeName),e=c.length>1?c[1]:0,f=d.length>1?d[1]:0;return e<f?-1:f<e?1:0});var l=j.map(function(a){return a.nodeValue}),m=[d,f].concat(l);k.go.apply(null,m),c.originalEvent.preventDefault()}),e.on(b.events.activate,n.ROUTES_BACK,function(a,b){k.back(d),b.originalEvent.preventDefault()}),f||(c.subscribe(m.SHOW,function(){r(d,e)}),c.subscribe(m.HIDE,function(){s(e)}),c.subscribe(m.TOGGLE_VISIBILITY,function(){t(e)?s(e):r(d,e)})),c.subscribe(m.SHOW_CONVERSATION,function(a){r(d,e),k.go(d,l.VIEW_CONVERSATION,a)}),c.subscribe(m.CREATE_CONVERSATION_WITH_USER,function(a){r(d,e),k.go(d,l.VIEW_CONVERSATION,null,"create",a)}),c.subscribe(m.SHOW_SETTINGS,function(){r(d,e),k.go(d,l.VIEW_SETTINGS)}),c.subscribe(m.PREFERENCES_UPDATED,function(a){var b=a.filter(function(a){return"message_entertosend"==a.type}),c=b.length?b[0]:null;if(c){var d=e.find(n.FOOTER_CONTAINER).find(n.VIEW_CONVERSATION);d.attr("data-enter-to-send",c.value)}})},v=function(b,c,d,e){if(b=a(b),q(c,b),u(c,b,d),d&&(r(c,b),e)){var f=e.params||[];f=[c,e.path].concat(f),k.go.apply(null,f)}};return{init:v}});
+1 -1
View File
@@ -1 +1 @@
define(["jquery","core/pubsub","core/str","core_message/message_drawer_events","core_message/message_drawer_view_contacts_section_contacts","core_message/message_drawer_view_contacts_section_requests"],function(a,b,c,d,e,f){var g={ACTION_SHOW_CONTACTS_SECTION:'[data-action="show-contacts-section"]',ACTION_SHOW_REQUESTS_SECTION:'[data-action="show-requests-section"]',CONTACT_REQUEST_COUNT:'[data-region="contact-request-count"]',CONTACTS_SECTION_CONTAINER:'[data-section="contacts"]',REQUESTS_SECTION_CONTAINER:'[data-section="requests"]'},h=function(a){return a.find(g.CONTACTS_SECTION_CONTAINER)},i=function(a){return a.find(g.REQUESTS_SECTION_CONTAINER)},j=function(a){return a.hasClass("active")},k=function(a){return function(){var b=a.find(g.CONTACT_REQUEST_COUNT),c=parseInt(b.text(),10);c=isNaN(c)?0:c-1,c<=0?b.addClass("hidden"):b.text(c)}},l=function(a){var c=h(a),j=i(a),l=a.find(g.ACTION_SHOW_CONTACTS_SECTION),m=a.find(g.ACTION_SHOW_REQUESTS_SECTION);l.on("show.bs.tab",function(){e.show(c)}),m.on("show.bs.tab",function(){f.show(j)}),b.subscribe(d.CONTACT_REQUEST_ACCEPTED,k(a)),b.subscribe(d.CONTACT_REQUEST_DECLINED,k(a))},m=function(b,c,d){d=a(d),d.attr("data-contacts-init")||(l(d),d.attr("data-contacts-init",!0));var g=h(d),k=i(d);return j(g)?e.show(g):f.show(k),a.Deferred().resolve().promise()},n=function(){return c.get_string("messagedrawerviewcontacts","core_message")};return{show:m,description:n}});
define(["jquery","core/pubsub","core/str","core_message/message_drawer_events","core_message/message_drawer_view_contacts_section_contacts","core_message/message_drawer_view_contacts_section_requests"],function(a,b,c,d,e,f){var g={ACTION_SHOW_CONTACTS_SECTION:'[data-action="show-contacts-section"]',ACTION_SHOW_REQUESTS_SECTION:'[data-action="show-requests-section"]',CONTACT_REQUEST_COUNT:'[data-region="contact-request-count"]',CONTACTS_SECTION_CONTAINER:'[data-section="contacts"]',REQUESTS_SECTION_CONTAINER:'[data-section="requests"]'},h=function(a){return a.find(g.CONTACTS_SECTION_CONTAINER)},i=function(a){return a.find(g.REQUESTS_SECTION_CONTAINER)},j=function(a){return a.find(g.ACTION_SHOW_CONTACTS_SECTION)},k=function(a){return a.find(g.ACTION_SHOW_REQUESTS_SECTION)},l=function(a){return a.hasClass("active")},m=function(a){return function(){var b=a.find(g.CONTACT_REQUEST_COUNT),c=parseInt(b.text(),10);c=isNaN(c)?0:c-1,c<=0?b.addClass("hidden"):b.text(c)}},n=function(a){var c=h(a),g=i(a),l=j(a),n=k(a);l.on("show.bs.tab",function(){e.show(c)}),n.on("show.bs.tab",function(){f.show(g)}),b.subscribe(d.CONTACT_REQUEST_ACCEPTED,m(a)),b.subscribe(d.CONTACT_REQUEST_DECLINED,m(a))},o=function(b,c,d,g,m){d=a(d),d.attr("data-contacts-init")||(n(d),d.attr("data-contacts-init",!0));var o=h(d),p=i(d);if(m){var q=j(d),r=k(d);"requests"==m?(q.removeClass("active"),o.removeClass("show active"),r.addClass("active"),p.addClass("show active")):(r.removeClass("active"),p.removeClass("show active"),q.addClass("active"),o.addClass("show active"))}return l(o)?e.show(o):f.show(p),a.Deferred().resolve().promise()},p=function(){return c.get_string("messagedrawerviewcontacts","core_message")};return{show:o,description:p}});
+7 -11
View File
@@ -270,22 +270,18 @@ function(
* @param {int} sendToUser Should we message someone now?
* @param {int} conversationId The value of the conversation id, null if none
*/
var init = function(root, uniqueId, alwaysVisible, sendToUser, conversationId) {
var init = function(root, uniqueId, alwaysVisible, route) {
root = $(root);
createRoutes(uniqueId, root);
registerEventListeners(uniqueId, root, alwaysVisible);
if (alwaysVisible) {
show(uniqueId, root);
// Are we sending to a specific user?
if (sendToUser) {
// Check if a conversation already exists, if not, create one.
if (conversationId) {
Router.go(uniqueId, Routes.VIEW_CONVERSATION, conversationId);
} else {
Router.go(uniqueId, Routes.VIEW_CONVERSATION, null, 'create', sendToUser);
}
} else if (conversationId) { // We aren't sending to a specific user, but to a group conversation.
Router.go(uniqueId, Routes.VIEW_CONVERSATION, conversationId);
if (route) {
var routeParams = route.params || [];
routeParams = [uniqueId, route.path].concat(routeParams);
Router.go.apply(null, routeParams);
}
}
};
@@ -66,6 +66,26 @@ function(
return body.find(SELECTORS.REQUESTS_SECTION_CONTAINER);
};
/**
* Get the element that triggers showing the contacts section.
*
* @param {Object} body Contacts page body element.
* @return {Object}
*/
var getShowContactsAction = function(body) {
return body.find(SELECTORS.ACTION_SHOW_CONTACTS_SECTION);
};
/**
* Get the element that triggers showing the requests section.
*
* @param {Object} body Contacts page body element.
* @return {Object}
*/
var getShowRequestsAction = function(body) {
return body.find(SELECTORS.ACTION_SHOW_REQUESTS_SECTION);
};
/**
* Check if the given section is visible.
*
@@ -105,8 +125,8 @@ function(
var registerEventListeners = function(body) {
var contactsSection = getContactsSectionContainer(body);
var requestsSection = getRequestsSectionContainer(body);
var showContactsAction = body.find(SELECTORS.ACTION_SHOW_CONTACTS_SECTION);
var showRequestsAction = body.find(SELECTORS.ACTION_SHOW_REQUESTS_SECTION);
var showContactsAction = getShowContactsAction(body);
var showRequestsAction = getShowRequestsAction(body);
showContactsAction.on('show.bs.tab', function() {
ContactsSection.show(contactsSection);
@@ -126,9 +146,11 @@ function(
* @param {string} namespace The route namespace.
* @param {Object} header Contacts header container element.
* @param {Object} body Contacts body container element.
* @param {Object} footer Contacts footer container element.
* @param {String|null} tab Tab to show, either 'requests' or 'contacts', if any.
* @return {Object} jQuery promise
*/
var show = function(namespace, header, body) {
var show = function(namespace, header, body, footer, tab) {
body = $(body);
if (!body.attr('data-contacts-init')) {
@@ -139,6 +161,27 @@ function(
var contactsSection = getContactsSectionContainer(body);
var requestsSection = getRequestsSectionContainer(body);
if (tab) {
var showContactsAction = getShowContactsAction(body);
var showRequestsAction = getShowRequestsAction(body);
// Unfortunately we need to hardcode the class changes here rather than trigger
// the bootstrap tab functionality because the bootstrap JS doesn't appear to be
// loaded by this point which means the tab plugin isn't added and the event listeners
// haven't been set up so we can't just trigger a click either.
if (tab == 'requests') {
showContactsAction.removeClass('active');
contactsSection.removeClass('show active');
showRequestsAction.addClass('active');
requestsSection.addClass('show active');
} else {
showRequestsAction.removeClass('active');
requestsSection.removeClass('show active');
showContactsAction.addClass('active');
contactsSection.addClass('show active');
}
}
if (isSectionVisible(contactsSection)) {
ContactsSection.show(contactsSection);
} else {
+20 -8
View File
@@ -687,9 +687,15 @@ class helper {
* @param bool $isdrawer Are we are rendering the drawer or is this on a full page?
* @param int|null $sendtouser The ID of the user we want to send a message to
* @param int|null $conversationid The ID of the conversation we want to load
* @param string|null $view The first view to load in the message widget
* @return string The HTML.
*/
public static function render_messaging_widget(bool $isdrawer, int $sendtouser = null, int $conversationid = null) {
public static function render_messaging_widget(
bool $isdrawer,
int $sendtouser = null,
int $conversationid = null,
string $view = null
) {
global $USER, $CFG, $PAGE;
// Early bail out conditions.
@@ -765,18 +771,24 @@ class helper {
'messageurl' => $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);
}
+2 -1
View File
@@ -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();
+33
View File
@@ -0,0 +1,33 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This is a placeholder file for a legacy implementation.
*
* @package core
* @copyright 2019 Ryan Wyllie <[email protected]>
* @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");
+1 -1
View File
@@ -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}}