Skip to content

Commit

Permalink
Merge branch 'MDL-63901-master' of git://github.com/sarjona/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed Nov 14, 2018
2 parents e77cae1 + 8105af9 commit 462fc2a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 40 deletions.
1 change: 0 additions & 1 deletion lang/en/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
$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?";
Expand Down
91 changes: 52 additions & 39 deletions message/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@

// 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.
Expand All @@ -140,52 +142,63 @@

// 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'];

// 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);
$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;
$messages = [];
if (!empty($convmessages)) {
$messages = $convmessages['messages'];

// 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;
}
}
}

// 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'));
}
// 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;
// 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();
}
}
}
}

Expand Down

0 comments on commit 462fc2a

Please sign in to comment.