MDL-54687 message: show most recent conversation by default

This commit is contained in:
Ryan Wyllie 2016-08-12 07:09:45 +00:00 committed by Mark Nelson
parent c1fec732c6
commit 8c250260e6
3 changed files with 34 additions and 1 deletions

View File

@ -55,6 +55,13 @@ class contact implements templatable, renderable {
$this->contact = $contact;
}
/**
* Get the user id for this contact.
*/
public function get_contact() {
return $this->contact;
}
public function export_for_template(\renderer_base $output) {
$contact = new \stdClass();
$contact->userid = $this->contact->userid;

View File

@ -64,6 +64,22 @@ class contacts implements templatable, renderable {
$this->contacts = $contacts;
}
/**
* Get the list of contacts.
*/
public function get_contacts() {
return $this->contacts;
}
/**
* Set the other user id.
*
* @param {int} $otheruserid The id of the other user
*/
public function set_otheruserid($otheruserid) {
$this->otheruserid = $otheruserid;
}
public function export_for_template(\renderer_base $output) {
$data = new \stdClass();
$data->userid = $this->userid;

View File

@ -245,7 +245,17 @@ $settings->make_active();
$renderer = $PAGE->get_renderer('core_message');
if (!$user2realuser) {
$conversations = \core_message\api::get_conversations($user1->id, 0, 0, 20);
$messages = null;
$contacts = $conversations->get_contacts();
if (!empty($contacts)) {
// If there are conversations then render the most recent one by default.
$contact = reset($contacts);
$otheruserid = $contact->get_contact()->userid;
$conversations->set_otheruserid($otheruserid);
$messages = \core_message\api::get_messages($user1->id, $otheruserid);
} else {
$messages = null;
}
} else {
$conversations = \core_message\api::get_conversations($user1->id, $user2->id, 0, 20);
$messages = \core_message\api::get_messages($user1->id, $user2->id);