From f5a174f451839149839789cbe4bff9fa4ca2972d Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Tue, 18 Oct 2016 02:00:09 +0000 Subject: [PATCH] MDL-56411 message: dont render message area without other user Stop the message area header and footer from being rendered if there is no other user being messaged, otherwise notices are generated and the messages fail to send. --- message/classes/output/messagearea/messages.php | 8 +++++++- message/index.php | 2 +- message/templates/message_area_messages_area.mustache | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/message/classes/output/messagearea/messages.php b/message/classes/output/messagearea/messages.php index 1f1842ce6ef..368d1d08ec6 100644 --- a/message/classes/output/messagearea/messages.php +++ b/message/classes/output/messagearea/messages.php @@ -82,7 +82,13 @@ class messages implements templatable, renderable { $data->currentuserid = $this->currentuserid; $data->otheruserid = $this->otheruserid; $data->otheruserfullname = fullname($this->otheruser); - $data->isonline = \core_message\helper::is_online($this->otheruser->lastaccess); + + if (empty($this->otheruser)) { + $data->isonline = false; + } else { + $data->isonline = \core_message\helper::is_online($this->otheruser->lastaccess); + } + $data->messages = array(); foreach ($this->messages as $message) { $message = new message($message); diff --git a/message/index.php b/message/index.php index 3e53d4bd30a..0f834a88a05 100644 --- a/message/index.php +++ b/message/index.php @@ -99,7 +99,7 @@ $settings->make_active(); $renderer = $PAGE->get_renderer('core_message'); $requestedconversation = false; $conversations = \core_message\api::get_conversations($user1->id, 0, 20); -$messages = null; +$messages = []; if (!$user2realuser) { // If there are conversations, but the user has not chosen a particular one, then render the most recent one. $user2 = new stdClass(); diff --git a/message/templates/message_area_messages_area.mustache b/message/templates/message_area_messages_area.mustache index cd06e52ee61..5a62fbff524 100644 --- a/message/templates/message_area_messages_area.mustache +++ b/message/templates/message_area_messages_area.mustache @@ -14,6 +14,7 @@ You should have received a copy of the GNU General Public License along with Moodle. If not, see . }} +{{#otheruserid}}
@@ -38,9 +39,11 @@
+{{/otheruserid}}
{{> core_message/message_area_messages }}
+{{#otheruserid}}
{{#iscurrentuser}}
@@ -51,3 +54,4 @@
+{{/otheruserid}}