Skip to content

Commit

Permalink
Step 7.14: Added chats publication
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Nov 28, 2016
1 parent 2fb702b commit 45ec3e9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions api/server/publications.ts
Expand Up @@ -21,4 +21,33 @@ export function initPublications() {
return Messages.collection.find({chatId});
});

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

return {
find: () => {
return Chats.collection.find({memberIds: this.userId});
},

children: [
{
find: (chat) => {
return Messages.collection.find({chatId: chat._id}, {
sort: {createdAt: -1},
limit: 1
});
}
},
{
find: (chat) => {
return Users.collection.find({
_id: {$in: chat.memberIds}
}, {
fields: {profile: 1}
});
}
}
]
};
});
}

0 comments on commit 45ec3e9

Please sign in to comment.