Alright, problem fixed, thanks guys.
It was because of the template whitespace/indents messing up since I was copying from a file into the terminal.
Thanks 🙂
We have about 4 categories 1 parent, 3 children, that are very noisy. Instead of asking everybody to change from "Watching" to "Ignoring" for those categories. Is there a way I can change the default for all users?
No way to do this in core right now, you can write a plugin and on user create ignore those categories.
User create isn't going to work. I need to do this for my existing 12k member. Is there any documentation on the various data models?
I've tried looking at the code to figure it out but I'm struggling.
In that case you would want to run a one time script to ignore those categories for all users.
First make a backup of your database, then place the below script in your nodebb root folder. After that modify the cidsToIgnore
array and add the category ids you want ignored. Once you run it those categories will be ignored for all users. Keep in mind you still need a plugin that watches for new users and ignore those categories if you don't want them to do it manually.
/*globals require, console, process */
'use strict';
var nconf = require('nconf');
var async = require('async');
nconf.file({
file: 'config.json'
});
nconf.defaults({
base_dir: __dirname,
views_dir: './build/public/templates',
});
var db = require('./src/database');
db.init(function(err) {
if (err) {
console.log("NodeBB could not connect to your database. Error: " + err.message);
process.exit();
}
ignoreCategories(function (err) {
if (err) {
console.error(err);
process.exit();
}
console.log('done');
process.exit();
});
});
function ignoreCategories(callback) {
var batch = require('./src/batch');
batch.processSortedSet('users:joindate', function (uids, next) {
ignoreCategory(uids, next);
}, function (err) {
callback(err);
});
}
function ignoreCategory(uids, callback) {
const now = Date.now();
const cidsToIgnore = []; // add the cids that will be ignore to this array
const sets = uids.map(uid => 'uid:' + uid + ':ignored:cids');
async.eachSeries(cidsToIgnore, function (cid, next) {
db.sortedSetsAdd(sets, now, cid, next);
}, callback);
}
For some more info about the database take a look at https://github.com/NodeBB/NodeBB/wiki/Database-Structure
It appears that "Unwatching" a category also removes it from appearing in the Digest email, right?
@baris I'm not sure why but that script stopped working. I think it stopped when I upgraded to 1.11.x
@djensen47 hey there! It could be because category watch state is now able to be set globally!
Give that a spin and see if that's what you originally wanted
That script is no longer compatible with latest the set names changed.
@julian said in Category watch/ignore set default for all users?:
@djensen47 hey there! It could be because category watch state is now able to be set globally!
Give that a spin and see if that's what you originally wanted
Yeah, awesome, this is exactly what we wanted.
@julian I can't seem to find the setting. Where do I change the global default? Is this feature on 1.12 or master?
Here it is, I knew I wasn't crazy
@julian Okay, thanks. I misinterpreted the the settings. I thought this was a per category global setting. This is a global all categories setting.
What I need is to set the default for about 5 or our categories to "Ignored" and "Watch" for the rest.
@baris said in Category watch/ignore set default for all users?:
That script is no longer compatible with latest the set names changed.
What are the new names?
@djensen47 cid:<cid>:ignorers
and uid:<uid>:ignored:cids
got removed there is a single set cid:<cid>:uid:watch:state
@baris So the _key
is as you described, the value
is the user id, and the score
is the watch state?
So I can't just write these records, I need to check for existing, handle that and continue.
Sorry, I'm trying to follow but I'm just not understanding how the database model works. I try digging into the code and go to db.sortedSetsAdd to see what that actually does but there's no docs so I read some more code and it adds a records but I'm not understanding what it means and why. I'm stuck now but I'll figure it out eventually. Thanks.
@djensen47 said in Category watch/ignore set default for all users?:
@baris So the _key is as you described, the value is the user id, and the score is the watch state?
That's correct, and the records do not exist until a user explicitly changes the setting on the category page. Until they change it the default from the ACP is used.
There are 3 possible values. https://github.com/NodeBB/NodeBB/blob/master/src/categories/watch.js#L9