Skip to content

Commit

Permalink
MDL-63303 message: fix bugs in message drawer part 4
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ryanwyllie committed Nov 16, 2018
1 parent 30538dc commit d3d95d5
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 153 deletions.
5 changes: 3 additions & 2 deletions lang/en/message.php
Expand Up @@ -49,11 +49,11 @@
$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';
Expand Down Expand Up @@ -132,6 +132,7 @@
$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';
Expand Down
2 changes: 1 addition & 1 deletion message/amd/build/message_drawer_view_conversation.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion message/amd/build/message_drawer_view_group_info.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion message/amd/src/message_drawer_view_conversation.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion message/amd/src/message_drawer_view_group_info.js
Expand Up @@ -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;
});
});
};
};
Expand Down
9 changes: 7 additions & 2 deletions message/classes/api.php
Expand Up @@ -1797,7 +1797,7 @@ public static function send_message_to_conversation(int $userid, int $conversati
* @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".
Expand All @@ -1806,7 +1806,12 @@ public static function get_user_privacy_messaging_preference(int $userid) : int
} 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.
Expand Down
8 changes: 4 additions & 4 deletions message/lib.php
Expand Up @@ -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,
Expand Down
Expand Up @@ -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}}
Expand Down
36 changes: 0 additions & 36 deletions theme/boost/scss/moodle/message.scss
Expand Up @@ -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 {
Expand Down
30 changes: 1 addition & 29 deletions theme/boost/style/moodle.css
Expand Up @@ -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;
Expand Down
36 changes: 0 additions & 36 deletions theme/bootstrapbase/less/moodle/message.less
Expand Up @@ -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 {
Expand Down
39 changes: 0 additions & 39 deletions theme/bootstrapbase/style/moodle.css
Expand Up @@ -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;
Expand Down

0 comments on commit d3d95d5

Please sign in to comment.