MDL-63303 message: fix bugs in message drawer part 2

* Added missing icon mappings for font-awesome
* Fixed focus on dialogue button when it opens
* Fixed UI updates on user block / unblock
* Fix jQuery syntax error when sending message with quotes
* Fix message/index.php opening drawer when no conversation found
* Fix placeholders rendered for new requests
This commit is contained in:
Ryan Wyllie 2018-11-14 08:33:34 +08:00
parent 1d3535f95c
commit a111ab44af
18 changed files with 57 additions and 63 deletions

View File

@ -303,6 +303,7 @@ class icon_system_fontawesome extends icon_system_font {
'core:i/stats' => 'fa-line-chart',
'core:i/switch' => 'fa-exchange',
'core:i/switchrole' => 'fa-user-secret',
'core:i/trash' => 'fa-trash',
'core:i/twoway' => 'fa-arrows-h',
'core:i/unchecked' => 'fa-square-o',
'core:i/unflagged' => 'fa-flag-o',
@ -313,6 +314,7 @@ class icon_system_fontawesome extends icon_system_font {
'core:i/users' => 'fa-users',
'core:i/valid' => 'fa-check text-success',
'core:i/warning' => 'fa-exclamation text-warning',
'core:i/window_close' => 'fa-window-close',
'core:i/withsubcat' => 'fa-plus-square',
'core:m/USD' => 'fa-usd',
'core:t/addcontact' => 'fa-address-card',
@ -378,6 +380,7 @@ class icon_system_fontawesome extends icon_system_font {
'core:t/reset' => 'fa-repeat',
'core:t/restore' => 'fa-arrow-circle-up',
'core:t/right' => 'fa-arrow-right',
'core:t/sendmessage' => 'fa-paper-plane',
'core:t/show' => 'fa-eye-slash',
'core:t/sort_asc' => 'fa-sort-asc',
'core:t/sort_desc' => 'fa-sort-desc',

View File

@ -1 +1 @@
define(["jquery","core/pubsub","core/str","core_message/message_drawer_events"],function(a,b,c,d){var e={},f=[],g={CAN_RECEIVE_FOCUS:'input:not([type="hidden"]), a[href], button, textarea, select, [tabindex]',ROUTES_BACK:"[data-route-back]"},h=function(a,b,c,d){e[a]={elements:b,onGo:c,getDescription:d}},i=function(c){var f,h=[].slice.call(arguments,1),i=a.Deferred().resolve().promise();if(Object.keys(e).forEach(function(a){var b=e[a],d=a===c;d&&(f=b),b.elements.forEach(function(a){a.removeClass("previous"),d?(a.removeClass("hidden"),a.attr("aria-hidden",!1)):(a.addClass("hidden"),a.attr("aria-hidden",!0))})}),f&&f.onGo){i=f.onGo.apply(void 0,f.elements.concat(h));for(var j=a(document.activeElement),k=!1,l=0;l<f.elements.length;l++){var m=f.elements[l];if(m.has(j).length){k=!0;break}}k||f.elements[0].find(g.CAN_RECEIVE_FOCUS).first().focus()}var n={route:c,params:h,renderPromise:i};return b.publish(d.ROUTE_CHANGED,n),n},j=function(){var b=a(document.activeElement),d=i.apply(null,arguments),h=!1;f=f.reduce(function(a,b){return b.route===d.route&&(h=!0),h||a.push(b),a},[]);var j=f.length?f[f.length-1]:null;if(j){var k=e[j.route];k.elements.forEach(function(a){a.addClass("previous")}),j.focusElement=b,k.getDescription&&k.getDescription.apply(null,k.elements.concat(j.params)).then(function(a){return c.get_string("backto","core_message",a)}).then(function(a){return d.renderPromise.then(function(){e[d.route].elements.forEach(function(b){b.find(g.ROUTES_BACK).attr("aria-label",a)})})})["catch"](function(){})}return f.push(d),d},k=function(){if(f.length){f.pop();var a=f.pop();a&&(j.apply(void 0,[a.route].concat(a.params)),window.setTimeout(function(){a.focusElement.focus()},50))}};return{add:h,go:j,back:k}});
define(["jquery","core/pubsub","core/str","core_message/message_drawer_events"],function(a,b,c,d){var e={},f=[],g={CAN_RECEIVE_FOCUS:'input:not([type="hidden"]), a[href], button, textarea, select, [tabindex]',ROUTES_BACK:"[data-route-back]"},h=function(a,b,c,d){e[a]={elements:b,onGo:c,getDescription:d}},i=function(c){var f,h=[].slice.call(arguments,1),i=a.Deferred().resolve().promise();if(Object.keys(e).forEach(function(a){var b=e[a],d=a===c;d&&(f=b),b.elements.forEach(function(a){a.removeClass("previous"),d?(a.removeClass("hidden"),a.attr("aria-hidden",!1)):(a.addClass("hidden"),a.attr("aria-hidden",!0))})}),f&&f.onGo){i=f.onGo.apply(void 0,f.elements.concat(h));for(var j=a(document.activeElement),k=!1,l=0;l<f.elements.length;l++){var m=f.elements[l];if(m.has(j).length){k=!0;break}}k||f.elements[0].find(g.CAN_RECEIVE_FOCUS).filter(":visible").first().focus()}var n={route:c,params:h,renderPromise:i};return b.publish(d.ROUTE_CHANGED,n),n},j=function(){var b=a(document.activeElement),d=i.apply(null,arguments),h=!1;f=f.reduce(function(a,b){return b.route===d.route&&(h=!0),h||a.push(b),a},[]);var j=f.length?f[f.length-1]:null;if(j){var k=e[j.route];k.elements.forEach(function(a){a.addClass("previous")}),j.focusElement=b,k.getDescription&&k.getDescription.apply(null,k.elements.concat(j.params)).then(function(a){return c.get_string("backto","core_message",a)}).then(function(a){return d.renderPromise.then(function(){e[d.route].elements.forEach(function(b){b.find(g.ROUTES_BACK).attr("aria-label",a)})})})["catch"](function(){})}return f.push(d),d},k=function(){if(f.length){f.pop();var a=f.pop();a&&(j.apply(void 0,[a.route].concat(a.params)),window.setTimeout(function(){a.focusElement.focus()},50))}};return{add:h,go:j,back:k}});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -116,7 +116,7 @@ function(
if (!hasFocus) {
// This page doesn't have focus yet so focus the first focusable
// element in the new view.
newConfig.elements[0].find(SELECTORS.CAN_RECEIVE_FOCUS).first().focus();
newConfig.elements[0].find(SELECTORS.CAN_RECEIVE_FOCUS).filter(':visible').first().focus();
}
}
}

View File

@ -598,7 +598,7 @@ function(
var newState = StateManager.addMembers(viewState, [profile]);
newState = StateManager.removePendingBlockUsersById(newState, [userId]);
newState = StateManager.setLoadingConfirmAction(newState, false);
PubSub.publish(MessageDrawerEvents.CONTACT_BLOCKED, newState.id);
PubSub.publish(MessageDrawerEvents.CONTACT_BLOCKED, userId);
return render(newState);
});
};
@ -634,7 +634,7 @@ function(
var newState = StateManager.addMembers(viewState, [profile]);
newState = StateManager.removePendingUnblockUsersById(newState, [userId]);
newState = StateManager.setLoadingConfirmAction(newState, false);
PubSub.publish(MessageDrawerEvents.CONTACT_UNBLOCKED, newState.id);
PubSub.publish(MessageDrawerEvents.CONTACT_UNBLOCKED, userId);
return render(newState);
});
};

View File

@ -992,7 +992,7 @@ function(
showConfirmDialogueContainer(header);
}
dialogue.find(SELECTORS.CAN_RECEIVE_FOCUS).first().focus();
dialogue.find(SELECTORS.CAN_RECEIVE_FOCUS).filter(':visible').first().focus();
};
/**

View File

@ -128,6 +128,7 @@ function(
return carry;
}, null);
formattedConversation.userid = otherUser.id;
formattedConversation.showonlinestatus = otherUser.showonlinestatus;
formattedConversation.isonline = otherUser.isosnline;
formattedConversation.isblocked = otherUser.isblocked;
@ -253,6 +254,17 @@ function(
return root.find('[data-conversation-id="' + conversationId + '"]');
};
/**
* Get a contact / conversation element from a user id.
*
* @param {Object} root Overview messages container element.
* @param {Number} userId The user id.
* @return {Object} Conversation element.
*/
var getConversationElementFromUserId = function(root, userId) {
return root.find('[data-user-id="' + userId + '"]');
};
/**
* Show the contact is blocked icon.
*
@ -303,8 +315,7 @@ function(
element.find(SELECTORS.LAST_MESSAGE).html(lastMessage);
element.find(SELECTORS.LAST_MESSAGE_DATE).text(dateString).removeClass('hidden');
return dateString;
})
.catch(Notification.exception);
});
};
/**
@ -412,15 +423,15 @@ function(
setCollapsed(root);
});
PubSub.subscribe(MessageDrawerEvents.CONTACT_BLOCKED, function(conversationId) {
var conversationElement = getConversationElement(root, conversationId);
PubSub.subscribe(MessageDrawerEvents.CONTACT_BLOCKED, function(userId) {
var conversationElement = getConversationElementFromUserId(root, userId);
if (conversationElement.length) {
blockContact(conversationElement);
}
});
PubSub.subscribe(MessageDrawerEvents.CONTACT_UNBLOCKED, function(conversationId) {
var conversationElement = getConversationElement(root, conversationId);
PubSub.subscribe(MessageDrawerEvents.CONTACT_UNBLOCKED, function(userId) {
var conversationElement = getConversationElementFromUserId(root, userId);
if (conversationElement.length) {
unblockContact(conversationElement);
}

View File

@ -90,8 +90,13 @@ class core_message_external extends external_api {
$messages = [];
foreach ($params['messages'] as $message) {
$messages[] = \core_message\api::send_message_to_conversation($USER->id, $params['conversationid'], $message['text'],
$createdmessage = \core_message\api::send_message_to_conversation($USER->id, $params['conversationid'], $message['text'],
$message['textformat']);
$createdmessage->text = message_format_message_text((object) [
'smallmessage' => $createdmessage->text,
'fullmessageformat' => external_validate_format($message['textformat'])
]);
$messages[] = $createdmessage;
}
return $messages;

View File

@ -107,10 +107,12 @@ if ($currentuser) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('messages', 'message'));
$conversationid = empty($user2id) ? null : \core_message\api::get_conversation_between_users([$USER->id, $user2id]);
if (empty($conversationid)) {
if (empty($conversationid) && !empty($user2id)) {
$PAGE->requires->js_call_amd('core_message/message_drawer_helper', 'createConversationWithUser', [$user2id]);
} else {
} else if (!empty($conversationid)) {
$PAGE->requires->js_call_amd('core_message/message_drawer_helper', 'showConversation', [$conversationid]);
} else {
$PAGE->requires->js_call_amd('core_message/message_drawer_helper', 'show');
}
echo $OUTPUT->footer();
exit();

View File

@ -901,7 +901,10 @@ function core_message_before_standard_top_of_body_html() {
'contacts' => [
'sectioncontacts' => [
'placeholders' => array_fill(0, $contactscount > 50 ? 50 : $contactscount, true)
]
],
'sectionrequests' => [
'placeholders' => array_fill(0, $requestcount > 50 ? 50 : $requestcount, true)
],
],
'settings' => [
'privacy' => $choices,

View File

@ -34,7 +34,7 @@
{}
}}
<div class="p-1 d-flex list-group-item border-0" data-region="placeholder">
<div class="p-2 d-flex list-group-item border-0" data-region="placeholder">
<div
class="rounded-circle bg-pulse-grey"
style="height: 38px; width: 38px"

View File

@ -39,6 +39,9 @@
href="#"
class="p-2 d-flex list-group-item list-group-item-action border-0 align-items-center"
data-conversation-id="{{id}}"
{{#userid}}
data-user-id="{{.}}"
{{/userid}}
>
{{#imageurl}}
<img

View File

@ -34,7 +34,7 @@
{}
}}
<div class="p-1 d-flex list-group-item border-0" data-region="placeholder">
<div class="p-2 d-flex list-group-item border-0" data-region="placeholder">
<div
class="rounded-circle bg-pulse-grey"
style="height: 38px; width: 38px"

View File

@ -34,7 +34,7 @@
{}
}}
<div class="p-1 d-flex list-group-item border-0" data-region="placeholder">
<div class="p-2 d-flex list-group-item border-0" data-region="placeholder">
<div
class="rounded-circle bg-pulse-grey"
style="height: 38px; width: 38px"

View File

@ -38,11 +38,11 @@
{{$emptymessage}}{{#str}} nocontactsgetstarted, core_message {{/str}}{{/emptymessage}}
{{$placeholder}}
{{#contacts}}
{{#sectioncontacts}}
{{#sectionrequests}}
{{#placeholders}}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{/placeholders}}
{{/sectioncontacts}}
{{/sectionrequests}}
{{/contacts}}
{{/placeholder}}
{{/ core_message/message_drawer_lazy_load_list }}

View File

@ -37,45 +37,12 @@
{{< core_message/message_drawer_lazy_load_list }}
{{$emptymessage}}{{#str}} nocontactrequests, core_message {{/str}}{{/emptymessage}}
{{$placeholder}}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{#contacts}}
{{#sectioncontacts}}
{{#placeholders}}
{{> core_message/message_drawer_contacts_list_item_placeholder }}
{{/placeholders}}
{{/sectioncontacts}}
{{/contacts}}
{{/placeholder}}
{{/ core_message/message_drawer_lazy_load_list }}