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.

Enable 'Category Notifications' by default?

Hi guys,

I want to setup my forums to default to notify all my users when a new Discussion is added to specific categories. Is that possible via something like:

$Configuration['Preferences']['Email']['MyCategoryName'] = '1';

I see requests from this previously, but no answers...

I don't my SQL hacking for my current users, but would really like to enable this automatically for new users...

Comments

  • R_JR_J Ex-Fanboy Munich Admin

    I cannot imagine that it is doable by setting a config parameter. But a very small and easy plugin will do.

    Something like that should be enough:

    class YourPluginsNamePlugin extends Gdn_Plugin {
        public function userModel_afterInsertUser_handler($sender, $args) {
            $this->setUserMeta(
                $args['InsertUserID'],
                'Preferences.Email.NewDiscussion.X', // replace the X with the category ID
                '1'
            );
        }
    }
    

    Please look at an example if you are not sure how a plugin for Vanilla must be named/structured

  • R_J - thanks! That looks really promising...

    But after fiddling a bit, I see this in the UserMeta table:

    Plugin.SetupNotifications.Preferences.Email.NewDiscussion.1 = 1

    So, its prepending "Plugin.SetupNotifications" to the setting I'm trying to do. Makes sense, the code comments say:

         * ++ Before any queries are run, $key is converted to its fully qualified format (Plugin.<PluginName> prepended)
         * ++ to prevent collisions in the meta table when multiple plugins have similar key names.
    

    Which makes sense, but is also a bummer when I really do want to change pre-existing keys.

    But, all this shows what SQL scripts I need to write, so unless there's an obvious fix, I'll just go that route.

  • R_JR_J Ex-Fanboy Munich Admin

    Your plugin is extending the plugin class. If you look at /library/core/class.plugin.php you will find the method setUserMeta with this code:

        protected function setUserMeta($userID, $key, $value = null) {
            $metaKey = $this->makeMetaKey($key);
            $this->userMetaModel()->setUserMeta($userID, $metaKey, $value);
        }
    

    What you can see is that the function creates a "metaKey" and that is something that you do not want to (I haven't thought of that, sorry)

    But what you can also see is that after transforming the key somehow $this->userMetaModel()->setUserMeta() is called. There is nothing that prevents you from using it directly that way. In my code from the previous post, simply replace $this->setUserMeta( by $this->userMetaModel()->setUserMeta( and that should be all what is needed.

  • BINGO!

    Much appreciated!

  • @R_J thanks a lot for the solution. That worked for me in case of new users.

    But, for existing 26K+ users in my forum how I'll set that?

    Thanks in advance.

  • R_JR_J Ex-Fanboy Munich Admin

    Well, I will tell you two things: 1. how to achieve what you've asked for and 2. that you shouldn't do it.

    I start with the second one: If your users are current users and they never wanted to get notified about new discussion, changing their notification settings feels like ignoring their current decision which in the end feels like spam.

    But if that for any reason doesn't apply to your situation (I didn't want to judge, just wanted to utter my concerns) here is what you have to do: the preferences are saved to the GDN_UserMeta table. For existing users I would say you should change it with an SQL. You will need to replace the number 1984 below with your CategoryID:


    INSERT INTO GDN_UserMeta
    SELECT
     u.UserID
     , 'Preferences.Email.NewDiscussion.1984'
     , 1
    FROM GDN_User u
    WHERE
     u.Deleted = 0
     AND u.UserID NOT IN (
       SELECT
         um.UserID
       FROM GDN_UserMeta um
       WHERE
         Name = 'Preferences.Email.NewDiscussion.1984'
     )
    
Sign In or Register to comment.