Setting user lastonline field does not work as expected?



  • @julian

    I want to send a chat message to a user, and to ensure that the user will be notified via email, I set the user's lastonline to 5 minutes before current timestamp.

    I see that the user's lastonline field is being set correctly (verified via api call), but the user is still not being notified via email.

    // set lastonline field to 5 minutes before current timestamp
    Users.setUserField(req.params.uid, 'lastonline', Date.now() - 300000, function(err) {
            Messaging.newRoom(req.user.uid, [req.params.uid], function(err, roomId) {
                    Messaging.addMessage(req.user.uid, roomId, req.body.message, timestamp, function(err, message) {
                            // this should send an email notification to the user
                            Messaging.notifyUsersInRoom(req.user.uid, roomId, message);
    
                            return errorHandler.handle(err, res, message);
                    });
            });
    });
    

    This is the condition which determines whether the user is online:
    https://github.com/NodeBB/NodeBB/blob/dcb73f9647bd73acce0d0907d04d060e7fe05eb7/src/user.js#L152

    I print the lastonline field value inside the isOnline method, which prints the previous set value and this is strange. Is this due to some kind of caching in the db layer? I am using mongodb by the way.

    This commit shows that to make the user offline, all that's needed is to set the lastonline field, so I am not sure what I'm missing.
    https://github.com/NodeBB/NodeBB/commit/18e68346e713fce2efb49aff0b18bd2bbf0be332


  • Plugin & Theme Dev

    @wktang is this option enabled for the user in their settings?

    0_1465514394933_upload-d3d594cf-c7c1-4266-a7e6-39c90d7702f8

    and do you have email subscriptions enabled in ACP?



  • @pichalite Yes. I have tested that if the user is not currently online, the user is able to receive email from executing the above code.


Log in to reply
 

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.