/** * Determines if a user is permitted to send another user a private message. * If no sender is provided then it defaults to the logged in user. * * @deprecated since Moodle 3.2 * @param object $recipient User object. * @param object $sender User object. * @return bool true if user is permitted, false otherwise. */ function message_can_post_message($recipient, $sender = null) { debugging('message_can_post_message() is deprecated and is no longer used, please use \\core_message\\api::can_post_message() instead.', DEBUG_DEVELOPER); return \core_message\api::can_post_message($recipient, $sender); }
/** * Tests the user can't post a message if they are blocked. */ public function test_can_post_message_when_blocked() { // Create some users. $user1 = self::getDataGenerator()->create_user(); $user2 = self::getDataGenerator()->create_user(); // Set the user. $this->setUser($user1); // Block the second user. message_block_contact($user2->id); // Check that the second user can no longer send the first user a message. $this->assertFalse(\core_message\api::can_post_message($user1, $user2)); }