From 46014b8343078085f96088bdebb7fa64db2eeb9e Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 5 Feb 2019 13:03:07 +0800 Subject: [PATCH] MDL-64093 core: added new 'messagingdefaultpressenter' setting --- admin/settings/subsystems.php | 6 ++++++ lang/en/admin.php | 2 ++ lib/db/upgrade.php | 8 ++++++++ message/externallib.php | 6 ++++-- message/lib.php | 2 +- version.php | 2 +- 6 files changed, 22 insertions(+), 4 deletions(-) diff --git a/admin/settings/subsystems.php b/admin/settings/subsystems.php index a108b4277a9..b559de31e3b 100644 --- a/admin/settings/subsystems.php +++ b/admin/settings/subsystems.php @@ -21,6 +21,12 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page 0) ); + $optionalsubsystems->add(new admin_setting_configcheckbox('messagingdefaultpressenter', + new lang_string('messagingdefaultpressenter', 'admin'), + new lang_string('configmessagingdefaultpressenter', 'admin'), + 1) + ); + $options = array( DAYSECS => new lang_string('secondstotime86400'), WEEKSECS => new lang_string('secondstotime604800'), diff --git a/lang/en/admin.php b/lang/en/admin.php index 707818cd554..0cedfb063af 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -279,6 +279,7 @@ $string['configmaxeditingtime'] = 'This specifies the amount of time people have $string['configmaxevents'] = 'Events to Lookahead'; $string['configmessaging'] = 'If enabled, users can send messages to other users on the site.'; $string['configmessagingallowemailoverride'] = 'Allow users to have email message notifications sent to an email address other than the email address in their profile'; +$string['configmessagingdefaultpressenter'] = 'Whether \'Use enter to send\' is enabled by default in users\' messaging settings.'; $string['configmessagingdeletereadnotificationsdelay'] = 'Read notifications can be deleted to save space. How long after a notification is read can it be deleted?'; $string['configmessagingdeleteallnotificationsdelay'] = 'Read and unread notifications can be deleted to save space. How long after a notification is created can it be deleted?'; $string['configmessagingallusers'] = 'If enabled, users can view the list of all users on the site when selecting someone to message, and their message preferences include the option to accept messages from anyone on the site. If disabled, users can only view the list of users in their courses, and they have just two options in message preferences - to accept messages from their contacts only, or their contacts and anyone in their courses.'; @@ -772,6 +773,7 @@ $string['mediapluginyoutube'] = 'Enable YouTube links filter'; $string['messaging'] = 'Enable messaging system'; $string['messagingallowemailoverride'] = 'Notification email override'; $string['messagingallusers'] = 'Allow site-wide messaging'; +$string['messagingdefaultpressenter'] = 'Use enter to send enabled by default'; $string['messagingdeletereadnotificationsdelay'] = 'Delete read notifications'; $string['messagingdeleteallnotificationsdelay'] = 'Delete all notifications'; $string['minpassworddigits'] = 'Digits'; diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index cf8ad44ffe4..fc5dac57f20 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2719,5 +2719,13 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2019011801.03); } + if ($oldversion < 2019020100.01) { + // Default 'off' for existing sites as this is the behaviour they had earlier. + set_config('messagingdefaultpressenter', false); + + // Main savepoint reached. + upgrade_main_savepoint(true, 2019020100.01); + } + return true; } diff --git a/message/externallib.php b/message/externallib.php index c9c6631cfe2..588a4d4c2ba 100644 --- a/message/externallib.php +++ b/message/externallib.php @@ -4160,7 +4160,7 @@ class core_message_external extends external_api { * @since 3.2 */ public static function get_user_message_preferences($userid = 0) { - global $PAGE; + global $CFG, $PAGE; $params = self::validate_parameters( self::get_user_message_preferences_parameters(), @@ -4189,11 +4189,13 @@ class core_message_external extends external_api { $renderer = $PAGE->get_renderer('core_message'); + $entertosend = get_user_preferences('message_entertosend', $CFG->messagingdefaultpressenter, $user); + $result = array( 'warnings' => array(), 'preferences' => $notificationlistoutput->export_for_template($renderer), 'blocknoncontacts' => \core_message\api::get_user_privacy_messaging_preference($user->id), - 'entertosend' => get_user_preferences('message_entertosend', false, $user) + 'entertosend' => $entertosend ); return $result; } diff --git a/message/lib.php b/message/lib.php index 474b27429fe..37f77398651 100644 --- a/message/lib.php +++ b/message/lib.php @@ -855,7 +855,7 @@ function core_message_standard_after_main_region_html() { } // Enter to send. - $entertosend = get_user_preferences('message_entertosend', false, $USER); + $entertosend = get_user_preferences('message_entertosend', $CFG->messagingdefaultpressenter, $USER); return $renderer->render_from_template('core_message/message_drawer', [ 'contactrequestcount' => $requestcount, diff --git a/version.php b/version.php index 7c6db743a52..24ebb757edf 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2019020800.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2019020800.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.