public static function get_self_conversation(
        int $userid,
        int $messagelimit = 0,
        int $messageoffset = 0,
        bool $newestmessagesfirst = true
    ) {
        global $CFG;

        // All the standard BL checks.
        if (empty($CFG->messaging)) {
            throw new moodle_exception('disabled', 'message');
        }

        $params = [
            'userid' => $userid,
            'messagelimit' => $messagelimit,
            'messageoffset' => $messageoffset,
            'newestmessagesfirst' => $newestmessagesfirst
        ];
        self::validate_parameters(self::get_self_conversation_parameters(), $params);

        $systemcontext = context_system::instance();
        self::validate_context($systemcontext);

        $conversation = \core_message\api::get_self_conversation($params['userid']);

        if ($conversation) {
            $conversation = \core_message\api::get_conversation(
                $params['userid'],
                $conversation->id,
                false,
                false,
                0,
                0,
                $params['messagelimit'],
                $params['messageoffset'],
                $params['newestmessagesfirst']
            );
        }

        if ($conversation) {
            return $conversation;
        } else {
            // We have to throw an exception here because the external functions annoyingly
            // don't accept null to be returned for a single structure.
            throw new \moodle_exception('errorconversationdoesnotexist', 'message');
        }
    }