users.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. Meteor.publish('user-miniprofile', function (usernames) {
  2. check(usernames, Array);
  3. // eslint-disable-next-line no-console
  4. // console.log('usernames:', usernames);
  5. return Users.find(
  6. {
  7. $or: [
  8. { username: { $in: usernames } },
  9. { importUsernames: { $in: usernames } },
  10. ],
  11. },
  12. {
  13. fields: {
  14. ...Users.safeFields,
  15. importUsernames: 1,
  16. },
  17. },
  18. );
  19. });
  20. Meteor.publish('user-admin', function () {
  21. return Meteor.users.find(this.userId, {
  22. fields: {
  23. isAdmin: 1,
  24. teams: 1,
  25. orgs: 1,
  26. authenticationMethod: 1,
  27. },
  28. });
  29. });
  30. Meteor.publish('user-authenticationMethod', function (match) {
  31. check(match, String);
  32. return Users.find(
  33. { $or: [{ _id: match }, { email: match }, { username: match }] },
  34. {
  35. fields: {
  36. authenticationMethod: 1,
  37. teams: 1,
  38. orgs: 1,
  39. },
  40. },
  41. );
  42. });
  43. // update last connection date and last connection average time (in seconds) for a user
  44. // function UpdateLastConnectionDateAndLastConnectionAverageTime(lstUsers) {
  45. // let lastConnectionAverageTime;
  46. // lstUsers.forEach((currentUser) => {
  47. // lastConnectionAverageTime =
  48. // currentUser.lastConnectionAverageTimeInSecs !== undefined
  49. // ? currentUser.lastConnectionAverageTimeInSecs
  50. // : 0;
  51. // lastConnectionAverageTime =
  52. // currentUser.lastConnectionDate !== undefined
  53. // ? ((new Date().getTime() - currentUser.lastConnectionDate.getTime()) /
  54. // 1000 +
  55. // lastConnectionAverageTime) /
  56. // 2
  57. // : 0;
  58. // Users.update(currentUser._id, {
  59. // $set: {
  60. // lastConnectionDate: new Date(),
  61. // lastConnectionAverageTimeInSecs: parseInt(lastConnectionAverageTime),
  62. // },
  63. // });
  64. // });
  65. // }
  66. if (Meteor.isServer) {
  67. Meteor.onConnection(function (connection) {
  68. // console.log(
  69. // 'Meteor.server.stream_server.open_sockets',
  70. // Meteor.server.stream_server.open_sockets,
  71. // );
  72. //console.log('connection.Id on connection...', connection.id);
  73. // connection.onClose(() => {
  74. // console.log('connection.Id on close...', connection.id);
  75. // // Get all user that were connected to this socket
  76. // // And update last connection date and last connection average time (in seconds) for each user
  77. // let lstOfUserThatWasConnectedToThisSocket = Users.find({
  78. // lastconnectedSocketId: connection.id,
  79. // }).fetch();
  80. // if (
  81. // lstOfUserThatWasConnectedToThisSocket !== undefined &&
  82. // lstOfUserThatWasConnectedToThisSocket.length > 0
  83. // ) {
  84. // console.log({ lstOfUserThatWasConnectedToThisSocket });
  85. // UpdateLastConnectionDateAndLastConnectionAverageTime(
  86. // lstOfUserThatWasConnectedToThisSocket,
  87. // );
  88. // }
  89. // });
  90. // Meteor.server.stream_server.open_sockets.forEach((socket) =>
  91. // console.log('meteor session', socket._meteorSession.userId),
  92. // );
  93. // update last connected user date (needed for one of the KPI)
  94. Meteor.server.stream_server.open_sockets.forEach(
  95. (socket) =>
  96. //console.log('meteor session', socket._meteorSession.userId),
  97. socket._meteorSession?.userId !== null &&
  98. Users.update(socket._meteorSession.userId, {
  99. $set: {
  100. lastConnectionDate: new Date(),
  101. },
  102. }),
  103. );
  104. });
  105. }