$string['unreadnotification'] = 'Unread notification: {$a}';
$string['unreadnewgroupconversationmessage'] = 'New message from {$a->name} in {$a->conversationname}';
$string['unreadnewmessage'] = 'New message from {$a}';
+$string['useentertosend'] = 'Use enter to send';
$string['usercantbemessaged'] = 'You can\'t message {$a} due to their message preferences. Try adding them as a contact.';
$string['userisblockingyou'] = 'This user has blocked you from sending messages to them';
$string['userisblockingyounoncontact'] = '{$a} only accepts messages from their contacts.';
CONVERSATION_READ: 'message-drawer-conversation-read',
CONVERSATION_SET_FAVOURITE: 'message-drawer-conversation-set-favourite',
CONVERSATION_UNSET_FAVOURITE: 'message-drawer-conversation-unset-favourite',
+ PREFERENCES_UPDATED: 'message-drawer-preferences-updated',
ROUTE_CHANGED: 'message-drawer-route-change',
SHOW: 'message-drawer-show',
HIDE: 'message-drawer-hide',
CustomEvents.events.activate
]);
CustomEvents.define(footer, [
- CustomEvents.events.activate
+ CustomEvents.events.activate,
+ CustomEvents.events.enter
]);
CustomEvents.define(messagesContainer, [
CustomEvents.events.scrollTop,
footer.on(CustomEvents.events.activate, selector, handlerFunction);
});
+ footer.on(CustomEvents.events.enter, SELECTORS.MESSAGE_TEXT_AREA, function(e, data) {
+ var enterToSend = footer.attr('data-enter-to-send');
+ if (enterToSend == true) {
+ handleSendMessage(e, data);
+ }
+ });
+
PubSub.subscribe(MessageDrawerEvents.ROUTE_CHANGED, function(newRouteData) {
if (newMessagesPollTimer) {
if (newRouteData.route == MessageDrawerRoutes.VIEW_CONVERSATION) {
}
}
});
+
+ PubSub.subscribe(MessageDrawerEvents.PREFERENCES_UPDATED, function(preferences) {
+ var filteredPreferences = preferences.filter(function(preference) {
+ return preference.type == 'message_entertosend';
+ });
+ var enterToSendPreference = filteredPreferences.length ? filteredPreferences[0] : null;
+
+ if (enterToSendPreference) {
+ footer.attr('data-enter-to-send', enterToSendPreference.value);
+ }
+ });
};
/**
'jquery',
'core/notification',
'core/str',
+ 'core/pubsub',
'core_message/message_repository',
'core/custom_interaction_events',
+ 'core_message/message_drawer_events'
],
function(
$,
Notification,
Str,
+ PubSub,
Repository,
- CustomEvents
+ CustomEvents,
+ MessageDrawerEvents
) {
var SELECTORS = {
SETTINGS: '[data-region="settings"]',
PREFERENCE_CONTROL: '[data-region="preference-control"]',
PRIVACY_PREFERENCE: '[data-preference="blocknoncontacts"] input[type="radio"]',
- EMAIL_ENABLED_PREFERENCE: '[data-preference="emailnotifications"] input[type="checkbox"]'
+ EMAIL_ENABLED_PREFERENCE: '[data-preference="emailnotifications"] input[type="checkbox"]',
+ ENTER_TO_SEND_PREFERENCE: '[data-preference="entertosend"] input[type="checkbox"]',
};
var PREFERENCES_EMAIL = {
}, []);
Repository.savePreferences(loggedInUserId, preferences)
+ .then(function() {
+ PubSub.publish(MessageDrawerEvents.PREFERENCES_UPDATED, preferences);
+ return;
+ })
.catch(Notification.exception);
}
);
];
Repository.savePreferences(loggedInUserId, preferences)
+ .then(function() {
+ PubSub.publish(MessageDrawerEvents.PREFERENCES_UPDATED, preferences);
+ return;
+ })
+ .catch(Notification.exception);
+ }
+ );
+
+ settingsContainer.on(CustomEvents.events.activate, SELECTORS.ENTER_TO_SEND_PREFERENCE, function(e) {
+ var newValue = $(e.target).prop('checked');
+ var preferences = [
+ {
+ type: 'message_entertosend',
+ value: newValue
+ }
+ ];
+
+ Repository.savePreferences(loggedInUserId, preferences)
+ .then(function() {
+ PubSub.publish(MessageDrawerEvents.PREFERENCES_UPDATED, preferences);
+ return;
+ })
.catch(Notification.exception);
}
);
public static function export_user_preferences(int $userid) {
$preferences = get_user_preferences(null, null, $userid);
foreach ($preferences as $name => $value) {
- if ((substr($name, 0, 16) == 'message_provider') || ($name == 'message_blocknoncontacts')) {
+ if (
+ (substr($name, 0, 16) == 'message_provider') ||
+ ($name == 'message_blocknoncontacts') ||
+ ($name == 'message_entertosend')
+ ) {
writer::export_user_preference(
'core_message',
$name,
return $value;
}
);
+ $preferences['message_entertosend'] = array(
+ 'type' => PARAM_BOOL,
+ 'null' => NULL_NOT_ALLOWED,
+ 'default' => false
+ );
$preferences['/^message_provider_([\w\d_]*)_logged(in|off)$/'] = array('isregex' => true, 'type' => PARAM_NOTAGS,
'null' => NULL_NOT_ALLOWED, 'default' => 'none',
'permissioncallback' => function ($user, $preferencename) {
$emailloggedoff = get_user_preferences('message_provider_moodle_instantmessage_loggedoff', 'none', $USER->id);
$emailenabled = $emailloggedin == 'email' && $emailloggedoff == 'email';
+ // Enter to send.
+ $entertosend = get_user_preferences('message_entertosend', false, $USER->id);
+
return $renderer->render_from_template('core_message/message_drawer', [
'contactrequestcount' => $requestcount,
'loggedinuser' => [
],
'settings' => [
'privacy' => $choices,
- 'emailenabled' => $emailenabled
+ 'emailenabled' => $emailenabled,
+ 'entertosend' => $entertosend
]
]);
}
class="hidden border-top bg-white position-relative"
aria-hidden="true"
data-region="view-conversation"
+ data-enter-to-send="{{settings.entertosend}}"
>
<div class="hidden p-2" data-region="content-messages-footer-container">
{{> core_message/message_drawer_view_conversation_footer_content }}
</div>
{{/privacy}}
</div>
- <h3 class="mb-2 mt-5 h6 font-weight-bold">{{#str}}categoryemail, admin{{/str}}</h3>
+ <h3 class="mb-2 mt-4 h6 font-weight-bold">{{#str}}categoryemail, admin{{/str}}</h3>
<div
data-region="preference-control"
data-preference="emailnotifications"
</label>
</span>
</div>
+ <h3 class="mb-2 mt-4 h6 font-weight-bold">{{#str}} general, core {{/str}}</h3>
+ <div
+ data-region="preference-control"
+ data-preference="entertosend"
+ >
+ <span class="switch">
+ <input type="checkbox"
+ id="enter-to-send-{{uniqid}}"
+ {{#entertosend}}checked{{/entertosend}}
+ >
+ <label for="enter-to-send-{{uniqid}}">
+ {{#str}} useentertosend, core_message {{/str}}
+ </label>
+ </span>
+ </div>
</div>
{{/settings}}
</div>
\ No newline at end of file
set_user_preference('message_provider_moodle_instantmessage_loggedin', 'airnotifier', $USER->id);
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'popup', $USER->id);
set_user_preference('message_blocknoncontacts', \core_message\api::MESSAGE_PRIVACY_ONLYCONTACTS, $USER->id);
+ set_user_preference('message_entertosend', true, $USER->id);
set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'inbound', $user->id);
// Set an unrelated preference.
$prefs = (array) $writer->get_user_preferences('core_message');
// Check only 3 preferences exist.
- $this->assertCount(3, $prefs);
+ $this->assertCount(4, $prefs);
$this->assertArrayHasKey('message_provider_moodle_instantmessage_loggedin', $prefs);
$this->assertArrayHasKey('message_provider_moodle_instantmessage_loggedoff', $prefs);
$this->assertArrayHasKey('message_blocknoncontacts', $prefs);
+ $this->assertArrayHasKey('message_entertosend', $prefs);
foreach ($prefs as $key => $pref) {
if ($key == 'message_provider_moodle_instantmessage_loggedin') {