Hi!
I have a collection of sessions where people can be added. So I publish to the users of one session the list of the others users that shared the same session.
Meteor.publish("users.all", function () {
const userID = this.userId;
const userSessions = Sessions.find({
"subscribers.userID": userID
});
let usersToSubscribe = [];
userSessions.forEach( function(oneSession){
usersToSubscribe = usersToSubscribe.concat( _.pluck(oneSession.subscribers, 'userID') );
});
const allUsers = Meteor.users.find({
"_id": { $in: usersToSubscribe }
}, {
fields: Users.publicFields,
});
if(allUsers){
return allUsers;
}
return this.ready();
});
And I subscribe on the router
Router.route('/session/:_ID/share', {
name: 'session.share',
template: 'share',
waitOn: function () {
return [
this.subscribe( 'sessions.all' ),
this.subscribe( 'sessionDates.currents' ),
this.subscribe( 'roles.all' ),
this.subscribe( 'users.all' )
]
},
data: function () {
if (this.ready()) {
...
}
}
});
But when a user is added to the session, the subscription is not refreshed. What is the problem?
Thanks for your help!!