Skip to content

Commit

Permalink
Step 6.5: Add chats publication
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB authored and Dotan Simha committed Nov 23, 2016
1 parent cea52a4 commit e06fc7c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions server/publications.js
@@ -1,5 +1,31 @@
import { Meteor } from 'meteor/meteor';
import { Chats, Messages } from '../lib/collections';

Meteor.publish('users', function() {
return Meteor.users.find({}, { fields: { profile: 1 } });
});

Meteor.publishComposite('chats', function() {
if (!this.userId) return;

return {
find() {
return Chats.find({ userIds: this.userId });
},
children: [
{
find(chat) {
return Messages.find({ chatId: chat._id });
}
},
{
find(chat) {
const query = { _id: { $in: chat.userIds } };
const options = { fields: { profile: 1 } };

return Meteor.users.find(query, options);
}
}
]
};
});

0 comments on commit e06fc7c

Please sign in to comment.