I'm using the profile field in Meteor.users system defined collection to store information about the last message user read on every communication channel with the following structure:
profile : {
lastMsgRead : [
{channelId: 'YYEBNEI7894K', messageCreatedAt: '14578970667"}
{channelId: 'GERYUE789774', messageCreatedAt: '14578999845"}
]
}
I discovered that reading lastMsgRead field fails because of on the client the array in still empty at the time of read. I correctly publish this field to the client through:
Meteor.publish(null, function() {
return Meteor.users.find({}, {fields: {_id: 1, username: 1, emails: 1, profile :1}});
and I read its value from a client library located in the lib directory, in this way:
var chHistory = Meteor.user().profile.lastMsgRead;
Debugging my code it looks like the changes I make to the profile field have not been propagated to all the client at the time I read them. So I need to wait for the subscription Meteor.users gets ready, but I don't have its handle ─ you get this automatically from the framework.
How can I wait for the Meteor.users subscription gets ready?