MDL-81428 core: Display the correct status for the contact request

This commit is contained in:
Huong Nguyen
2024-06-10 17:00:46 +07:00
parent d3ae1391ab
commit a07054af30
11 changed files with 168 additions and 19 deletions
+37 -4
View File
@@ -129,9 +129,42 @@ class core_renderer extends \core_renderer {
if ($USER->id != $user->id) {
$iscontact = \core_message\api::is_contact($USER->id, $user->id);
$contacttitle = $iscontact ? 'removefromyourcontacts' : 'addtoyourcontacts';
$contacturlaction = $iscontact ? 'removecontact' : 'addcontact';
$contactimage = $iscontact ? 'removecontact' : 'addcontact';
$isrequested = \core_message\api::get_contact_requests_between_users($USER->id, $user->id);
$contacturlaction = '';
$linkattributes = \core_message\helper::togglecontact_link_params(
$user,
$iscontact,
true,
!empty($isrequested),
);
// If the user is not a contact.
if (!$iscontact) {
if ($isrequested) {
// We just need the first request.
$requests = array_shift($isrequested);
if ($requests->userid == $USER->id) {
// If the user has requested to be a contact.
$contacttitle = 'contactrequestsent';
} else {
// If the user has been requested to be a contact.
$contacttitle = 'waitingforcontactaccept';
}
$linkattributes = array_merge($linkattributes, [
'class' => 'disabled',
'tabindex' => '-1',
]);
} else {
// If the user is not a contact and has not requested to be a contact.
$contacttitle = 'addtoyourcontacts';
$contacturlaction = 'addcontact';
}
$contactimage = 'addcontact';
} else {
// If the user is a contact.
$contacttitle = 'removefromyourcontacts';
$contacturlaction = 'removecontact';
$contactimage = 'removecontact';
}
$userbuttons['togglecontact'] = array(
'buttontype' => 'togglecontact',
'title' => get_string($contacttitle, 'message'),
@@ -142,7 +175,7 @@ class core_renderer extends \core_renderer {
'sesskey' => sesskey())
),
'image' => $contactimage,
'linkattributes' => \core_message\helper::togglecontact_link_params($user, $iscontact),
'linkattributes' => $linkattributes,
'page' => $this->page
);
}