SOLVED All users' status is invisible


  • I recently migrated my forums from SMF to NodeBB. And one thing that I noticed is that everybody has their status set to invisible.
    Is there any way to change this setting for all 12k of my users on the forum?

  • Global Moderator Plugin & Theme Dev

    Here's a script you can use to change the status of all users:

    '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');
    
    async.series([
    	db.init,
    	setUsersOnline,
    ], (err) => {
    	if (err) {
    		console.error(err);
    		process.exit(1);
    	}
    
    	process.exit();
    });
    
    function setUsersOnline(callback) {
    	var batch = require('./src/batch');
    	batch.processSortedSet('users:joindate', function (uids, next) {
    		const lastonline = Date.now();
    		const data = {
    			lastonline,
    			status: 'online',
    		};
    		async.parallel([
    			cb => async.each(uids, (uid, next) => {
    				db.setObject(`user:${uid}`, data, next);
    			}, cb),
    			cb => db.sortedSetAdd('users:online', uids.map(() => lastonline), uids, cb),
    		], next);
    	}, callback);
    }
    

    Create a new file called set-users-online.js in your main nodebb directory (the one with config.js etc), paste that script into it, and run node set-users-online from within that directory to set all of your users to online.

    However, I'm not sure why your default for status would be Invisible in the first place. As far as I can tell, it's Online by default. You mentioned it's every user, how did you confirm that?


  • @PitaJ Whenever I'm looking at online users, they're always invisible. All of the migrated accounts that I use were also invisible.

  • NodeBB


  • @baris Thanks @baris should I run this script or wait for the next release with the bug fix?

  • NodeBB

    No need to run the script, just wait for the next release, or run master if you are brave 😆


  • @baris What's the timeline for the next release?

  • NodeBB


  • sorry for pulling this topic up.  but we face the same problem: after migrating from a proprietary forum software four out of five users logged on are set to "offline" while they are obviously online and active.  the "online" users are either new or changed their status manually.

    the title should be "all migrated users' status is invisible"

    on the one hand i have basically no idea where to run the script mentioned by @PitaJ.  on the other i'm not sure if the value of lastonline will be written to Date.now() then which would be nice to leave unchanged.

    i'm wondering why a user isn't set to "online" by default with every login and has to change the status every time to "offline" or whatever manually if needed?!

  • NodeBB

    @pitaj mentioned where to put the file, it goes into your nodebb installation folder, so in the same folder as your config.json.

    A user is set to online when they register and then it is up to the user to change the status. For example a user can set their status to offline if they don't want to be seen online.


  • @baris said in All users' status is invisible:

    @pitaj mentioned where to put the file, it goes into your nodebb installation folder, so in the same folder as your config.json.

    you are right.  one should read until the end of a post.  sorry.

    A user is set to online when they register and then it is up to the user to change the status. For example a user can set their status to offline if they don't want to be seen online.

    i know.  but more than 29,000 migrated users were set to offline (by fault) and didn't choose it.

    frankly speaking i would expect the software to set my status to online whenever i log on.  let's say my status was set to absent - for whatever reason i forgot in the meantime - before i logged out.  when i come back later i'm not absent anymore - i'm online.  in my opinion it should be no choice - for a normal user at least - to stay invisible forever.

    the other question was if the value of lastonline will be changed by the script to Date.now() or not?  i would prefer to leave it unchanged.

  • NodeBB

    @pitaj said in All users' status is invisible:

    const data = {
    lastonline,
    status: 'online',
    };

    The script @pitaj posted will set lastonline field of the user to Date.now if you don't want that remove it from the data object above.

    Just to reiterate the offline status is special in that when the user sets themselves offline they appear offline to other users even if they are online. But admins can still them on /users?section=online.

    Also if a user's status is set online and they aren't active for more than x minutes their status will be returned as offline until they come back. The value of the status field in the database isn't modified automatically by nodebb it is only changed if the user changes it manually.


  • @baris thank you for the detailed explanation.  i was afraid setting lastonline to Date.now() is needed to manipulate the status field in the database.

    we have already seen that users are automatically set to offline after some [30?] minutes of inactivity - this is absolutely wanted as long as the status field in the database stays untouched.  great!


  • @baris said in All users' status is invisible:

    The script @pitaj posted will set lastonline field of the user to Date.now if you don't want that remove it from the data object above.

    unfortunately we had to remove the other lastonline line(s) in setUsersOnline()too.

    function setUsersOnline(callback) {
    	var batch = require('./src/batch');
    	batch.processSortedSet('users:joindate', function (uids, next) {
    //		const lastonline = Date.now();
    		const data = {
    //			lastonline,
    			status: 'online',
    		};
    		async.parallel([
    			cb => async.each(uids, (uid, next) => {
    				db.setObject(`user:${uid}`, data, next);
    			}, cb),
    //			cb => db.sortedSetAdd('users:online', uids.map(() => lastonline), uids, cb),
    		], next);
    	}, callback);
    }
    

    no idea why lastonline is manipulated by the script anyway.  to force a re-login to see it taking effect the forum was rebuild and restarted after running the script.

Suggested Topics

  • 5
  • 1
  • 3
  • 4
  • 2
| |