Merge pull request #13802 from Tainan404/remove-parameters-from-publishers

Removes parameters usage in the group-chat-messages and authtoken-validation publishers
This commit is contained in:
Anton Georgiev 2021-12-01 15:29:12 -05:00 committed by GitHub
commit bdd31b4dbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 10 deletions

View File

@ -1,11 +1,33 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import _ from 'lodash';
import AuthTokenValidation from '/imports/api/auth-token-validation';
import { extractCredentials } from '/imports/api/common/server/helpers';
import Logger from '/imports/startup/server/logger';
function authTokenValidation({ meetingId, userId }) {
async function authTokenValidation({ meetingId, userId }) {
check(meetingId, String);
check(userId, String);
const credentials = await new Promise((resp)=> {
const tempSettimeout = () => {
setTimeout(() => {
const cred = extractCredentials(this.userId);
const objIsEmpty = _.isEmpty(cred);
if (objIsEmpty) {
return tempSettimeout();
}
return resp(cred);
}, 200);
};
tempSettimeout();
});
const { meetingId: mId, requesterUserId } = credentials;
const selector = {
meetingId,
userId,
meetingId: mId,
userId: requesterUserId,
};
Logger.debug(`Publishing auth-token-validation for ${meetingId} ${userId}`);

View File

@ -1,11 +1,13 @@
import { GroupChatMsg, UsersTyping } from '/imports/api/group-chat-msg';
import Users from '/imports/api/users';
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import GroupChat from '/imports/api/group-chat';
import Logger from '/imports/startup/server/logger';
import AuthTokenValidation, { ValidationStates } from '/imports/api/auth-token-validation';
function groupChatMsg(chatsIds) {
function groupChatMsg(chatCount) {
check(chatCount, Number);
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
@ -20,6 +22,14 @@ function groupChatMsg(chatsIds) {
Logger.debug('Publishing group-chat-msg', { meetingId, userId });
const chats = GroupChat.find({
$or: [
{ meetingId, users: { $all: [userId] } },
],
}).fetch();
const chatsIds = chats.map((ct) => ct.chatId);
const User = Users.findOne({ userId, meetingId });
const selector = {
timestamp: { $gte: User.authTokenValidatedTime },

View File

@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
import Polls from '/imports/api/polls';
@ -12,6 +13,7 @@ Meteor.server.setPublicationStrategy('polls', DDPServer.publicationStrategies.NO
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
function currentPoll(secretPoll) {
check(secretPoll, Boolean);
const tokenValidation = AuthTokenValidation.findOne({
connectionId: this.connection.id,
});

View File

@ -104,7 +104,7 @@ export default withTracker(() => {
let groupChatMessageHandler = {};
if (CHAT_ENABLED && ready) {
const chats = GroupChat.find({
const chatsCount = GroupChat.find({
$or: [
{
meetingId,
@ -113,15 +113,13 @@ export default withTracker(() => {
},
{ meetingId, users: { $all: [requesterUserId] } },
],
}).fetch();
const chatIds = chats.map(chat => chat.chatId);
}).count();
const subHandler = {
...subscriptionErrorHandler,
};
groupChatMessageHandler = Meteor.subscribe('group-chat-msg', chatIds, subHandler);
groupChatMessageHandler = Meteor.subscribe('group-chat-msg', chatsCount, subHandler);
}
// TODO: Refactor all the late subscribers