mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
Both issues ask the same question: which users are actively using WeKan, and for how long. The `lastConnectionDate` field already existed on the user schema but was only ever written from a commented-out, env-gated block in server/publications/users.js - so WeKan never actually recorded it. Accounts.onLogin now stamps it on every successful login (server/lastActiveOnLogin.js), and an open client session refreshes it every two minutes via a `usersHeartbeat` method (client/lastActiveHeartbeat.js, server/methods/lastActiveHeartbeat.js) - a periodic timestamp, not a WebSocket/real-time presence system, which is more than either issue asked for. Admin Panel / People gets a "Last active" column showing each user's timestamp with an online-now badge when it is within five minutes (models/lib/lastActive.js holds the pure recency check, reused by the unit test). "Last active" and "Online now" are added to en.i18n.json and translated into 203 other locale files; the remaining minority keep the English source as the untranslated-everywhere placeholder. Thanks to eccaw and xet7 ! Closes #3678, Closes #3734,
24 lines
942 B
JavaScript
24 lines
942 B
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
|
|
// Presence for Admin Panel > People (GitHub #3678, #3734): the "refreshed while
|
|
// active" half of the last-active timestamp. server/lastActiveOnLogin.js sets
|
|
// it once per login; this lets an open client session (client/lastActiveHeartbeat.js)
|
|
// keep it current without a full presence/WebSocket system - a periodic
|
|
// timestamp write is all either issue actually asked for.
|
|
//
|
|
// Deliberately unthrottled server-side beyond "once per call": the client only
|
|
// calls this every few minutes (see the heartbeat interval), and a user can
|
|
// only update their OWN lastConnectionDate, never anyone else's.
|
|
Meteor.methods({
|
|
async usersHeartbeat() {
|
|
const userId = this.userId;
|
|
if (!userId) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user');
|
|
}
|
|
await Meteor.users.updateAsync(userId, {
|
|
$set: { lastConnectionDate: new Date() },
|
|
});
|
|
return true;
|
|
},
|
|
});
|