Inside my Meteor + React app when a person accepts an invitation I am showing a notification to the admin throwing the party.
Code for notification container
let NotificationsContainer = React.createClass({
mixins: [ReactMeteorData],
getMeteorData() {
let handle = Meteor.subscribe('ReadNotifications');
let data = {notifications: []};
if (handle.ready()) {
data.notifications = Notifications.find({for: Meteor.userId()},
{sort: {createdAt: -1},limit: 10}).fetch()
.map((notification) => { return notification;});
data.users = Meteor.users.find().fetch();
}
return data;
},
render() {
<NotificationList
notifications={this.data.notifications}
users={this.data.users}
ref={(ref) => this._notificationList = ref}
/>
}
})
Notification List will display all the notifications.
Publication code is
publication() {
let notifications = Notifications.find({ for: this.userId }, { sort: {createdAt: -1}, limit: limit });
let notificationsFrom = notifications.map((item) => item.from);
let users = Meteor.users.find({_id: {$in: notificationsFrom}}, {fields: {profile: 1, emails: 1, username: 1}});
return [notifications, users];
},
Problem is when a user accepts party invitation, data.notifications in notification container gets new notification from notification containers but data.users does not get new user who accepted party invitation and data associated with it on notification list show undefined where name should be of that person
Once I refresh that page, meteor.subscription will fire and get then everything working is fine.
So what should be the solution in this case so that we get info of user without page refresh