2022-09-21 14:33:17 +02:00
|
|
|
Meteor.publish('user-miniprofile', function (usernames) {
|
2021-01-28 18:18:31 +02:00
|
|
|
check(usernames, Array);
|
2015-12-08 16:18:44 -05:00
|
|
|
|
2021-01-28 18:18:31 +02:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
// console.log('usernames:', usernames);
|
|
|
|
return Users.find(
|
2021-01-30 02:35:29 +02:00
|
|
|
{
|
|
|
|
$or: [
|
|
|
|
{ username: { $in: usernames } },
|
|
|
|
{ importUsernames: { $in: usernames } },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: {
|
|
|
|
...Users.safeFields,
|
|
|
|
importUsernames: 1,
|
|
|
|
},
|
|
|
|
},
|
2021-01-28 18:18:31 +02:00
|
|
|
);
|
2015-12-08 16:18:44 -05:00
|
|
|
});
|
2017-02-24 22:10:38 +08:00
|
|
|
|
2022-09-21 14:33:17 +02:00
|
|
|
Meteor.publish('user-admin', function () {
|
2017-02-24 22:10:38 +08:00
|
|
|
return Meteor.users.find(this.userId, {
|
|
|
|
fields: {
|
|
|
|
isAdmin: 1,
|
2021-07-23 10:39:42 +02:00
|
|
|
teams: 1,
|
|
|
|
orgs: 1,
|
2021-09-01 11:40:54 +02:00
|
|
|
authenticationMethod: 1,
|
2017-02-24 22:10:38 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2018-10-03 11:50:52 +03:00
|
|
|
|
2022-09-21 14:33:17 +02:00
|
|
|
Meteor.publish('user-authenticationMethod', function (match) {
|
2018-10-03 11:50:52 +03:00
|
|
|
check(match, String);
|
2019-06-28 12:52:09 -05:00
|
|
|
return Users.find(
|
|
|
|
{ $or: [{ _id: match }, { email: match }, { username: match }] },
|
|
|
|
{
|
|
|
|
fields: {
|
|
|
|
authenticationMethod: 1,
|
2021-07-23 10:39:42 +02:00
|
|
|
teams: 1,
|
|
|
|
orgs: 1,
|
2019-06-28 12:52:09 -05:00
|
|
|
},
|
2018-10-03 11:50:52 +03:00
|
|
|
},
|
2019-06-28 12:52:09 -05:00
|
|
|
);
|
2018-10-03 11:50:52 +03:00
|
|
|
});
|
2022-09-21 14:33:17 +02:00
|
|
|
|
|
|
|
// update last connection date and last connection average time (in seconds) for a user
|
|
|
|
// function UpdateLastConnectionDateAndLastConnectionAverageTime(lstUsers) {
|
|
|
|
// let lastConnectionAverageTime;
|
|
|
|
// lstUsers.forEach((currentUser) => {
|
|
|
|
// lastConnectionAverageTime =
|
|
|
|
// currentUser.lastConnectionAverageTimeInSecs !== undefined
|
|
|
|
// ? currentUser.lastConnectionAverageTimeInSecs
|
|
|
|
// : 0;
|
|
|
|
// lastConnectionAverageTime =
|
|
|
|
// currentUser.lastConnectionDate !== undefined
|
|
|
|
// ? ((new Date().getTime() - currentUser.lastConnectionDate.getTime()) /
|
|
|
|
// 1000 +
|
|
|
|
// lastConnectionAverageTime) /
|
|
|
|
// 2
|
|
|
|
// : 0;
|
|
|
|
|
|
|
|
// Users.update(currentUser._id, {
|
|
|
|
// $set: {
|
|
|
|
// lastConnectionDate: new Date(),
|
|
|
|
// lastConnectionAverageTimeInSecs: parseInt(lastConnectionAverageTime),
|
|
|
|
// },
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (Meteor.isServer) {
|
|
|
|
Meteor.onConnection(function (connection) {
|
|
|
|
// console.log(
|
|
|
|
// 'Meteor.server.stream_server.open_sockets',
|
|
|
|
// Meteor.server.stream_server.open_sockets,
|
|
|
|
// );
|
|
|
|
//console.log('connection.Id on connection...', connection.id);
|
|
|
|
// connection.onClose(() => {
|
|
|
|
// console.log('connection.Id on close...', connection.id);
|
|
|
|
// // Get all user that were connected to this socket
|
|
|
|
// // And update last connection date and last connection average time (in seconds) for each user
|
|
|
|
// let lstOfUserThatWasConnectedToThisSocket = Users.find({
|
|
|
|
// lastconnectedSocketId: connection.id,
|
|
|
|
// }).fetch();
|
|
|
|
// if (
|
|
|
|
// lstOfUserThatWasConnectedToThisSocket !== undefined &&
|
|
|
|
// lstOfUserThatWasConnectedToThisSocket.length > 0
|
|
|
|
// ) {
|
|
|
|
// console.log({ lstOfUserThatWasConnectedToThisSocket });
|
|
|
|
// UpdateLastConnectionDateAndLastConnectionAverageTime(
|
|
|
|
// lstOfUserThatWasConnectedToThisSocket,
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
|
|
|
|
// Meteor.server.stream_server.open_sockets.forEach((socket) =>
|
|
|
|
// console.log('meteor session', socket._meteorSession.userId),
|
|
|
|
// );
|
|
|
|
|
|
|
|
// update last connected user date (neddeed for one of the KPI)
|
|
|
|
Meteor.server.stream_server.open_sockets.forEach(
|
|
|
|
(socket) =>
|
|
|
|
//console.log('meteor session', socket._meteorSession.userId),
|
|
|
|
socket._meteorSession?.userId !== null &&
|
|
|
|
Users.update(socket._meteorSession.userId, {
|
|
|
|
$set: {
|
|
|
|
lastConnectionDate: new Date(),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|