diff --git a/message/classes/output/messagearea/contact.php b/message/classes/output/messagearea/contact.php index 8b2cefb59f7..bba8f359526 100644 --- a/message/classes/output/messagearea/contact.php +++ b/message/classes/output/messagearea/contact.php @@ -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; diff --git a/message/classes/output/messagearea/contacts.php b/message/classes/output/messagearea/contacts.php index f01df4ae0e7..f02de024fbd 100644 --- a/message/classes/output/messagearea/contacts.php +++ b/message/classes/output/messagearea/contacts.php @@ -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; diff --git a/message/index.php b/message/index.php index 01387dce431..57e853a4c87 100644 --- a/message/index.php +++ b/message/index.php @@ -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);