Skip to content

Commit

Permalink
MDL-57036 core_message: always show profile picture on messaging UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Nov 18, 2016
1 parent b4d6669 commit f4c39cb
Showing 1 changed file with 41 additions and 45 deletions.
86 changes: 41 additions & 45 deletions message/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,58 +329,54 @@ public static function get_most_recent_message($userid, $otheruserid) {
* @return \stdClass
*/
public static function get_profile($userid, $otheruserid) {
global $CFG, $DB;
global $CFG, $DB, $PAGE;

require_once($CFG->dirroot . '/user/lib.php');

if ($user = \core_user::get_user($otheruserid)) {
// Create the data we are going to pass to the renderable.
$userfields = user_get_user_details($user, null, array('city', 'country', 'email',
'profileimageurl', 'profileimageurlsmall', 'lastaccess'));
if ($userfields) {
$data = new \stdClass();
$data->userid = $userfields['id'];
$data->fullname = $userfields['fullname'];
$data->city = isset($userfields['city']) ? $userfields['city'] : '';
$data->country = isset($userfields['country']) ? $userfields['country'] : '';
$data->email = isset($userfields['email']) ? $userfields['email'] : '';
$data->profileimageurl = isset($userfields['profileimageurl']) ? $userfields['profileimageurl'] : '';
if (isset($userfields['profileimageurlsmall'])) {
$data->profileimageurlsmall = $userfields['profileimageurlsmall'];
} else {
$data->profileimageurlsmall = '';
}
if (isset($userfields['lastaccess'])) {
$data->isonline = helper::is_online($userfields['lastaccess']);
} else {
$data->isonline = false;
}
} else {
// Technically the access checks in user_get_user_details are correct,
// but messaging has never obeyed them. In order to keep messaging working
// we at least need to return a minimal user record.
$data = new \stdClass();
$data->userid = $otheruserid;
$data->fullname = fullname($user);
$data->city = '';
$data->country = '';
$data->email = '';
$data->profileimageurl = '';
$data->profileimageurlsmall = '';
$data->isonline = false;
$user = \core_user::get_user($otheruserid, '*', MUST_EXIST);

// Create the data we are going to pass to the renderable.
$data = new \stdClass();
$data->userid = $otheruserid;
$data->fullname = fullname($user);
$data->city = '';
$data->country = '';
$data->email = '';
$data->isonline = false;
// Get the user picture data - messaging has always shown these to the user.
$userpicture = new \user_picture($user);
$userpicture->size = 1; // Size f1.
$data->profileimageurl = $userpicture->get_url($PAGE)->out(false);
$userpicture->size = 0; // Size f2.
$data->profileimageurlsmall = $userpicture->get_url($PAGE)->out(false);

$userfields = user_get_user_details($user, null, array('city', 'country', 'email', 'lastaccess'));
if ($userfields) {
if (isset($userfields['city'])) {
$data->city = $userfields['city'];
}
// Check if the contact has been blocked.
$contact = $DB->get_record('message_contacts', array('userid' => $userid, 'contactid' => $otheruserid));
if ($contact) {
$data->isblocked = (bool) $contact->blocked;
$data->iscontact = true;
} else {
$data->isblocked = false;
$data->iscontact = false;
if (isset($userfields['country'])) {
$data->country = $userfields['country'];
}
if (isset($userfields['email'])) {
$data->email = $userfields['email'];
}
if (isset($userfields['lastaccess'])) {
$data->isonline = helper::is_online($userfields['lastaccess']);
}
}

return $data;
// Check if the contact has been blocked.
$contact = $DB->get_record('message_contacts', array('userid' => $userid, 'contactid' => $otheruserid));
if ($contact) {
$data->isblocked = (bool) $contact->blocked;
$data->iscontact = true;
} else {
$data->isblocked = false;
$data->iscontact = false;
}

return $data;
}

/**
Expand Down

0 comments on commit f4c39cb

Please sign in to comment.