Skip to content
Permalink
Browse files

MDL-63915 core_message: add the UI to the message/index.php page

  • Loading branch information...
markn86 committed Jan 18, 2019
1 parent cb01c45 commit fd998fc6f002790970f0bfc1a3e8e2155170d4bd
@@ -242,7 +242,6 @@
$string['userisblockingyounoncontact'] = '{$a} only accepts messages from their contacts.'; $string['userisblockingyounoncontact'] = '{$a} only accepts messages from their contacts.';
$string['userwouldliketocontactyou'] = '{$a} would like to contact you'; $string['userwouldliketocontactyou'] = '{$a} would like to contact you';
$string['viewfullnotification'] = 'View full notification'; $string['viewfullnotification'] = 'View full notification';
$string['viewinganotherusersmessagearea'] = 'You are viewing another user\'s message area.';
$string['viewmessageswith'] = 'View messages with {$a}'; $string['viewmessageswith'] = 'View messages with {$a}';
$string['viewnotificationresource'] = 'Go to: {$a}'; $string['viewnotificationresource'] = 'Go to: {$a}';
$string['viewunreadmessageswith'] = 'View unread messages with {$a}'; $string['viewunreadmessageswith'] = 'View unread messages with {$a}';

Some generated files are not rendered by default. Learn more.

@@ -155,8 +155,9 @@ function(
* *
* @param {string} namespace The route namespace. * @param {string} namespace The route namespace.
* @param {Object} root The message drawer container. * @param {Object} root The message drawer container.
* @param {bool} alwaysVisible Is this messaging app always shown?
*/ */
var registerEventListeners = function(namespace, root) { var registerEventListeners = function(namespace, root, alwaysVisible) {
CustomEvents.define(root, [CustomEvents.events.activate]); CustomEvents.define(root, [CustomEvents.events.activate]);
var paramRegex = /^data-route-param-?(\d*)$/; var paramRegex = /^data-route-param-?(\d*)$/;


@@ -205,21 +206,23 @@ function(
data.originalEvent.preventDefault(); data.originalEvent.preventDefault();
}); });


PubSub.subscribe(Events.SHOW, function() { if (!alwaysVisible) {
show(namespace, root); PubSub.subscribe(Events.SHOW, function() {
}); show(namespace, root);

});
PubSub.subscribe(Events.HIDE, function() {
hide(root);
});


PubSub.subscribe(Events.TOGGLE_VISIBILITY, function() { PubSub.subscribe(Events.HIDE, function() {
if (isVisible(root)) {
hide(root); hide(root);
} else { });
show(namespace, root);
} PubSub.subscribe(Events.TOGGLE_VISIBILITY, function() {
}); if (isVisible(root)) {
hide(root);
} else {
show(namespace, root);
}
});
}


PubSub.subscribe(Events.SHOW_CONVERSATION, function(conversationId) { PubSub.subscribe(Events.SHOW_CONVERSATION, function(conversationId) {
show(namespace, root); show(namespace, root);
@@ -254,11 +257,24 @@ function(
* *
* @param {Object} root The message drawer container. * @param {Object} root The message drawer container.
* @param {String} uniqueId Unique identifier for the Routes * @param {String} uniqueId Unique identifier for the Routes
* @param {bool} alwaysVisible Should we show the app now, or wait for the user?
* @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) { var init = function(root, uniqueId, alwaysVisible, sendToUser, conversationId) {
root = $(root); root = $(root);
createRoutes(uniqueId, root); createRoutes(uniqueId, root);
registerEventListeners(uniqueId, root); registerEventListeners(uniqueId, root, alwaysVisible);
if (alwaysVisible) {
show(uniqueId, root);
if (sendToUser) {
if (conversationId) {
Router.go(uniqueId, Routes.VIEW_CONVERSATION, conversationId);
} else {
Router.go(uniqueId, Routes.VIEW_CONVERSATION, null, 'create', sendToUser);
}
}
}
}; };


return { return {
@@ -642,4 +642,88 @@ public static function get_conversations_legacy_formatter(array $conversations)
} }
return $tmp; return $tmp;
} }
/**
* Renders the messaging widget.
*
* @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
* @return string The HTML.
*/
public static function render_messaging_widget(bool $isdrawer, int $sendtouser = null, int $conversationid = null) {
global $USER, $CFG, $PAGE;
// Early bail out conditions.
if (empty($CFG->messaging) || !isloggedin() || isguestuser() || user_not_fully_set_up($USER) ||
get_user_preferences('auth_forcepasswordchange') ||
(!$USER->policyagreed && !is_siteadmin() &&
($manager = new \core_privacy\local\sitepolicy\manager()) && $manager->is_defined())) {
return '';
}
$renderer = $PAGE->get_renderer('core');
$requestcount = \core_message\api::get_received_contact_requests_count($USER->id);
$contactscount = \core_message\api::count_contacts($USER->id);
$choices = [];
$choices[] = [
'value' => \core_message\api::MESSAGE_PRIVACY_ONLYCONTACTS,
'text' => get_string('contactableprivacy_onlycontacts', 'message')
];
$choices[] = [
'value' => \core_message\api::MESSAGE_PRIVACY_COURSEMEMBER,
'text' => get_string('contactableprivacy_coursemember', 'message')
];
if (!empty($CFG->messagingallusers)) {
// Add the MESSAGE_PRIVACY_SITE option when site-wide messaging between users is enabled.
$choices[] = [
'value' => \core_message\api::MESSAGE_PRIVACY_SITE,
'text' => get_string('contactableprivacy_site', 'message')
];
}
// Enter to send.
$entertosend = get_user_preferences('message_entertosend', $CFG->messagingdefaultpressenter, $USER);
if ($isdrawer) {
$template = 'core_message/message_drawer';
$messageurl = new \moodle_url('/message/index.php');
} else {
$template = 'core_message/message_index';
$messageurl = null;
}
$templatecontext = [
'contactrequestcount' => $requestcount,
'loggedinuser' => [
'id' => $USER->id,
'midnight' => usergetmidnight(time())
],
'contacts' => [
'sectioncontacts' => [
'placeholders' => array_fill(0, $contactscount > 50 ? 50 : $contactscount, true)
],
'sectionrequests' => [
'placeholders' => array_fill(0, $requestcount > 50 ? 50 : $requestcount, true)
],
],
'settings' => [
'privacy' => $choices,
'entertosend' => $entertosend
],
'overview' => [
'messageurl' => $messageurl
],
'sendtouser' => false,
'conversationid' => false
];
if ($sendtouser) {
$templatecontext['sendtouser'] = $sendtouser;
$templatecontext['conversationid'] = $conversationid;
}
return $renderer->render_from_template($template, $templatecontext);
}
} }

0 comments on commit fd998fc

Please sign in to comment.
You can’t perform that action at this time.