diff --git a/message/classes/helper.php b/message/classes/helper.php index 8eef5fe7685..d2c4ececffc 100644 --- a/message/classes/helper.php +++ b/message/classes/helper.php @@ -531,8 +531,12 @@ class helper { $data->profileimageurlsmall = $userpicture->get_url($PAGE)->out(false); // Set online status indicators. - $data->isonline = self::show_online_status($member) ? self::is_online($member->lastaccess) : null; - $data->showonlinestatus = is_null($data->isonline) ? false : true; + $data->isonline = false; + $data->showonlinestatus = false; + if (!$member->deleted) { + $data->isonline = self::show_online_status($member) ? self::is_online($member->lastaccess) : null; + $data->showonlinestatus = is_null($data->isonline) ? false : true; + } // Set contact and blocked status indicators. $data->iscontact = ($member->contactid) ? true : false; diff --git a/message/tests/api_test.php b/message/tests/api_test.php index f7446ab6ce6..69841aff04f 100644 --- a/message/tests/api_test.php +++ b/message/tests/api_test.php @@ -1370,6 +1370,9 @@ class core_message_api_testcase extends core_message_messagelib_testcase { // We should have 5, as $ic1 drops off the list. // Group conversations remain albeit with less members. delete_user($user2); + // This is to confirm an exception is not thrown when a user AND the user context is deleted. + // We no longer delete the user context, but historically we did. + context_helper::delete_instance(CONTEXT_USER, $user2->id); $conversations = \core_message\api::get_conversations($user1->id); $this->assertCount(5, $conversations); $this->assertEquals($gc3->id, $conversations[0]->id);