mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-45565 core_message: Fixed strangers array
Strangers get mixed with noreply user and support user, if noreply/support users real user. To avoid duplication use userid as array index. Also, avoid fetching data again for noreply and support users, if they are real users, then data is already feteched.
This commit is contained in:
parent
3e511ca50b
commit
25bd63b713
1 changed files with 14 additions and 8 deletions
|
@ -370,21 +370,27 @@ function message_get_contacts($user1=null, $user2=null) {
|
|||
ORDER BY u.firstname ASC";
|
||||
|
||||
$rs = $DB->get_recordset_sql($strangersql, array($USER->id));
|
||||
// Add user id as array index, so supportuser and noreply user don't get duplicated (if they are real users).
|
||||
foreach ($rs as $rd) {
|
||||
$strangers[] = $rd;
|
||||
$strangers[$rd->id] = $rd;
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
// Add noreply user and support user to the list.
|
||||
// Add noreply user and support user to the list, if they don't exist.
|
||||
$supportuser = core_user::get_support_user();
|
||||
if (!isset($strangers[$supportuser->id])) {
|
||||
$supportuser->messagecount = message_count_unread_messages($USER, $supportuser);
|
||||
if ($supportuser->messagecount > 0) {
|
||||
$strangers[] = $supportuser;
|
||||
$strangers[$supportuser->id] = $supportuser;
|
||||
}
|
||||
}
|
||||
|
||||
$noreplyuser = core_user::get_noreply_user();
|
||||
if (!isset($strangers[$noreplyuser->id])) {
|
||||
$noreplyuser->messagecount = message_count_unread_messages($USER, $noreplyuser);
|
||||
if ($noreplyuser->messagecount > 0) {
|
||||
$strangers[] = $noreplyuser;
|
||||
$strangers[$noreplyuser->id] = $noreplyuser;
|
||||
}
|
||||
}
|
||||
return array($onlinecontacts, $offlinecontacts, $strangers);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue