public static function export_conversations(int $userid, string $component, string $itemtype, \context $context,
                                                array $subcontext = [], int $itemid = 0) {
        global $DB;

        // Search for conversations for this user in this area.
        $sql = "SELECT DISTINCT mc.*
                  FROM {message_conversations} mc
                  JOIN {message_conversation_members} mcm
                    ON (mcm.conversationid = mc.id AND mcm.userid = :userid)";
        $params = [
            'userid' => $userid
        ];

        // Get the conversations for the defined component and itemtype.
        if (!empty($component) && !empty($itemtype)) {
            $sql .= " WHERE mc.component = :component AND mc.itemtype = :itemtype";
            $params['component'] = $component;
            $params['itemtype'] = $itemtype;
            if (!empty($itemid)) {
                $sql .= " AND mc.itemid = :itemid";
                $params['itemid'] = $itemid;
            }
        } else {
            // Get all the conversations without any component and itemtype, so with null contextid.
            $sql .= " WHERE mc.contextid IS NULL";
        }

        if ($conversations = $DB->get_records_sql($sql, $params)) {
            // Export conversation messages.
            foreach ($conversations as $conversation) {
                self::export_user_data_conversation_messages($userid, $conversation, $context, $subcontext);
            }
        }
    }