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

* Add clarification to delete messages lang strings
* Stop message polling when sending a message to fix UI bug
* Publish update last message event when polling finds more messages
* Remove logged in user from group conversation participants list
* Use user object to fetch user preferences to reduce DB calls
* Remove animated slide transitions because the browser breaks when
  showing some conversations
This commit is contained in:
Ryan Wyllie
2018-11-16 14:10:10 +08:00
parent 30538dc9c1
commit d3d95d5dc2
12 changed files with 32 additions and 153 deletions
+3 -2
View File
@@ -49,11 +49,11 @@ $string['contacts'] = 'Contacts';
$string['decline'] = 'Decline';
$string['defaultmessageoutputs'] = 'Default message outputs';
$string['defaults'] = 'Defaults';
$string['deleteallconfirm'] = "Are you sure you would like to delete this entire conversation?";
$string['deleteallconfirm'] = "Are you sure you would like to delete this entire conversation? This will not delete it for other conversation participants.";
$string['deleteallmessages'] = "Delete all messages";
$string['deleteconversation'] = "Delete conversation";
$string['deleteselectedmessages'] = 'Delete selected messages';
$string['deleteselectedmessagesconfirm'] = 'Are you sure you would like to delete the selected messages?';
$string['deleteselectedmessagesconfirm'] = 'Are you sure you would like to delete the selected messages? This will not delete them for other conversation participants.';
$string['disableall'] = 'Disable notifications';
$string['disabled'] = 'Messaging is disabled on this site';
$string['disallowed'] = 'Disallowed';
@@ -132,6 +132,7 @@ $string['off'] = 'Off';
$string['offline'] = 'Offline';
$string['on'] = 'On';
$string['online'] = 'Online';
$string['otherparticipants'] = 'Other participants';
$string['outputdisabled'] = 'Output disabled';
$string['outputdoesnotexist'] = 'Message output does not exists';
$string['outputenabled'] = 'Output enabled';
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1 +1 @@
define(["jquery","core/str","core/templates","core_message/message_repository","core_message/message_drawer_lazy_load_list"],function(a,b,c,d,e){var f=50,g={CONTENT_CONTAINER:'[data-region="group-info-content-container"]',MEMBERS_LIST:'[data-region="members-list"]'},h={CONTENT:"core_message/message_drawer_view_group_info_body_content",MEMBERS_LIST:"core_message/message_drawer_view_group_info_participants_list"},i=function(a){return a.find(g.CONTENT_CONTAINER)},j=function(a,b,d){var e=b.totalMemberCount>50?50:b.totalMemberCount,f=Array.apply(null,Array(e)).map(function(){return!0}),g={name:b.name,subname:b.subname,imageurl:b.imageUrl,placeholders:f,loggedinuser:{id:d}};return c.render(h.CONTENT,g).then(function(b){return i(a).append(b),b})},k=function(a,b,c){return function(f,g){return d.getConversationMembers(a.id,g,b+1,c).then(function(a){return a.length>b?a=a.slice(0,-1):e.setLoadedAll(f,!0),c+=b,a})}},l=function(a,b){return c.render(h.MEMBERS_LIST,{contacts:b}).then(function(b){return a.append(b),b})},m=function(b,c,d){return b=a(b),i(b).empty(),j(b,c,d).then(function(){var a=e.getRoot(b);e.show(a,k(c,f,0),l)})},n=function(a,c){return b.get_string("messagedrawerviewgroupinfo","core_message",c.name)};return{show:m,description:n}});
define(["jquery","core/str","core/templates","core_message/message_repository","core_message/message_drawer_lazy_load_list"],function(a,b,c,d,e){var f=50,g={CONTENT_CONTAINER:'[data-region="group-info-content-container"]',MEMBERS_LIST:'[data-region="members-list"]'},h={CONTENT:"core_message/message_drawer_view_group_info_body_content",MEMBERS_LIST:"core_message/message_drawer_view_group_info_participants_list"},i=function(a){return a.find(g.CONTENT_CONTAINER)},j=function(a,b,d){var e=b.totalMemberCount>50?50:b.totalMemberCount,f=Array.apply(null,Array(e)).map(function(){return!0}),g={name:b.name,subname:b.subname,imageurl:b.imageUrl,placeholders:f,loggedinuser:{id:d}};return c.render(h.CONTENT,g).then(function(b){return i(a).append(b),b})},k=function(a,b,c){return function(f,g){return d.getConversationMembers(a.id,g,b+1,c).then(function(a){return a.length>b?a=a.slice(0,-1):e.setLoadedAll(f,!0),c+=b,a.filter(function(a){return a.id!=g})})}},l=function(a,b){return c.render(h.MEMBERS_LIST,{contacts:b}).then(function(b){return a.append(b),b})},m=function(b,c,d){return b=a(b),i(b).empty(),j(b,c,d).then(function(){var a=e.getRoot(b);e.show(a,k(c,f,0),l)})},n=function(a,c){return b.get_string("messagedrawerviewgroupinfo","core_message",c.name)};return{show:m,description:n}});
@@ -99,6 +99,8 @@ function(
var newMessagesPollTimer = null;
// If the UI is currently resetting.
var isResetting = true;
// If the UI is currently sending a message.
var isSendingMessage = false;
// This is the render function which will be generated when this module is
// first called. See generateRenderFunction for details.
var render = null;
@@ -523,7 +525,7 @@ function(
var messages = viewState.messages;
var mostRecentMessage = messages.length ? messages[messages.length - 1] : null;
if (mostRecentMessage && !isResetting) {
if (mostRecentMessage && !isResetting && !isSendingMessage) {
// There may be multiple messages with the same time created value since
// the accuracy is only down to the second. The server will include these
// messages in the result (since it does a >= comparison on time from) so
@@ -555,6 +557,10 @@ function(
// If we found some results then restart the polling timer
// because the other user might be sending messages.
newMessagesPollTimer.restart();
// We've also got a new last message so publish that for other
// components to update.
var conversation = formatConversationForEvent(viewState);
PubSub.publish(MessageDrawerEvents.CONVERSATION_NEW_LAST_MESSAGE, conversation);
return markConversationAsRead(conversationId);
} else {
return result;
@@ -950,6 +956,7 @@ function(
* @return {Promise} Renderer promise.
*/
var sendMessage = function(conversationId, text) {
isSendingMessage = true;
var newState = StateManager.setSendingMessage(viewState, true);
var newConversationId = null;
return render(newState)
@@ -983,11 +990,13 @@ function(
return render(newState)
.then(function() {
isSendingMessage = false;
PubSub.publish(MessageDrawerEvents.CONVERSATION_NEW_LAST_MESSAGE, conversation);
return;
});
})
.catch(function(error) {
isSendingMessage = false;
var newState = StateManager.setSendingMessage(viewState, false);
render(newState);
Notification.exception(error);
@@ -108,7 +108,10 @@ function(
offset = offset + limit;
return members;
// Filter out the logged in user so that they don't appear in the list.
return members.filter(function(member) {
return member.id != userId;
});
});
};
};
+7 -2
View File
@@ -1797,7 +1797,7 @@ class api {
* @return int The default messaging preference.
*/
public static function get_user_privacy_messaging_preference(int $userid) : int {
global $CFG;
global $CFG, $USER;
// When $CFG->messagingallusers is enabled, default value for the messaging preference will be "Anyone on the site";
// otherwise, the default value will be "My contacts and anyone in my courses".
@@ -1806,7 +1806,12 @@ class api {
} else {
$defaultprefvalue = self::MESSAGE_PRIVACY_SITE;
}
$privacypreference = get_user_preferences('message_blocknoncontacts', $defaultprefvalue, $userid);
if ($userid == $USER->id) {
$user = $USER;
} else {
$user = $userid;
}
$privacypreference = get_user_preferences('message_blocknoncontacts', $defaultprefvalue, $user);
// When the $CFG->messagingallusers privacy setting is disabled, MESSAGE_PRIVACY_SITE is
// also disabled, so it has to be replaced to MESSAGE_PRIVACY_COURSEMEMBER.
+4 -4
View File
@@ -859,12 +859,12 @@ function core_message_standard_after_main_region_html() {
];
}
// Email settings.
$emailloggedin = get_user_preferences('message_provider_moodle_instantmessage_loggedin', 'none', $USER->id);
$emailloggedoff = get_user_preferences('message_provider_moodle_instantmessage_loggedoff', 'none', $USER->id);
$emailenabled = $emailloggedin == 'email' && $emailloggedoff == 'email';
$emailloggedin = get_user_preferences('message_provider_moodle_instantmessage_loggedin', 'none', $USER);
$emailloggedoff = get_user_preferences('message_provider_moodle_instantmessage_loggedoff', 'none', $USER);
$emailenabled = $emailloggedin == 'email' || $emailloggedoff == 'email';
// Enter to send.
$entertosend = get_user_preferences('message_entertosend', false, $USER->id);
$entertosend = get_user_preferences('message_entertosend', false, $USER);
return $renderer->render_from_template('core_message/message_drawer', [
'contactrequestcount' => $requestcount,
@@ -54,7 +54,7 @@
<h2 class="mt-2 mb-0 text-center text-truncate h4">{{name}}</h2>
{{#subname}}<h3 class="mt-2 mb-0 text-center text-truncate h5">{{.}}</h3>{{/subname}}
</div>
<h3 class="border-bottom h6 mt-3 px-3 py-2 mb-0 font-weight-bold">{{#str}} participants, core_message {{/str}}</h3>
<h3 class="border-bottom h6 mt-3 px-3 py-2 mb-0 font-weight-bold">{{#str}} otherparticipants, core_message {{/str}}</h3>
<div class="pt-1 bg-white" data-region="members-list-container" style="overflow-y: auto">
{{< core_message/message_drawer_lazy_load_list }}
{{$rootattributes}}
-36
View File
@@ -1225,48 +1225,12 @@ $message-drawer-width: 320px;
left: 0;
top: 0;
bottom: 0;
opacity: 1;
@include transition();
&.hidden {
display: block;
left: $message-drawer-width;
right: $message-drawer-width * -1;
opacity: 0;
visibility: hidden;
&.previous {
left: $message-drawer-width * -1;
right: $message-drawer-width;
}
}
}
}
.footer-container {
flex-shrink: 0;
overflow-x: hidden;
& > * {
max-height: 2000px;
opacity: 1;
@include transition();
&.hidden {
display: block;
max-height: 0;
opacity: 0;
padding: 0 !important; /* stylelint-disable-line declaration-no-important */
border: 0 !important; /* stylelint-disable-line declaration-no-important */
visibility: hidden;
transform: translate(#{$message-drawer-width});
transition: all .2s ease-in-out, max-height .2s .2s ease-in-out;
&.previous {
transform: translate(#{($message-drawer-width * -1)});
}
}
}
}
.matchtext {
+1 -29
View File
@@ -14095,38 +14095,10 @@ a.ygtvspacer:hover {
right: 0;
left: 0;
top: 0;
bottom: 0;
opacity: 1;
transition: all 0.2s ease-in-out; }
.message-drawer .body-container > *.hidden {
display: block;
left: 320px;
right: -320px;
opacity: 0;
visibility: hidden; }
.message-drawer .body-container > *.hidden.previous {
left: -320px;
right: 320px; }
bottom: 0; }
.message-drawer .footer-container {
flex-shrink: 0;
overflow-x: hidden; }
.message-drawer .footer-container > * {
max-height: 2000px;
opacity: 1;
transition: all 0.2s ease-in-out; }
.message-drawer .footer-container > *.hidden {
display: block;
max-height: 0;
opacity: 0;
padding: 0 !important;
/* stylelint-disable-line declaration-no-important */
border: 0 !important;
/* stylelint-disable-line declaration-no-important */
visibility: hidden;
transform: translate(320px);
transition: all .2s ease-in-out, max-height .2s .2s ease-in-out; }
.message-drawer .footer-container > *.hidden.previous {
transform: translate(-320px); }
.message-drawer .matchtext {
background-color: #b5d9f9;
color: #373a3c;
@@ -1236,48 +1236,12 @@
left: 0;
top: 0;
bottom: 0;
opacity: 1;
.transition(all .2s ease-in-out);
&.hidden {
display: block;
left: @message-drawer-width;
right: @message-drawer-width * -1;
opacity: 0;
visibility: hidden;
&.previous {
left: @message-drawer-width * -1;
right: @message-drawer-width;
}
}
}
}
.footer-container {
flex-shrink: 0;
overflow-x: hidden;
& > * {
max-height: 2000px;
opacity: 1;
.transition(all .2s ease-in-out);
&.hidden {
display: block;
max-height: 0;
opacity: 0;
padding: 0 !important; /* stylelint-disable-line declaration-no-important */
border: 0 !important; /* stylelint-disable-line declaration-no-important */
visibility: hidden;
transform: translate(@message-drawer-width);
transition: all .2s ease-in-out, max-height .2s .2s ease-in-out;
&.previous {
transform: translate(@message-drawer-width * -1);
}
}
}
}
.matchtext {
-39
View File
@@ -9149,50 +9149,11 @@ a.ygtvspacer:hover {
left: 0;
top: 0;
bottom: 0;
opacity: 1;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
.message-drawer .body-container > *.hidden {
display: block;
left: 320px;
right: -320px;
opacity: 0;
visibility: hidden;
}
.message-drawer .body-container > *.hidden.previous {
left: -320px;
right: 320px;
}
.message-drawer .footer-container {
flex-shrink: 0;
overflow-x: hidden;
}
.message-drawer .footer-container > * {
max-height: 2000px;
opacity: 1;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
.message-drawer .footer-container > *.hidden {
display: block;
max-height: 0;
opacity: 0;
padding: 0 !important;
/* stylelint-disable-line declaration-no-important */
border: 0 !important;
/* stylelint-disable-line declaration-no-important */
visibility: hidden;
transform: translate(320px);
transition: all 0.2s ease-in-out, max-height 0.2s 0.2s ease-in-out;
}
.message-drawer .footer-container > *.hidden.previous {
transform: translate(-320px);
}
.message-drawer .matchtext {
background-color: #ade6fe;
color: #333;