Refactor: Migrate users for the Meteor 3.0 api

This commit is contained in:
Tainan Felipe 2023-03-15 10:18:31 -03:00 committed by Ramón Souza
parent f03cc32b56
commit 470937bf6f
38 changed files with 172 additions and 142 deletions

View File

@ -12,7 +12,7 @@ if (Meteor.isServer) {
// 1. meetingId
// 2. meetingId, userId
// { connection: Meteor.isClient ? null : true }
Users._ensureIndex({ meetingId: 1, userId: 1 });
Users.createIndexAsync({ meetingId: 1, userId: 1 });
}
export default Users;

View File

@ -1,11 +1,11 @@
import { check } from 'meteor/check';
import changeRole from '/imports/api/users/server/modifiers/changeRole';
export default function handleChangeRole(payload, meetingId) {
export default async function handleChangeRole(payload, meetingId) {
check(payload.body, Object);
check(meetingId, String);
const { userId, role, changedBy } = payload.body;
changeRole(role, userId, meetingId, changedBy);
await changeRole(role, userId, meetingId, changedBy);
}

View File

@ -2,7 +2,7 @@ import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import Users from '/imports/api/users';
export default function handleEmojiStatus({ body }, meetingId) {
export default async function handleEmojiStatus({ body }, meetingId) {
const { userId, emoji } = body;
check(userId, String);
@ -21,7 +21,7 @@ export default function handleEmojiStatus({ body }, meetingId) {
};
try {
const numberAffected = Users.update(selector, modifier);
const numberAffected = await Users.updateAsync(selector, modifier);
if (numberAffected) {
Logger.info(`Assigned user emoji status ${emoji} id=${userId} meeting=${meetingId}`);

View File

@ -18,10 +18,10 @@ function setPresenterInPodReqMsg(credentials) { // TODO-- switch to meetingId, e
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
}
export default function handlePresenterAssigned({ body }, meetingId) {
export default async function handlePresenterAssigned({ body }, meetingId) {
const { presenterId, assignedBy } = body;
changePresenter(true, presenterId, meetingId, assignedBy);
await changePresenter(true, presenterId, meetingId, assignedBy);
const selector = {
meetingId,
@ -34,7 +34,7 @@ export default function handlePresenterAssigned({ body }, meetingId) {
podId: 'DEFAULT_PRESENTATION_POD',
};
const currentDefaultPod = PresentationPods.findOne(defaultPodSelector);
const currentDefaultPod = await PresentationPods.findOneAsync(defaultPodSelector);
const setPresenterPayload = {
meetingId,
@ -42,10 +42,10 @@ export default function handlePresenterAssigned({ body }, meetingId) {
presenterId,
};
const prevPresenter = Users.findOne(selector);
const prevPresenter = await Users.findOneAsync(selector);
if (prevPresenter) {
changePresenter(false, prevPresenter.userId, meetingId, assignedBy);
await changePresenter(false, prevPresenter.userId, meetingId, assignedBy);
}
/**
@ -55,7 +55,7 @@ export default function handlePresenterAssigned({ body }, meetingId) {
*/
if (currentDefaultPod.currentPresenterId !== presenterId) {
const presenterToBeAssigned = Users.findOne({ userId: presenterId });
const presenterToBeAssigned = await Users.findOneAsync({ userId: presenterId });
if (!presenterToBeAssigned) setPresenterPayload.presenterId = '';

View File

@ -2,11 +2,12 @@ import { check } from 'meteor/check';
import removeUser from '../modifiers/removeUser';
export default function handleRemoveUser({ body }, meetingId) {
export default async function handleRemoveUser({ body }, meetingId) {
const { intId } = body;
check(meetingId, String);
check(intId, String);
return removeUser(body, meetingId);
const result = await removeUser(body, meetingId);
return result;
}

View File

@ -1,7 +1,7 @@
import { check } from 'meteor/check';
import userInactivityInspect from '../modifiers/userInactivityInspect';
export default function handleUserInactivityInspect({ header, body }, meetingId) {
export default async function handleUserInactivityInspect({ header, body }, meetingId) {
const { userId } = header;
const { responseDelay } = body;
@ -9,6 +9,5 @@ export default function handleUserInactivityInspect({ header, body }, meetingId)
check(responseDelay, Match.Integer);
check(meetingId, String);
userInactivityInspect(userId, responseDelay);
await userInactivityInspect(userId, responseDelay);
}

View File

@ -2,10 +2,10 @@ import { check } from 'meteor/check';
import addUser from '../modifiers/addUser';
export default function handleUserJoined({ body }, meetingId) {
export default async function handleUserJoined({ body }, meetingId) {
const user = body;
check(user, Object);
addUser(meetingId, user);
await addUser(meetingId, user);
}

View File

@ -2,12 +2,12 @@ import { check } from 'meteor/check';
import userLeftFlag from '../modifiers/userLeftFlagUpdated';
export default function handleUserLeftFlag({ body }, meetingId) {
export default async function handleUserLeftFlag({ body }, meetingId) {
const user = body;
check(user, {
intId: String,
userLeftFlag: Boolean,
});
userLeftFlag(meetingId, user.intId, user.userLeftFlag);
await userLeftFlag(meetingId, user.intId, user.userLeftFlag);
}

View File

@ -1,7 +1,7 @@
import { check } from 'meteor/check';
import changePin from '../modifiers/changePin';
export default function handlePinAssigned({ body }, meetingId) {
export default async function handlePinAssigned({ body }, meetingId) {
const { userId, pin, changedBy } = body;
check(meetingId, String);
@ -9,5 +9,6 @@ export default function handlePinAssigned({ body }, meetingId) {
check(pin, Boolean);
check(changedBy, String);
return changePin(meetingId, userId, pin, changedBy);
const result = await changePin(meetingId, userId, pin, changedBy);
return result;
}

View File

@ -18,7 +18,7 @@ const clearOtherSessions = (sessionUserId, current = false) => {
.forEach(i => serverSessions[i].close());
};
export default function handleValidateAuthToken({ body }, meetingId) {
export default async function handleValidateAuthToken({ body }, meetingId) {
const {
userId,
valid,
@ -42,56 +42,71 @@ export default function handleValidateAuthToken({ body }, meetingId) {
if (pendingAuths.length === 0) return;
if (!valid) {
pendingAuths.forEach(
(pendingAuth) => {
await Promise.all(pendingAuths.map(
async (pendingAuth) => {
try {
const { methodInvocationObject } = pendingAuth;
const connectionId = methodInvocationObject.connection.id;
upsertValidationState(meetingId, userId, ValidationStates.INVALID, connectionId, reasonCode);
await upsertValidationState(
meetingId,
userId,
ValidationStates.INVALID,
connectionId,
reasonCode,
);
// Schedule socket disconnection for this user, giving some time for client receiving the reason of disconnection
Meteor.setTimeout(() => {
// Schedule socket disconnection for this user
// giving some time for client receiving the reason of disconnection
new Promise((resolve) => {
setTimeout(() => {
methodInvocationObject.connection.close();
}, 2000);
Logger.info(`Closed connection ${connectionId} due to invalid auth token.`);
resolve();
}, 2000);
});
} catch (e) {
Logger.error(`Error closing socket for meetingId '${meetingId}', userId '${userId}', authToken ${authToken}`);
}
},
);
));
return;
}
// Define user ID on connections
pendingAuths.forEach(
(pendingAuth) => {
await Promise.all(pendingAuths.map(
async (pendingAuth) => {
const { methodInvocationObject } = pendingAuth;
/* Logic migrated from validateAuthToken method ( postponed to only run in case of success response ) - Begin */
/* Logic migrated from validateAuthToken method
( postponed to only run in case of success response ) - Begin */
const sessionId = `${meetingId}--${userId}`;
methodInvocationObject.setUserId(sessionId);
const User = Users.findOne({
const User = await Users.findOneAsync({
meetingId,
userId,
});
if (!User) {
createDummyUser(meetingId, userId, authToken);
}else{
updateUserConnectionId(meetingId, userId, methodInvocationObject.connection.id);
await createDummyUser(meetingId, userId, authToken);
} else {
await updateUserConnectionId(meetingId, userId, methodInvocationObject.connection.id);
}
ClientConnections.add(sessionId, methodInvocationObject.connection);
upsertValidationState(meetingId, userId, ValidationStates.VALIDATED, methodInvocationObject.connection.id);
await upsertValidationState(
meetingId,
userId,
ValidationStates.VALIDATED,
methodInvocationObject.connection.id,
);
/* End of logic migrated from validateAuthToken */
},
);
));
const selector = {
meetingId,
@ -99,7 +114,7 @@ export default function handleValidateAuthToken({ body }, meetingId) {
clientType: 'HTML5',
};
const User = Users.findOne(selector);
const User = await Users.findOneAsync(selector);
// If we dont find the user on our collection is a flash user and we can skip
if (!User) return;
@ -121,7 +136,7 @@ export default function handleValidateAuthToken({ body }, meetingId) {
};
try {
const numberAffected = Users.update(selector, modifier);
const numberAffected = await Users.updateAsync(selector, modifier);
if (numberAffected) {
const sessionUserId = `${meetingId}-${userId}`;

View File

@ -5,7 +5,7 @@ import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
import { extractCredentials } from '/imports/api/common/server/helpers';
export default function assignPresenter(userId) { // TODO-- send username from client side
export default async function assignPresenter(userId) { // TODO-- send username from client side
try {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
@ -16,7 +16,7 @@ export default function assignPresenter(userId) { // TODO-- send username from c
check(requesterUserId, String);
check(userId, String);
const User = Users.findOne({
const User = await Users.findOneAsync({
meetingId,
userId,
});

View File

@ -3,7 +3,7 @@ import Logger from '/imports/startup/server/logger';
import { extractCredentials } from '/imports/api/common/server/helpers';
import setUserExitReason from '/imports/api/users/server/modifiers/setUserExitReason';
export default function setExitReason(reason) {
export default async function setExitReason(reason) {
try {
const { meetingId, requesterUserId } = extractCredentials(this.userId);
@ -14,8 +14,8 @@ export default function setExitReason(reason) {
check(requesterUserId, String);
check(reason, String);
setUserExitReason(meetingId, requesterUserId, reason);
await setUserExitReason(meetingId, requesterUserId, reason);
} catch (err) {
Logger.error(`Exception while invoking method setExitReason ${err.stack}`);
}
};
}

View File

@ -3,7 +3,7 @@ import Logger from '/imports/startup/server/logger';
import setMobile from '../modifiers/setMobile';
import { extractCredentials } from '/imports/api/common/server/helpers';
export default function setMobileUser() {
export default async function setMobileUser() {
try {
const { meetingId, requesterUserId } = extractCredentials(this.userId);
@ -12,7 +12,7 @@ export default function setMobileUser() {
Logger.verbose(`Mobile user ${requesterUserId} from meeting ${meetingId}`);
setMobile(meetingId, requesterUserId);
await setMobile(meetingId, requesterUserId);
} catch (err) {
Logger.error(`Exception while invoking method setMobileUser ${err.stack}`);
}

View File

@ -5,7 +5,7 @@ import { extractCredentials } from '/imports/api/common/server/helpers';
const LANGUAGES = Meteor.settings.public.app.audioCaptions.language.available;
export default function setSpeechLocale(locale) {
export default async function setSpeechLocale(locale) {
try {
const { meetingId, requesterUserId } = extractCredentials(this.userId);
@ -14,7 +14,7 @@ export default function setSpeechLocale(locale) {
check(locale, String);
if (LANGUAGES.includes(locale) || locale === '') {
updateSpeechLocale(meetingId, requesterUserId, locale);
await updateSpeechLocale(meetingId, requesterUserId, locale);
}
} catch (err) {
Logger.error(`Exception while invoking method setSpeechLocale ${err.stack}`);

View File

@ -5,7 +5,7 @@ import Logger from '/imports/startup/server/logger';
import { extractCredentials } from '/imports/api/common/server/helpers';
import setEffectiveConnectionType from '../modifiers/setUserEffectiveConnectionType';
export default function setUserEffectiveConnectionType(effectiveConnectionType) {
export default async function setUserEffectiveConnectionType(effectiveConnectionType) {
try {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
@ -22,7 +22,7 @@ export default function setUserEffectiveConnectionType(effectiveConnectionType)
effectiveConnectionType,
};
setEffectiveConnectionType(meetingId, requesterUserId, effectiveConnectionType);
await setEffectiveConnectionType(meetingId, requesterUserId, effectiveConnectionType);
Logger.verbose('Updated user effective connection', { requesterUserId, effectiveConnectionType });

View File

@ -5,7 +5,7 @@ import Logger from '/imports/startup/server/logger';
import { extractCredentials } from '/imports/api/common/server/helpers';
import { check } from 'meteor/check';
export default function userActivitySign() {
export default async function userActivitySign() {
try {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
@ -29,7 +29,7 @@ export default function userActivitySign() {
},
};
Users.update(selector, modifier); // TODO-- we should move this to a modifier
await Users.updateAsync(selector, modifier); // TODO-- we should move this to a modifier
Logger.info(`User ${userId} sent a activity sign for meeting ${meetingId}`);

View File

@ -6,7 +6,7 @@ import AuthTokenValidation from '/imports/api/auth-token-validation';
import Users from '/imports/api/users';
import ClientConnections from '/imports/startup/server/ClientConnections';
export default function userLeaving(meetingId, userId, connectionId) {
export default async function userLeaving(meetingId, userId, connectionId) {
try {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
@ -19,14 +19,14 @@ export default function userLeaving(meetingId, userId, connectionId) {
userId,
};
const user = Users.findOne(selector);
const user = await Users.findOneAsync(selector);
if (!user) {
Logger.info(`Skipping userLeaving. Could not find ${userId} in ${meetingId}`);
return;
}
const auth = AuthTokenValidation.findOne({
const auth = await AuthTokenValidation.findOneAsync({
meetingId,
userId,
}, { sort: { updatedAt: -1 } });

View File

@ -5,7 +5,8 @@ import ClientConnections from '/imports/startup/server/ClientConnections';
import { check } from 'meteor/check';
import UsersPersistentData from '/imports/api/users-persistent-data';
export default function userLeftMeeting() { // TODO-- spread the code to method/modifier/handler
export default async function userLeftMeeting() {
// TODO-- spread the code to method/modifier/handler
try {
// so we don't update the db in a method
const { meetingId, requesterUserId } = extractCredentials(this.userId);
@ -18,10 +19,10 @@ export default function userLeftMeeting() { // TODO-- spread the code to method/
userId: requesterUserId,
};
const numberAffected = Users.update(selector, { $set: { loggedOut: true } });
const numberAffected = await Users.updateAsync(selector, { $set: { loggedOut: true } });
if (numberAffected) {
UsersPersistentData.update(selector, { $set: { loggedOut: true } });
await UsersPersistentData.updateAsync(selector, { $set: { loggedOut: true } });
Logger.info(`user left id=${requesterUserId} meeting=${meetingId}`);
ClientConnections.removeClientConnection(this.userId, this.connection.id);
}

View File

@ -9,7 +9,7 @@ const AUTH_TIMEOUT = 120000;
async function validateAuthToken(meetingId, requesterUserId, requesterToken, externalId) {
let setTimeoutRef = null;
const userValidation = await new Promise((res, rej) => {
const userValidation = await new Promise(async (res, rej) => {
const observeFunc = (obj) => {
if (obj.validationStatus === ValidationStates.VALIDATED) {
clearTimeout(setTimeoutRef);
@ -43,7 +43,7 @@ async function validateAuthToken(meetingId, requesterUserId, requesterToken, ext
// Store reference of methodInvocationObject ( to postpone the connection userId definition )
pendingAuthenticationsStore.add(meetingId, requesterUserId, requesterToken, this);
upsertValidationState(
await upsertValidationState(
meetingId,
requesterUserId,
ValidationStates.VALIDATING,

View File

@ -1,7 +1,7 @@
import { check } from 'meteor/check';
import addUser from '/imports/api/users/server/modifiers/addUser';
export default function addDialInUser(meetingId, voiceUser) {
export default async function addDialInUser(meetingId, voiceUser) {
check(meetingId, String);
check(voiceUser, Object);
@ -26,6 +26,6 @@ export default function addDialInUser(meetingId, voiceUser) {
pin: false,
clientType: 'dial-in-user',
};
return addUser(meetingId, voiceOnlyUser);
const user = await addUser(meetingId, voiceOnlyUser);
return user;
}

View File

@ -16,7 +16,7 @@ const COLOR_LIST = [
'#0d47a1', '#0277bd', '#01579b',
];
export default function addUser(meetingId, userData) {
export default async function addUser(meetingId, userData) {
const user = userData;
check(meetingId, String);
@ -44,7 +44,7 @@ export default function addUser(meetingId, userData) {
meetingId,
userId,
};
const Meeting = Meetings.findOne({ meetingId });
const Meeting = await Meetings.findOneAsync({ meetingId });
/* While the akka-apps dont generate a color we just pick one
from a list based on the userId */
@ -71,11 +71,12 @@ export default function addUser(meetingId, userData) {
const modifier = {
$set: userInfos,
};
addUserPsersistentData(userInfos);
await addUserPsersistentData(userInfos);
// Only add an empty VoiceUser if there isn't one already and if the user coming in isn't a
// dial-in user. We want to avoid overwriting good data
if (user.clientType !== 'dial-in-user' && !VoiceUsers.findOne({ meetingId, intId: userId })) {
addVoiceUser(meetingId, {
const voiceUser = await VoiceUsers.findOneAsync({ meetingId, intId: userId });
if (user.clientType !== 'dial-in-user' && !voiceUser) {
await addVoiceUser(meetingId, {
voiceUserId: '',
intId: userId,
callerName: user.name,
@ -94,14 +95,14 @@ export default function addUser(meetingId, userData) {
* In some cases the user information is set after the presenter is set
* causing the first moderator to join a meeting be marked as presenter: false
*/
const partialUser = Users.findOne(selector);
const partialUser = await Users.findOneAsync(selector);
if (partialUser?.presenter) {
modifier.$set.presenter = true;
}
try {
const { insertedId } = Users.upsert(selector, modifier);
const { insertedId } = await Users.upsertAsync(selector, modifier);
if (insertedId) {
Logger.info(`Added user id=${userId} meeting=${meetingId}`);

View File

@ -1,7 +1,7 @@
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
export default function changePin(meetingId, userId, pin, changedBy) {
export default async function changePin(meetingId, userId, pin, changedBy) {
const selector = {
meetingId,
userId,
@ -14,7 +14,7 @@ export default function changePin(meetingId, userId, pin, changedBy) {
};
try {
const numberAffected = Users.update(selector, modifier);
const numberAffected = await Users.updateAsync(selector, modifier);
if (numberAffected) {
Logger.info(`Change pin=${pin} id=${userId} meeting=${meetingId} changedBy=${changedBy}`);

View File

@ -1,7 +1,7 @@
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
export default function changePresenter(presenter, userId, meetingId, changedBy) {
export default async function changePresenter(presenter, userId, meetingId, changedBy) {
const selector = {
meetingId,
userId,
@ -14,7 +14,7 @@ export default function changePresenter(presenter, userId, meetingId, changedBy)
};
try {
const numberAffected = Users.update(selector, modifier);
const numberAffected = await Users.updateAsync(selector, modifier);
if (numberAffected) {
Logger.info(`Changed presenter=${presenter} id=${userId} meeting=${meetingId}`

View File

@ -2,7 +2,7 @@ import Logger from '/imports/startup/server/logger';
import updateRole from '/imports/api/users-persistent-data/server/modifiers/updateRole';
import Users from '/imports/api/users';
export default function changeRole(role, userId, meetingId, changedBy) {
export default async function changeRole(role, userId, meetingId, changedBy) {
const selector = {
meetingId,
userId,
@ -15,7 +15,7 @@ export default function changeRole(role, userId, meetingId, changedBy) {
};
try {
const numberAffected = Users.update(selector, modifier);
const numberAffected = await Users.updateAsync(selector, modifier);
if (numberAffected) {
updateRole(userId, meetingId, role);

View File

@ -1,10 +1,10 @@
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users/index';
export default function clearUsers(meetingId) {
export default async function clearUsers(meetingId) {
if (meetingId) {
try {
const numberAffected = Users.remove({ meetingId });
const numberAffected = await Users.removeAsync({ meetingId });
if (numberAffected) {
Logger.info(`Cleared Users (${meetingId})`);
@ -14,7 +14,7 @@ export default function clearUsers(meetingId) {
}
} else {
try {
const numberAffected = Users.remove({});
const numberAffected = await Users.removeAsync({});
if (numberAffected) {
Logger.info('Cleared Users (all)');

View File

@ -3,12 +3,12 @@ import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
export default function createDummyUser(meetingId, userId, authToken) {
export default async function createDummyUser(meetingId, userId, authToken) {
check(meetingId, String);
check(userId, String);
check(authToken, String);
const User = Users.findOne({ meetingId, userId });
const User = await Users.findOneAsync({ meetingId, userId });
if (User) {
throw new Meteor.Error('existing-user', 'Tried to create a dummy user for an existing user');
}
@ -23,7 +23,7 @@ export default function createDummyUser(meetingId, userId, authToken) {
};
try {
const insertedId = Users.insert(doc);
const insertedId = await Users.insertAsync(doc);
if (insertedId) {
Logger.info(`Created dummy user id=${userId} token=${authToken} meeting=${meetingId}`);

View File

@ -24,7 +24,7 @@ const disconnectUser = (meetingId, userId) => {
}
};
export default function removeUser(body, meetingId) {
export default async function removeUser(body, meetingId) {
const { intId: userId, reasonCode } = body;
check(meetingId, String);
check(userId, String);
@ -39,30 +39,31 @@ export default function removeUser(body, meetingId) {
// since the backend is supposed to update Mongo
if ((process.env.BBB_HTML5_ROLE !== 'frontend')) {
if (body.eject) {
userEjected(meetingId, userId, reasonCode);
await userEjected(meetingId, userId, reasonCode);
}
setloggedOutStatus(userId, meetingId, true);
VideoStreams.remove({ meetingId, userId });
await setloggedOutStatus(userId, meetingId, true);
await VideoStreams.removeAsync({ meetingId, userId });
clearUserInfoForRequester(meetingId, userId);
await clearUserInfoForRequester(meetingId, userId);
const currentUser = UsersPersistentData.findOne({ userId, meetingId });
const currentUser = await UsersPersistentData.findOneAsync({ userId, meetingId });
const hasMessages = currentUser?.shouldPersist?.hasMessages?.public || currentUser?.shouldPersist?.hasMessages?.private;
const hasConnectionStatus = currentUser?.shouldPersist?.hasConnectionStatus;
if (!hasMessages && !hasConnectionStatus) {
UsersPersistentData.remove(selector);
await UsersPersistentData.removeAsync(selector);
}
Users.remove(selector);
clearVoiceUser(meetingId, userId);
await Users.removeAsync(selector);
await clearVoiceUser(meetingId, userId);
}
if (!process.env.BBB_HTML5_ROLE || process.env.BBB_HTML5_ROLE === 'frontend') {
// Wait for user removal and then kill user connections and sessions
const queryCurrentUser = Users.find(selector);
if (queryCurrentUser.count() === 0) {
const countUser = await queryCurrentUser.countAsync();
if (countUser === 0) {
disconnectUser(meetingId, userId);
} else {
const queryUserObserver = queryCurrentUser.observeChanges({

View File

@ -2,7 +2,12 @@ import { check } from 'meteor/check';
import Users from '/imports/api/users';
import Logger from '/imports/startup/server/logger';
export default function setConnectionIdAndAuthToken(meetingId, userId, connectionId, authToken) {
export default async function setConnectionIdAndAuthToken(
meetingId,
userId,
connectionId,
authToken,
) {
check(meetingId, String);
check(userId, String);
check(authToken, String);
@ -21,7 +26,7 @@ export default function setConnectionIdAndAuthToken(meetingId, userId, connectio
};
try {
const numberAffected = Users.update(selector, modifier);
const numberAffected = await Users.updateAsync(selector, modifier);
if (numberAffected) {
Logger.info(`Updated connectionId and authToken user=${userId} connectionId=${connectionId} meeting=${meetingId} authToken=${authToken}`);

View File

@ -1,7 +1,7 @@
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
export default function setMobile(meetingId, userId) {
export default async function setMobile(meetingId, userId) {
const selector = {
meetingId,
userId,
@ -14,7 +14,7 @@ export default function setMobile(meetingId, userId) {
};
try {
const numberAffected = Users.update(selector, modifier);
const numberAffected = await Users.updateAsync(selector, modifier);
if (numberAffected) {
Logger.info(`Assigned mobile user id=${userId} meeting=${meetingId}`);

View File

@ -2,7 +2,11 @@ import { check } from 'meteor/check';
import Users from '/imports/api/users';
import Logger from '/imports/startup/server/logger';
export default function setUserEffectiveConnectionType(meetingId, userId, effectiveConnectionType) {
export default async function setUserEffectiveConnectionType(
meetingId,
userId,
effectiveConnectionType,
) {
check(meetingId, String);
check(userId, String);
check(effectiveConnectionType, String);
@ -20,7 +24,7 @@ export default function setUserEffectiveConnectionType(meetingId, userId, effect
};
try {
const numberAffected = Users.update(selector, modifier);
const numberAffected = await Users.updateAsync(selector, modifier);
if (numberAffected) {
Logger.info(`Updated user ${userId} effective connection to ${effectiveConnectionType} in meeting ${meetingId}`);

View File

@ -1,7 +1,7 @@
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
export default function setUserExitReason(meetingId, userId, reason) {
export default async function setUserExitReason(meetingId, userId, reason) {
const selector = {
meetingId,
userId,
@ -14,7 +14,7 @@ export default function setUserExitReason(meetingId, userId, reason) {
};
try {
const numberAffected = Users.update(selector, modifier);
const numberAffected = await Users.updateAsync(selector, modifier);
if (numberAffected) {
Logger.info(`Set exit reason userId=${userId} meeting=${meetingId}`);

View File

@ -1,7 +1,7 @@
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
export default function updateSpeechLocale(meetingId, userId, locale) {
export default async function updateSpeechLocale(meetingId, userId, locale) {
const selector = {
meetingId,
userId,
@ -14,7 +14,7 @@ export default function updateSpeechLocale(meetingId, userId, locale) {
};
try {
const numberAffected = Users.update(selector, modifier);
const numberAffected = await Users.updateAsync(selector, modifier);
if (numberAffected) {
Logger.info(`Updated speech locale=${locale} userId=${userId} meetingId=${meetingId}`);

View File

@ -2,7 +2,7 @@ import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
export default function updateUserConnectionId(meetingId, userId, connectionId) {
export default async function updateUserConnectionId(meetingId, userId, connectionId) {
check(meetingId, String);
check(userId, String);
check(connectionId, String);
@ -16,11 +16,11 @@ export default function updateUserConnectionId(meetingId, userId, connectionId)
},
};
const User = Users.findOne(selector);
const User = await Users.findOneAsync(selector);
if (User) {
try {
const updated = Users.update(selector, modifier);
const updated = await Users.updateAsync(selector, modifier);
if (updated) {
Logger.info(`Updated connection user=${userId} connectionid=${connectionId} meeting=${meetingId}`);

View File

@ -3,7 +3,7 @@ import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
import clearUserInfoForRequester from '/imports/api/users-infos/server/modifiers/clearUserInfoForRequester';
export default function userEjected(meetingId, userId, ejectedReason) {
export default async function userEjected(meetingId, userId, ejectedReason) {
check(meetingId, String);
check(userId, String);
check(ejectedReason, String);
@ -21,10 +21,10 @@ export default function userEjected(meetingId, userId, ejectedReason) {
};
try {
const numberAffected = Users.update(selector, modifier);
const numberAffected = await Users.updateAsync(selector, modifier);
if (numberAffected) {
clearUserInfoForRequester(meetingId, userId);
await clearUserInfoForRequester(meetingId, userId);
Logger.info(`Ejected user id=${userId} meeting=${meetingId} reason=${ejectedReason}`);
}
} catch (err) {

View File

@ -2,7 +2,7 @@ import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
export default function userInactivityInspect(userId, responseDelay) {
export default async function userInactivityInspect(userId, responseDelay) {
check(userId, String);
check(responseDelay, Match.Integer);
@ -19,7 +19,7 @@ export default function userInactivityInspect(userId, responseDelay) {
};
try {
const { numberAffected } = Users.update(selector, modifier);
const { numberAffected } = await Users.updateAsync(selector, modifier);
if (numberAffected) {
Logger.info(`Updated user ${userId} with inactivity inspect`);

View File

@ -1,7 +1,7 @@
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
export default function userLeftFlagUpdated(meetingId, userId, left) {
export default async function userLeftFlagUpdated(meetingId, userId, left) {
const selector = {
meetingId,
userId,
@ -14,7 +14,7 @@ export default function userLeftFlagUpdated(meetingId, userId, left) {
};
try {
const numberAffected = Users.update(selector, modifier);
const numberAffected = await Users.updateAsync(selector, modifier);
if (numberAffected) {
Logger.info(`Updated user ${userId} with left flag as ${left} in meeting ${meetingId}`);
}

View File

@ -40,8 +40,9 @@ function publishCurrentUser(...args) {
Meteor.publish('current-user', publishCurrentUser);
function users() {
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
async function users() {
const tokenValidation = await AuthTokenValidation
.findOneAsync({ connectionId: this.connection.id });
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
Logger.warn(`Publishing Users was requested by unauth connection ${this.connection.id}`);
@ -63,15 +64,16 @@ function users() {
left: false,
};
const User = Users.findOne({ userId, meetingId }, { fields: { role: 1 } });
const User = await Users.findOneAsync({ userId, meetingId }, { fields: { role: 1 } });
if (!!User && User.role === ROLE_MODERATOR) {
selector.$or.push({
'breakoutProps.isBreakoutUser': true,
'breakoutProps.parentId': meetingId,
});
// Monitor this publication and stop it when user is not a moderator anymore
const comparisonFunc = () => {
const user = Users.findOne({ userId, meetingId }, { fields: { role: 1, userId: 1 } });
const comparisonFunc = async () => {
const user = await Users.findOneAsync({ userId, meetingId },
{ fields: { role: 1, userId: 1 } });
const condition = user.role === ROLE_MODERATOR;
if (!condition) {
Logger.info(`conditions aren't filled anymore in publication ${this._name}:

View File

@ -239,8 +239,8 @@ class Auth {
description: 'Authentication timeout',
});
}, CONNECTION_TIMEOUT);
Meteor.call('validateAuthToken', this.meetingID, this.userID, this.token, this.externUserID, (err, result) => {
Meteor.callAsync('validateAuthToken', this.meetingID, this.userID, this.token, this.externUserID)
.then((result) => {
const authenticationTokenValidation = result;
if (!authenticationTokenValidation) return;