Merge branch 'MDL-63901-master' of git://github.com/sarjona/moodle

This commit is contained in:
Damyon Wiese 2018-11-14 11:14:18 +08:00
commit 462fc2abcd
2 changed files with 51 additions and 39 deletions

View File

@ -38,7 +38,6 @@ $string['contactableprivacy_site'] = 'Anyone on the site';
$string['contactblocked'] = 'Contact blocked';
$string['contactrequests'] = 'Contact requests';
$string['contacts'] = 'Contacts';
$string['conversationdoesntexist'] = 'Conversation does not exist';
$string['defaultmessageoutputs'] = 'Default message outputs';
$string['defaults'] = 'Defaults';
$string['deleteallconfirm'] = "Are you sure you would like to delete this entire conversation?";

View File

@ -128,10 +128,12 @@ if (!$user2realuser) {
// Mark the conversation as read.
if (!empty($user2->id)) {
$hasbeenreadallmessages = false;
if ($currentuser && isset($conversations[$user2->id])) {
// Mark the conversation we are loading as read.
if ($conversationid = \core_message\api::get_conversation_between_users([$user1->id, $user2->id])) {
\core_message\api::mark_all_messages_as_read($user1->id, $conversationid);
$hasbeenreadallmessages = true;
}
// Ensure the UI knows it's read as well.
@ -140,52 +142,63 @@ if (!empty($user2->id)) {
// Get the conversationid.
if (!isset($conversationid)) {
if (!$conversationid = self::get_conversation_between_users($userids)) {
// If the conversationid doesn't exist, throw an exception.
throw new moodle_exception('conversationdoesntexist', 'core_message');
if (!$conversationid = \core_message\api::get_conversation_between_users([$user1->id, $user2->id])) {
// If the individual conversationid doesn't exist, create it.
$conversation = \core_message\api::create_conversation(
\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
[$user1->id, $user2->id]
);
$conversationid = $conversation->id;
}
}
$convmessages = \core_message\api::get_conversation_messages($user1->id, $conversationid, 0, 20, 'timecreated DESC');
$messages = $convmessages['messages'];
$messages = [];
if (!empty($convmessages)) {
$messages = $convmessages['messages'];
// Keeps track of the last day, month and year combo we were viewing.
$day = '';
$month = '';
$year = '';
// Parse the messages to add missing fields for backward compatibility.
$messages = array_reverse($messages);
// Keeps track of the last day, month and year combo we were viewing.
$day = '';
$month = '';
$year = '';
foreach ($messages as $message) {
// Add useridto.
if (empty($message->useridto)) {
if ($message->useridfrom == $user1->id) {
$message->useridto = $user2->id;
} else {
$message->useridto = $user1->id;
}
}
// Parse the messages to add missing fields for backward compatibility.
$messages = array_reverse($messages);
$day = '';
$month = '';
$year = '';
foreach ($messages as $message) {
// Add useridto.
if (empty($message->useridto)) {
if ($message->useridfrom == $user1->id) {
$message->useridto = $user2->id;
} else {
$message->useridto = $user1->id;
// Add currentuserid.
$message->currentuserid = $USER->id;
// Check if we are now viewing a different block period.
$message->displayblocktime = false;
$date = usergetdate($message->timecreated);
if ($day != $date['mday'] || $month != $date['month'] || $year != $date['year']) {
$day = $date['mday'];
$month = $date['month'];
$year = $date['year'];
$message->displayblocktime = true;
$message->blocktime = userdate($message->timecreated, get_string('strftimedaydate'));
}
// We don't have this information here so, for now, we leave an empty value or the current time.
// This is a temporary solution because a new UI is being built in MDL-63303.
$message->timeread = 0;
if ($hasbeenreadallmessages && $message->useridfrom != $user1->id) {
// As all the messages sent by the other user have been marked as read previously, we will change
// timeread to the current time to avoid the last message will be duplicated after calling to the
// core_message_data_for_messagearea_messages via javascript.
// We only need to change that to the other user, because for the current user, messages are always
// marked as unread.
$message->timeread = time();
}
}
// Add currentuserid.
$message->currentuserid = $USER->id;
// Check if we are now viewing a different block period.
$message->displayblocktime = false;
$date = usergetdate($message->timecreated);
if ($day != $date['mday'] || $month != $date['month'] || $year != $date['year']) {
$day = $date['mday'];
$month = $date['month'];
$year = $date['year'];
$message->displayblocktime = true;
$message->blocktime = userdate($message->timecreated, get_string('strftimedaydate'));
}
// We don't have this information here so, for now, we leave an empty value.
// This is a temporary solution because a new UI is being built in MDL-63303.
$message->timeread = 0;
}
}