Setting user lastonline field does not work as expected?

Technical Support
  • #1


    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', - 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:

    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.

  • Plugin & Theme Dev

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


    and do you have email subscriptions enabled in ACP?

  • #3

    @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.

Suggested Topics

| | | |