def toot_visibility(mastodon, flag_visibility=None, parent_visibility=None):
    """ Return the visibility of a toot.
    We use the following precedence for flagging the privacy of a toot:
    flags > parent (if not public) > account settings
    """
    default_visibility = mastodon.account_verify_credentials()['source'][
        'privacy']
    if flag_visibility:
        return flag_visibility
    if parent_visibility and parent_visibility != 'public':
        return parent_visibility
    return default_visibility
