Change default category watch state for administrator
-
If you really want every user to watch a category I would suggest using a plugin to automatically watch the category on user creation. It can be done with the
action:user.create
hook.// in plugin.json "hooks" : { "action:user.create": "onUserCreate" } // in library.js of your plugin const categories = require.main.require('./src/categories'); plugin.onUserCreate = async function ({ user }) { const announcementCategory = 1; await user.setCategoryWatchState(user.uid, [announcementCategory], categories.watchStates.watching); };
-
It is not an entire plugin but it's the only code you need in a plugin to achieve what you want. A plugin has some boilerpate code. You can see a full starter plugin at https://github.com/NodeBB/nodebb-plugin-quickstart. The plugin docs also go over the details https://docs.nodebb.org/development/quickstart/
-
@baris Hmm, ok, I think I'm close to having built this small plugin. It's tripping up on the setting of the watch state, with:
error: TypeError: user.setCategoryWatchState is not a function
The only thing I've tried to deal with this error so far is to add in to library.js:
const user = require.main.require('./src/user');
And unfortunately that didn't change anything with regard to the error. I presume I'm close here but am not sure what else is missing to cause the lack of the function.
-
Can you put your plugin up on github or similar so we can see? That function is here so the below should work
const user = require.main.require('./src/user'); const categories = require.main.require('./src/categories'); await user.setCategoryWatchState(user.uid, [announcementCategory], categories.watchStates.watching);
-
Hmm, ok, I wonder what I'm doing incorrectly then. Maybe I stripped too much out of the quickstart or I haven't done something properly when updating the library.js? Here's the code:
GitHub - realkinetix/nodebb-plugin-auto-set-watch-categories: Plugin to set category watching on user creation
Plugin to set category watching on user creation. Contribute to realkinetix/nodebb-plugin-auto-set-watch-categories development by creating an account on GitHub.
GitHub (github.com)