public static function data_for_messagearea_get_most_recent_message($currentuserid, $otheruserid) {
        global $CFG, $PAGE, $USER;

        // Check if messaging is enabled.
        if (empty($CFG->messaging)) {
            throw new moodle_exception('disabled', 'message');
        }

        $systemcontext = context_system::instance();

        $params = array(
            'currentuserid' => $currentuserid,
            'otheruserid' => $otheruserid
        );
        $params = self::validate_parameters(self::data_for_messagearea_get_most_recent_message_parameters(), $params);
        self::validate_context($systemcontext);

        if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
            throw new moodle_exception('You do not have permission to perform this action.');
        }

        $message = \core_message\api::get_most_recent_message($params['currentuserid'], $params['otheruserid']);
        $message = new \core_message\output\messagearea\message($message);

        $renderer = $PAGE->get_renderer('core_message');
        return $message->export_for_template($renderer);
    }