Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

email notification to poster?

Currently notifications are sent only to other listeners, but not the poster of a discussion or comment.
It can be useful for a copy to be sent to the poster- as if they were just another listener.
Can this be selected in the config file?

Comments

  • Can this be selected in the config file?

    I don't believe there is an option in preferences or config file.

    what you are looking for is some kind of carboncopy emailer. that is selectable per user to email a copy of an individual's post.

    I know if you mention yourself in a post @peregrine you don't get a notification either to prevent the behavior.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • All sorted.
    I started to write an add-on to do it but the learning curve is fairly steep.
    So I took the easier path, found the code that specifically discards emails to the author, and commented it out.
    class.activitymodel.php lines 1075-76 and 1111-1115

    I know this may get overwritten on any upgrade, but it gets around the problem while I learn how to write an add-on to override that function.

  • I upgraded to V2.2 and repeated the exercise- same file but a number of lines further down in this version.
    vanillaforums/applications/dashboard/models/class.activitymodel.php lines 1218-20 and 1275-79

  • R_JR_J Ex-Fanboy Munich Admin

    You already have shown that you know that altering core files is bad practice. If you have decided to solve your problems that way, it is okay.
    But now that repeat your advice, I feel the need to repeat the warning:

    /!\ Don't change core files! /!\

    Don't hesitate to ask when you get stuck creating your plugin.

  • Understood.
    Just working my way through a legit solution.
    I will post here once I have it sorted.

  • @R.J Some help please.
    From the plugins documentation

    Plugin authors may therefore override any core function simply by defining it in a plugin or theme hook file, which are included before the core functions.

    I have tried this- copying the two functions I modified (queue and save) into my plugin-
    class NotifyAuthorPlugin extends Gdn_Plugin { public function queue($Data, $Preference = false, $Options = array()) { ... } public function save($Data, $Preference = false, $Options = array()) { ... } }
    but no joy.
    I suspect the issue is the naming of these overriding functions needs a full extended name?
    So what should I call these, overriding vanillaforums/applications/dashboard/models/class.activitymodel.php/queue{} and save{}?

  • R_JR_J Ex-Fanboy Munich Admin

    Vanilla is object oriented. In the world of OOP you have "classes" and "methods". Methods are defined with the word "function" but they are still called "methods". And the cited sentence is only true for functions that are defined outside of classes.

    The common way in Vanilla to influence the program flow is by using events. All through the code you find "EventArgument" and "FireEvent". So you have to find where you find those keywords in the near of where you try to change something.

    You've changed the activity models method queue because you want to change the behaviour of what is happening when someone saves a comment. So do a search for "activitymodel->queue" in class.commentmodel.php

    Personally I think what you try to achieve doesn't make sense at all, but I guess that part might fit best what you need:

    $Activity['NotifyUserID'] = $UserRow->UserID;
    $Activity['Data']['Reason'] = 'participated';
    $ActivityModel->Queue($Activity, 'ParticipateComment', array('CheckRecord' => true));
    

    We would have to call that code before the activity notification mechanism starts, correct? Looking through the CommentModel, you'll find: $this->fireEvent('BeforeNotification'); and that's what we need.

    Are you on a test system? You should. You could either continue reading code or start testing like crazy - that's what I prefer :mrgreen:

    Put this code in your plugin:

    public function commentModel_beforeNotification_handler($sender, $args) {
        file_put_contents(
            // change the path if needed, but make sure it is not public, like /vanilla/uploads or anything like that
            '/var/log/nginx/vanilla_testings.log',
            print_r($args, true)."\r\n",
            FILE_APPEND
        );
        // Normally you could simply use "decho($args)", but this won't help us here...
    }
    

    Create a discussion as user A. Log in as User B and write a comment to this discussion.
    Then open up the log file.
    You will see that one argument is the comment. You need that for the user that should be notified.
    Another argument is the Activity. You need that as a blueprint.
    And you have got the ActivityModel. You need that to queue your rubbish ;)

    public function commentModel_beforeNotification_handler($sender, $args) {
        $author = $args['Comment']['InsertUserID'];
        $activity = $args['Activity'];
        $activityModel = $args['ActivityModel'];
    
        $activity['NotifyUserID'] = $author;
        $activity['Data']['Reason'] = 'participated';
        $activityModel->queue(
            $activity,
            'ParticipateComment',
            array(
                'CheckRecord' => true,
                'Force' => true
            )
        );
    }
    

    See what I did? I put together what we had above and added 'Force' => true because that's what will cause the method queue to not kill this entry.

Sign In or Register to comment.