Create custom cursor for current poll and user
This commit is contained in:
parent
6f9e6b5efc
commit
0a00588651
@ -1,6 +1,7 @@
|
|||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
|
|
||||||
const Polls = new Mongo.Collection('polls');
|
const Polls = new Mongo.Collection('polls');
|
||||||
|
export const CurrentPoll = new Mongo.Collection('current-poll');
|
||||||
|
|
||||||
if (Meteor.isServer) {
|
if (Meteor.isServer) {
|
||||||
// We can have just one active poll per meeting
|
// We can have just one active poll per meeting
|
||||||
|
@ -14,11 +14,11 @@ function currentPoll(secretPoll) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!tokenValidation ||
|
!tokenValidation
|
||||||
tokenValidation.validationStatus !== ValidationStates.VALIDATED
|
|| tokenValidation.validationStatus !== ValidationStates.VALIDATED
|
||||||
) {
|
) {
|
||||||
Logger.warn(
|
Logger.warn(
|
||||||
`Publishing Polls was requested by unauth connection ${this.connection.id}`
|
`Publishing Polls was requested by unauth connection ${this.connection.id}`,
|
||||||
);
|
);
|
||||||
return Polls.find({ meetingId: '' });
|
return Polls.find({ meetingId: '' });
|
||||||
}
|
}
|
||||||
@ -41,15 +41,16 @@ function currentPoll(secretPoll) {
|
|||||||
if ((hasPoll && hasPoll.secretPoll) || secretPoll) {
|
if ((hasPoll && hasPoll.secretPoll) || secretPoll) {
|
||||||
options.fields.responses = 0;
|
options.fields.responses = 0;
|
||||||
}
|
}
|
||||||
|
Mongo.Collection._publishCursor(Polls.find(selector, options), this, 'current-poll');
|
||||||
return Polls.find(selector, options);
|
return this.ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.warn(
|
Logger.warn(
|
||||||
'Publishing current-poll was requested by non-moderator connection',
|
'Publishing current-poll was requested by non-moderator connection',
|
||||||
{ meetingId, userId, connectionId: this.connection.id },
|
{ meetingId, userId, connectionId: this.connection.id },
|
||||||
);
|
);
|
||||||
return Polls.find({ meetingId: '' });
|
Mongo.Collection._publishCursor(Polls.find({ meetingId: '' }), this, 'current-poll');
|
||||||
|
return this.ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
function publishCurrentPoll(...args) {
|
function publishCurrentPoll(...args) {
|
||||||
@ -65,11 +66,11 @@ function polls() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!tokenValidation ||
|
!tokenValidation
|
||||||
tokenValidation.validationStatus !== ValidationStates.VALIDATED
|
|| tokenValidation.validationStatus !== ValidationStates.VALIDATED
|
||||||
) {
|
) {
|
||||||
Logger.warn(
|
Logger.warn(
|
||||||
`Publishing Polls was requested by unauth connection ${this.connection.id}`
|
`Publishing Polls was requested by unauth connection ${this.connection.id}`,
|
||||||
);
|
);
|
||||||
return Polls.find({ meetingId: '' });
|
return Polls.find({ meetingId: '' });
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
|
|
||||||
const Users = new Mongo.Collection('users');
|
const Users = new Mongo.Collection('users');
|
||||||
|
export const CurrentUser = new Mongo.Collection('current-user');
|
||||||
|
|
||||||
if (Meteor.isServer) {
|
if (Meteor.isServer) {
|
||||||
// types of queries for the users:
|
// types of queries for the users:
|
||||||
|
@ -9,7 +9,8 @@ const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
|||||||
|
|
||||||
function currentUser() {
|
function currentUser() {
|
||||||
if (!this.userId) {
|
if (!this.userId) {
|
||||||
return Users.find({ meetingId: '' });
|
Mongo.Collection._publishCursor(Users.find({ meetingId: '' }), this, 'current-user');
|
||||||
|
return this.ready();
|
||||||
}
|
}
|
||||||
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
||||||
|
|
||||||
@ -28,8 +29,8 @@ function currentUser() {
|
|||||||
authToken: false, // Not asking for authToken from client side but also not exposing it
|
authToken: false, // Not asking for authToken from client side but also not exposing it
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Mongo.Collection._publishCursor(Users.find(selector, options), this, 'current-user');
|
||||||
return Users.find(selector, options);
|
return this.ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
function publishCurrentUser(...args) {
|
function publishCurrentUser(...args) {
|
||||||
@ -39,7 +40,7 @@ function publishCurrentUser(...args) {
|
|||||||
|
|
||||||
Meteor.publish('current-user', publishCurrentUser);
|
Meteor.publish('current-user', publishCurrentUser);
|
||||||
|
|
||||||
function users(role) {
|
function users() {
|
||||||
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
|
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
|
||||||
|
|
||||||
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
|
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useContext, useEffect } from 'react';
|
import { useContext, useEffect } from 'react';
|
||||||
import Users from '/imports/api/users';
|
import Users, { CurrentUser } from '/imports/api/users';
|
||||||
import UsersPersistentData from '/imports/api/users-persistent-data';
|
import UsersPersistentData from '/imports/api/users-persistent-data';
|
||||||
import { UsersContext, ACTIONS } from './context';
|
import { UsersContext, ACTIONS } from './context';
|
||||||
import ChatLogger from '/imports/ui/components/chat/chat-logger/ChatLogger';
|
import ChatLogger from '/imports/ui/components/chat/chat-logger/ChatLogger';
|
||||||
@ -8,11 +8,11 @@ const Adapter = () => {
|
|||||||
const usingUsersContext = useContext(UsersContext);
|
const usingUsersContext = useContext(UsersContext);
|
||||||
const { dispatch } = usingUsersContext;
|
const { dispatch } = usingUsersContext;
|
||||||
|
|
||||||
useEffect(()=> {
|
useEffect(() => {
|
||||||
const usersPersistentDataCursor = UsersPersistentData.find({}, { sort: { timestamp: 1 } });
|
const usersPersistentDataCursor = UsersPersistentData.find({}, { sort: { timestamp: 1 } });
|
||||||
usersPersistentDataCursor.observe({
|
usersPersistentDataCursor.observe({
|
||||||
added: (obj) => {
|
added: (obj) => {
|
||||||
ChatLogger.debug("usersAdapter::observe::added_persistent_user", obj);
|
ChatLogger.debug('usersAdapter::observe::added_persistent_user', obj);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.ADDED_USER_PERSISTENT_DATA,
|
type: ACTIONS.ADDED_USER_PERSISTENT_DATA,
|
||||||
value: {
|
value: {
|
||||||
@ -21,7 +21,7 @@ const Adapter = () => {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
changed: (obj) => {
|
changed: (obj) => {
|
||||||
ChatLogger.debug("usersAdapter::observe::changed_persistent_user", obj);
|
ChatLogger.debug('usersAdapter::observe::changed_persistent_user', obj);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.CHANGED_USER_PERSISTENT_DATA,
|
type: ACTIONS.CHANGED_USER_PERSISTENT_DATA,
|
||||||
value: {
|
value: {
|
||||||
@ -29,15 +29,16 @@ const Adapter = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
removed: (obj) => {},
|
removed: () => {},
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const usersCursor = Users.find({}, { sort: { timestamp: 1 } });
|
const usersCursor = Users.find({}, { sort: { timestamp: 1 } });
|
||||||
|
const CurrentUserCursor = CurrentUser.find({});
|
||||||
usersCursor.observe({
|
usersCursor.observe({
|
||||||
added: (obj) => {
|
added: (obj) => {
|
||||||
ChatLogger.debug("usersAdapter::observe::added", obj);
|
ChatLogger.debug('usersAdapter::observe::added', obj);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.ADDED,
|
type: ACTIONS.ADDED,
|
||||||
value: {
|
value: {
|
||||||
@ -54,6 +55,18 @@ const Adapter = () => {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CurrentUserCursor.observe({
|
||||||
|
added: (obj) => {
|
||||||
|
ChatLogger.debug('usersAdapter::observe::current-user::added', obj);
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.ADDED,
|
||||||
|
value: {
|
||||||
|
user: obj,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -7,7 +7,7 @@ import { setCustomLogoUrl, setModeratorOnlyMessage } from '/imports/ui/component
|
|||||||
import { makeCall } from '/imports/ui/services/api';
|
import { makeCall } from '/imports/ui/services/api';
|
||||||
import logger from '/imports/startup/client/logger';
|
import logger from '/imports/startup/client/logger';
|
||||||
import LoadingScreen from '/imports/ui/components/loading-screen/component';
|
import LoadingScreen from '/imports/ui/components/loading-screen/component';
|
||||||
import Users from '/imports/api/users';
|
import { CurrentUser } from '/imports/api/users';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
children: PropTypes.element.isRequired,
|
children: PropTypes.element.isRequired,
|
||||||
@ -162,7 +162,7 @@ class JoinHandler extends Component {
|
|||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (customdata.length) {
|
if (customdata.length) {
|
||||||
makeCall('addUserSettings', customdata).then(r => resolve(r));
|
makeCall('addUserSettings', customdata).then((r) => resolve(r));
|
||||||
}
|
}
|
||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
@ -190,8 +190,8 @@ class JoinHandler extends Component {
|
|||||||
setModOnlyMessage(response);
|
setModOnlyMessage(response);
|
||||||
|
|
||||||
Tracker.autorun(async (cd) => {
|
Tracker.autorun(async (cd) => {
|
||||||
const user = Users.findOne({ userId: Auth.userID, approved: true }, { fields: { _id: 1 } });
|
const user = CurrentUser
|
||||||
|
.findOne({ userId: Auth.userID, approved: true }, { fields: { _id: 1 } });
|
||||||
if (user) {
|
if (user) {
|
||||||
await setCustomData(response);
|
await setCustomData(response);
|
||||||
cd.stop();
|
cd.stop();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import Users from '/imports/api/users';
|
import Users from '/imports/api/users';
|
||||||
import Auth from '/imports/ui/services/auth';
|
import Auth from '/imports/ui/services/auth';
|
||||||
import Polls from '/imports/api/polls';
|
import { CurrentPoll } from '/imports/api/polls';
|
||||||
import caseInsensitiveReducer from '/imports/utils/caseInsensitiveReducer';
|
import caseInsensitiveReducer from '/imports/utils/caseInsensitiveReducer';
|
||||||
import { defineMessages } from 'react-intl';
|
import { defineMessages } from 'react-intl';
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ export default {
|
|||||||
{ fields: { presenter: 1 } },
|
{ fields: { presenter: 1 } },
|
||||||
).presenter,
|
).presenter,
|
||||||
pollTypes,
|
pollTypes,
|
||||||
currentPoll: () => Polls.findOne({ meetingId: Auth.meetingID }),
|
currentPoll: () => CurrentPoll.findOne({ meetingId: Auth.meetingID }),
|
||||||
pollAnswerIds,
|
pollAnswerIds,
|
||||||
POLL_AVATAR_COLOR,
|
POLL_AVATAR_COLOR,
|
||||||
isDefaultPoll,
|
isDefaultPoll,
|
||||||
|
Loading…
Reference in New Issue
Block a user