Setting user lastonline field does not work as expected?
-
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#L152I print the
lastonline
field value inside theisOnline
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