Permalink
Browse files

Merge branch 'MDL-30022_message_duplicate_23' of git://github.com/and…

…yjdavis/moodle into MOODLE_23_STABLE
  • Loading branch information...
2 parents d8a6407 + 78c2fa5 commit df4e81835a251ad0c90495ff6918b5508a252ef7 Sam Hemelryk committed Sep 4, 2012
Showing with 11 additions and 24 deletions.
  1. +11 −24 message/lib.php
View
35 message/lib.php
@@ -749,30 +749,16 @@ 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
- //and there may be multiple conversations with the same timecreated value.
- //The conversations array contains both read and unread messages (different tables) so sorting by ID won't work
- usort($conversations, "conversationsort");
+ // Sort the conversations by $conversation->timecreated, newest to oldest
+ // 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
+ $result = collatorlib::asort_objects_by_property($conversations, 'timecreated', collatorlib::SORT_NUMERIC);
+ $conversations = array_reverse($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
*
* @param object $user the current user
@@ -1804,23 +1790,24 @@ function message_get_history($user1, $user2, $limitnum=0, $viewingnewmessages=fa
array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id),
"timecreated $sort", '*', 0, $limitnum)) {
foreach ($messages_read as $message) {
- $messages[$message->timecreated] = $message;
+ $messages[] = $message;
}
}
if ($messages_new = $DB->get_records_select('message', "((useridto = ? AND useridfrom = ?) OR
(useridto = ? AND useridfrom = ?)) $ownnotificationwhere",
array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id),
"timecreated $sort", '*', 0, $limitnum)) {
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
- ksort($messages);
$messagecount = count($messages);
- if ($limitnum>0 && $messagecount>$limitnum) {
- $messages = array_slice($messages, $messagecount-$limitnum, $limitnum, true);
+ if ($limitnum > 0 && $messagecount > $limitnum) {
+ $messages = array_slice($messages, $messagecount - $limitnum, $limitnum, true);
}
return $messages;

0 comments on commit df4e818

Please sign in to comment.