Skip to content
Permalink
Browse files

Step 7.15: Added chats publication

  • Loading branch information...
dotansimha authored and DAB0mB committed Nov 3, 2016
1 parent efc5ab7 commit 7ea8c5b5e0b26e120901816b68cc391c2f74e49e
Showing with 29 additions and 0 deletions.
  1. +29 −0 api/server/publications.ts
@@ -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 7ea8c5b

Please sign in to comment.
You can’t perform that action at this time.