Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to close sitewide commenting for a specific time (ie. from midnight to 6 am.) #4553

Open
superklass opened this issue Feb 22, 2024 · 5 comments

Comments

@superklass
Copy link

Hello Coral-Team!

I would like to ask if there already is a function available for closing sitewide commenting within a timeframe.
Ie. daily from midnight until 6 am. in the morning.

I know we can manually close the commenting sitewide, But what we are looking for is an option to do
this automatically , on a daily basis, for certain hours.

There should be a option in the coral admin interface to set a time for closing sitewide commenting.
Best case would be to be able to set the from/to time on a daily basis (Mo, Tu, We, Th, Fr, Sa. Sun) and hours from/to.
Within this timeframe it should not be possible for users to add new comments.

An option like this would help our community management with their work a lot.

Thanks a lot, Eric

@losowsky
Copy link
Member

Thanks Eric. This isn't something we've had requested before, so it's not a priority for us (though of course you can always submit a PR to add it to our codebase.) I'd be interested to hear if anyone else here has a flow like this.

@ShittyAdvice
Copy link

I'd like to add to this that we would be interested as well. Currently we manually close them every evening and open them again in the mornings.

In the short term I don't have time to create a PR for this, but might do so in the future if I have some extra time and no one has picked this up yet

@czepan
Copy link

czepan commented Apr 4, 2024

This would be very nice. We plan to use CoralTalk in the future but our current comment system is closed between midnight and 6am.

Since there is already a switch to disable/enable "Sitewide commenting" - would it be possible to solve this with a cronjob and the API ?

@ihardyslide
Copy link

+1, our Moderation team also closes commenting for all of our sites between midnight and 7 a.m.
They would spare some time with this feature each day.

@czepan
Copy link

czepan commented Jan 13, 2025

Since I don't know to what extent an official feature can be expected here, attached is a script that we call internally via a cron job to enable or disable the comment section at various times. You only need to fill your CoralTalk base url and admin access token.

#!/bin/bash

# Script for updating global commenting settings in Coral Talk via a GraphQL API.
#
# Requirements:
# 1. Set the following variables to match your environment:
#    - CORAL_TALK_BASE_URL: Base URL of your Coral Talk instance (e.g., "https://example.com").
#    - ADMIN_ACCESS_TOKEN: Valid Bearer token with admin permissions.

# Variables (to be set by the user)
CORAL_TALK_BASE_URL="https://example.com"  # Replace with your Coral Talk base URL
ADMIN_ACCESS_TOKEN="_INSERT_ME_"  # Replace with your admin access token

# Function to update site-wide commenting settings
update_sitewide_commenting() {
    local action=$1

    # Convert "enable" and "disable" to JSON-compatible boolean values
    local enabled
    if [[ "$action" == "enable" ]]; then
        enabled="false"
    elif [[ "$action" == "disable" ]]; then
        enabled="true"
    else
        echo "Error: Parameter must be 'enable' or 'disable'." >&2
        exit 1
    fi

    # GraphQL mutation to update settings
    local query='mutation UpdateSettings($input: UpdateSettingsInput!) { 
        updateSettings(input: $input) { 
            settings { 
                disableCommenting {
                    enabled
                    message
                }
            }
        }
    }'

    # Variables used in the mutation
    local variables=$(jq -n \
        --arg enabled "$enabled" \
        --arg clientMutationId "$(uuidgen)" \
        '{
            "input": {
                "settings": {
                    "disableCommenting": {
                        "enabled": ($enabled | test("true"))
                    }
                },
                "clientMutationId": $clientMutationId
            }
        }')

    # JSON payload for the request
    local data=$(jq -n \
        --arg query "$query" \
        --argjson variables "$variables" \
        '{
            "query": $query,
            "variables": $variables
        }')

    # Send the request using curl
    local response=$(curl -s \
        -X POST "$CORAL_TALK_BASE_URL/api/graphql" \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer $ADMIN_ACCESS_TOKEN" \
        -d "$data")

    # Check if the response contains the expected data
    echo "$response" | jq '.data.updateSettings.settings.disableCommenting' || {
        echo "Error: Failed to update commenting settings." >&2
        return 1
    }
}

# Check if a parameter was provided
if [ -z "$1" ]; then
    echo "Usage: $0 <enable|disable>" >&2
    exit 1
fi

# Pass the parameter to the function
update_sitewide_commenting "$1"

Usage:
./update_sitewide_commenting.sh <enable|disable> // enables or disables sitewide commenting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants