Skip to content

Commit efc45c2

Browse files
author
Ryan Wyllie
committed
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.
1 parent 39ef515 commit efc45c2

File tree

8 files changed

+112
-26
lines changed

8 files changed

+112
-26
lines changed

message/amd/build/message_drawer.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

message/amd/build/message_drawer_view_contacts.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

message/amd/src/message_drawer.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -270,22 +270,18 @@ function(
270270
* @param {int} sendToUser Should we message someone now?
271271
* @param {int} conversationId The value of the conversation id, null if none
272272
*/
273-
var init = function(root, uniqueId, alwaysVisible, sendToUser, conversationId) {
273+
var init = function(root, uniqueId, alwaysVisible, route) {
274274
root = $(root);
275275
createRoutes(uniqueId, root);
276276
registerEventListeners(uniqueId, root, alwaysVisible);
277+
277278
if (alwaysVisible) {
278279
show(uniqueId, root);
279-
// Are we sending to a specific user?
280-
if (sendToUser) {
281-
// Check if a conversation already exists, if not, create one.
282-
if (conversationId) {
283-
Router.go(uniqueId, Routes.VIEW_CONVERSATION, conversationId);
284-
} else {
285-
Router.go(uniqueId, Routes.VIEW_CONVERSATION, null, 'create', sendToUser);
286-
}
287-
} else if (conversationId) { // We aren't sending to a specific user, but to a group conversation.
288-
Router.go(uniqueId, Routes.VIEW_CONVERSATION, conversationId);
280+
281+
if (route) {
282+
var routeParams = route.params || [];
283+
routeParams = [uniqueId, route.path].concat(routeParams);
284+
Router.go.apply(null, routeParams);
289285
}
290286
}
291287
};

message/amd/src/message_drawer_view_contacts.js

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ function(
6666
return body.find(SELECTORS.REQUESTS_SECTION_CONTAINER);
6767
};
6868

69+
/**
70+
* Get the element that triggers showing the contacts section.
71+
*
72+
* @param {Object} body Contacts page body element.
73+
* @return {Object}
74+
*/
75+
var getShowContactsAction = function(body) {
76+
return body.find(SELECTORS.ACTION_SHOW_CONTACTS_SECTION);
77+
};
78+
79+
/**
80+
* Get the element that triggers showing the requests section.
81+
*
82+
* @param {Object} body Contacts page body element.
83+
* @return {Object}
84+
*/
85+
var getShowRequestsAction = function(body) {
86+
return body.find(SELECTORS.ACTION_SHOW_REQUESTS_SECTION);
87+
};
88+
6989
/**
7090
* Check if the given section is visible.
7191
*
@@ -105,8 +125,8 @@ function(
105125
var registerEventListeners = function(body) {
106126
var contactsSection = getContactsSectionContainer(body);
107127
var requestsSection = getRequestsSectionContainer(body);
108-
var showContactsAction = body.find(SELECTORS.ACTION_SHOW_CONTACTS_SECTION);
109-
var showRequestsAction = body.find(SELECTORS.ACTION_SHOW_REQUESTS_SECTION);
128+
var showContactsAction = getShowContactsAction(body);
129+
var showRequestsAction = getShowRequestsAction(body);
110130

111131
showContactsAction.on('show.bs.tab', function() {
112132
ContactsSection.show(contactsSection);
@@ -126,9 +146,11 @@ function(
126146
* @param {string} namespace The route namespace.
127147
* @param {Object} header Contacts header container element.
128148
* @param {Object} body Contacts body container element.
149+
* @param {Object} footer Contacts footer container element.
150+
* @param {String|null} tab Tab to show, either 'requests' or 'contacts', if any.
129151
* @return {Object} jQuery promise
130152
*/
131-
var show = function(namespace, header, body) {
153+
var show = function(namespace, header, body, footer, tab) {
132154
body = $(body);
133155

134156
if (!body.attr('data-contacts-init')) {
@@ -139,6 +161,27 @@ function(
139161
var contactsSection = getContactsSectionContainer(body);
140162
var requestsSection = getRequestsSectionContainer(body);
141163

164+
if (tab) {
165+
var showContactsAction = getShowContactsAction(body);
166+
var showRequestsAction = getShowRequestsAction(body);
167+
168+
// Unfortunately we need to hardcode the class changes here rather than trigger
169+
// the bootstrap tab functionality because the bootstrap JS doesn't appear to be
170+
// loaded by this point which means the tab plugin isn't added and the event listeners
171+
// haven't been set up so we can't just trigger a click either.
172+
if (tab == 'requests') {
173+
showContactsAction.removeClass('active');
174+
contactsSection.removeClass('show active');
175+
showRequestsAction.addClass('active');
176+
requestsSection.addClass('show active');
177+
} else {
178+
showRequestsAction.removeClass('active');
179+
requestsSection.removeClass('show active');
180+
showContactsAction.addClass('active');
181+
contactsSection.addClass('show active');
182+
}
183+
}
184+
142185
if (isSectionVisible(contactsSection)) {
143186
ContactsSection.show(contactsSection);
144187
} else {

message/classes/helper.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,15 @@ public static function get_conversations_legacy_formatter(array $conversations)
687687
* @param bool $isdrawer Are we are rendering the drawer or is this on a full page?
688688
* @param int|null $sendtouser The ID of the user we want to send a message to
689689
* @param int|null $conversationid The ID of the conversation we want to load
690+
* @param string|null $view The first view to load in the message widget
690691
* @return string The HTML.
691692
*/
692-
public static function render_messaging_widget(bool $isdrawer, int $sendtouser = null, int $conversationid = null) {
693+
public static function render_messaging_widget(
694+
bool $isdrawer,
695+
int $sendtouser = null,
696+
int $conversationid = null,
697+
string $view = null
698+
) {
693699
global $USER, $CFG, $PAGE;
694700

695701
// Early bail out conditions.
@@ -765,18 +771,24 @@ public static function render_messaging_widget(bool $isdrawer, int $sendtouser =
765771
'messageurl' => $messageurl,
766772
'notification' => $notification
767773
],
768-
'sendtouser' => false,
769-
'conversationid' => false,
770774
'isdrawer' => $isdrawer
771775
];
772776

773-
if ($sendtouser) {
774-
$templatecontext['sendtouser'] = $sendtouser;
777+
if ($sendtouser || $conversationid) {
778+
$route = [
779+
'path' => 'view-conversation',
780+
'params' => $conversationid ? [$conversationid] : [null, 'create', $sendtouser]
781+
];
782+
} else if ($view === 'contactrequests') {
783+
$route = [
784+
'path' => 'view-contacts',
785+
'params' => ['requests']
786+
];
787+
} else {
788+
$route = null;
775789
}
776790

777-
if ($conversationid) {
778-
$templatecontext['conversationid'] = $conversationid;
779-
}
791+
$templatecontext['route'] = json_encode($route);
780792

781793
return $renderer->render_from_template($template, $templatecontext);
782794
}

message/index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
// The id of the user we want to view messages from.
3838
$id = optional_param('id', 0, PARAM_INT);
39+
$view = optional_param('view', null, PARAM_ALPHANUM);
3940
// It's possible a user may come from a link where these parameters are specified.
4041
// We no longer support viewing another user's messaging area (that can be achieved
4142
// via the 'Log-in as' feature). The 'user2' value takes preference over 'id'.
@@ -90,5 +91,5 @@
9091
\core\output\notification::NOTIFY_WARNING);
9192
echo $OUTPUT->render($notify);
9293
}
93-
echo \core_message\helper::render_messaging_widget(false, $userid, $conversationid);
94+
echo \core_message\helper::render_messaging_widget(false, $userid, $conversationid, $view);
9495
echo $OUTPUT->footer();

message/pendingcontactrequests.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* This is a placeholder file for a legacy implementation.
19+
*
20+
* @package core
21+
* @copyright 2019 Ryan Wyllie <[email protected]>
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
// Disable moodle specific debug messages since we're just redirecting.
26+
define('NO_DEBUG_DISPLAY', true);
27+
require('../config.php');
28+
29+
require_login(null, false);
30+
31+
// We have a bunch of old notifications (both internal and external, e.g. email) that
32+
// reference this URL which means we can't remove it so let's just redirect.
33+
redirect("{$CFG->wwwroot}/message/index.php?view=contactrequests");
34+

message/templates/message_index.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@
7979
{{#js}}
8080
require(['jquery', 'core_message/message_drawer'], function($, MessageDrawer) {
8181
var root = $('#message-index-{{uniqid}}');
82-
MessageDrawer.init(root, '{{uniqid}}', true, {{sendtouser}}, {{conversationid}});
82+
MessageDrawer.init(root, '{{uniqid}}', true, {{{route}}});
8383
});
8484
{{/js}}

0 commit comments

Comments
 (0)