2019-02-22 05:09:44 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import Users from '/imports/api/users';
|
|
|
|
|
2023-03-15 21:18:31 +08:00
|
|
|
export default async function userInactivityInspect(userId, responseDelay) {
|
2019-02-22 05:09:44 +08:00
|
|
|
check(userId, String);
|
|
|
|
check(responseDelay, Match.Integer);
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
userId,
|
2019-02-27 01:40:01 +08:00
|
|
|
inactivityCheck: false,
|
2019-02-22 05:09:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
$set: {
|
|
|
|
inactivityCheck: true,
|
|
|
|
responseDelay,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
try {
|
2023-03-15 21:18:31 +08:00
|
|
|
const { numberAffected } = await Users.updateAsync(selector, modifier);
|
2019-02-22 05:09:44 +08:00
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
if (numberAffected) {
|
|
|
|
Logger.info(`Updated user ${userId} with inactivity inspect`);
|
2019-02-27 01:40:01 +08:00
|
|
|
}
|
2020-11-23 21:13:46 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Inactivity check for user ${userId}: ${err}`);
|
|
|
|
}
|
2019-02-22 05:09:44 +08:00
|
|
|
}
|