Skip to content

Commit

Permalink
fix: fire action:user.online on user login
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Mar 28, 2023
1 parent 188ec62 commit 7397873
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/controllers/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ authenticationController.onSuccessfulLogin = async function (req, uid) {
}),
user.auth.addSession(uid, req.sessionID),
user.updateLastOnlineTime(uid),
user.updateOnlineUsers(uid),
user.onUserOnline(uid, Date.now()),
analytics.increment('logins'),
db.incrObjectFieldBy('global', 'loginCount', 1),
]);
Expand Down
8 changes: 6 additions & 2 deletions src/user/online.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ module.exports = function (User) {
if (now - parseInt(userOnlineTime, 10) < 300000) {
return;
}
await db.sortedSetAdd('users:online', now, uid);
await User.onUserOnline(uid, now);
topics.pushUnreadCount(uid);
plugins.hooks.fire('action:user.online', { uid: uid, timestamp: now });
};

User.onUserOnline = async (uid, timestamp) => {
await db.sortedSetAdd('users:online', timestamp, uid);
plugins.hooks.fire('action:user.online', { uid, timestamp });
};

User.isOnline = async function (uid) {
Expand Down

0 comments on commit 7397873

Please sign in to comment.