mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 02:16:41 +02:00
MDL-30022 message: made the messaging history display code able to deal with multiple messages with the same timecreated value
This commit is contained in:
parent
7033316dad
commit
78c2fa5cab
1 changed files with 11 additions and 24 deletions
|
@ -749,29 +749,15 @@ function message_get_recent_conversations($user, $limitfrom=0, $limitto=100) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Sort the conversations. This is a bit complicated as we need to sort by $conversation->timecreated
|
// Sort the conversations by $conversation->timecreated, newest to oldest
|
||||||
//and there may be multiple conversations with the same timecreated value.
|
// There may be multiple conversations with the same timecreated
|
||||||
//The conversations array contains both read and unread messages (different tables) so sorting by ID won't work
|
// The conversations array contains both read and unread messages (different tables) so sorting by ID won't work
|
||||||
usort($conversations, "conversationsort");
|
$result = collatorlib::asort_objects_by_property($conversations, 'timecreated', collatorlib::SORT_NUMERIC);
|
||||||
|
$conversations = array_reverse($conversations);
|
||||||
|
|
||||||
return $conversations;
|
return $conversations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sort function used to order conversations
|
|
||||||
*
|
|
||||||
* @param object $a A conversation object
|
|
||||||
* @param object $b A conversation object
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
function conversationsort($a, $b)
|
|
||||||
{
|
|
||||||
if ($a->timecreated == $b->timecreated) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return ($a->timecreated > $b->timecreated) ? -1 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the users recent event notifications
|
* Get the users recent event notifications
|
||||||
*
|
*
|
||||||
|
@ -1804,7 +1790,7 @@ function message_get_history($user1, $user2, $limitnum=0, $viewingnewmessages=fa
|
||||||
array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id),
|
array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id),
|
||||||
"timecreated $sort", '*', 0, $limitnum)) {
|
"timecreated $sort", '*', 0, $limitnum)) {
|
||||||
foreach ($messages_read as $message) {
|
foreach ($messages_read as $message) {
|
||||||
$messages[$message->timecreated] = $message;
|
$messages[] = $message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($messages_new = $DB->get_records_select('message', "((useridto = ? AND useridfrom = ?) OR
|
if ($messages_new = $DB->get_records_select('message', "((useridto = ? AND useridfrom = ?) OR
|
||||||
|
@ -1812,15 +1798,16 @@ function message_get_history($user1, $user2, $limitnum=0, $viewingnewmessages=fa
|
||||||
array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id),
|
array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id),
|
||||||
"timecreated $sort", '*', 0, $limitnum)) {
|
"timecreated $sort", '*', 0, $limitnum)) {
|
||||||
foreach ($messages_new as $message) {
|
foreach ($messages_new as $message) {
|
||||||
$messages[$message->timecreated] = $message;
|
$messages[] = $message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result = collatorlib::asort_objects_by_property($messages, 'timecreated', collatorlib::SORT_NUMERIC);
|
||||||
|
|
||||||
//if we only want the last $limitnum messages
|
//if we only want the last $limitnum messages
|
||||||
ksort($messages);
|
|
||||||
$messagecount = count($messages);
|
$messagecount = count($messages);
|
||||||
if ($limitnum>0 && $messagecount>$limitnum) {
|
if ($limitnum > 0 && $messagecount > $limitnum) {
|
||||||
$messages = array_slice($messages, $messagecount-$limitnum, $limitnum, true);
|
$messages = array_slice($messages, $messagecount - $limitnum, $limitnum, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $messages;
|
return $messages;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue