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';
|
|
|
|
|
|
|
|
export default function userInactivityInspect(userId, responseDelay) {
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-02-27 01:40:01 +08:00
|
|
|
const cb = (err, numChanged) => {
|
2019-02-22 05:09:44 +08:00
|
|
|
if (err) {
|
|
|
|
return Logger.error(`Inactivity check for user ${userId}: ${err}`);
|
|
|
|
}
|
|
|
|
|
2019-02-27 01:40:01 +08:00
|
|
|
if (numChanged) {
|
|
|
|
return Logger.info(`Updated user ${userId} with inactivity inspect`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2019-02-22 05:09:44 +08:00
|
|
|
};
|
|
|
|
|
2019-02-27 01:40:01 +08:00
|
|
|
return Users.update(selector, modifier, cb);
|
2019-02-22 05:09:44 +08:00
|
|
|
}
|