souramoo / commentoplusplus

Commento with out of the box patches and updates to add useful features and fixes. Also with one-click deploy to Heroku so you can get up and running fast.
MIT License
391 stars 63 forks source link

Consider to set new user to auto-subscribe email notification #135

Open alisanta opened 2 years ago

alisanta commented 2 years ago

First, thanks for your hardwork and all contributors.

As mostly disqus (or other systems) users may expect, the behaviour of new comment from new user is to 'always receive' email notification when someone reply their comment. Later they would unsubscribe if they found the thread becomes noisy.

I know that the fastest way is to change default value of 'sendreplynotifications' column in 'emails' table. Second alternative is to modify the row creation in the code. Or more elegant way is to add auto-subscribe checkbox during user registration.

Any inputs, much appreciated.

sander1095 commented 1 year ago

Hi @alisanta and @souramoo ! I'm also interested in this feature.

Or more elegant way is to add auto-subscribe checkbox during user registration.

I think this would be the best solution. For now I'm considering to manually add a SQL trigger to set the sendreplynotifications to true when a user is added, but this isn't very user friendly.

Also, @souramoo , is this repo still active or should people considering forking or moving to a new project? The last commit was almost a year ago.

sander1095 commented 1 year ago

I would appreciate some help with this trigger + function. I'm trying to simply set the sendreplynotifications to true when a new row is inserted, but the trigger doesn't do anything:

CREATE OR REPLACE FUNCTION public.set_sendreplynotifications_true()
    RETURNS trigger
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE NOT LEAKPROOF
AS $BODY$
BEGIN
    NEW.sendreplynotifications = true;
    RETURN NEW;
END;
$BODY$;

ALTER FUNCTION public.set_sendreplynotifications_true()
    OWNER TO commento;

CREATE TRIGGER set_sendreplynotifications_true_trigger
    AFTER INSERT
    ON public.emails
    FOR EACH ROW
    EXECUTE FUNCTION public.set_sendreplynotifications_true();

-- This doesn't set the value to TRUE

INSERT INTO public.emails (email, unsubscribesecrethex, lastemailnotificationdate, pendingemails)
VALUES ('test@example.com', 'secret123', NOW(), 2);
sander1095 commented 1 year ago

Fixed!

The trigger needs to be adjusted to the following:

CREATE TRIGGER set_sendreplynotifications_true_trigger
    BEFORE INSERT
    ON public.emails
    FOR EACH ROW
    EXECUTE FUNCTION public.set_sendreplynotifications_true();