Skip to content

Commit

Permalink
Step 9.12: Publish messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Mar 23, 2017
1 parent a35e91c commit 0eac43f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion api/server/publications.ts
@@ -1,5 +1,6 @@
import { User } from './models';
import { User, Message } from './models';
import { Users } from './collections/users';
import { Messages } from './collections/messages';

Meteor.publish('users', function(): Mongo.Cursor<User> {
if (!this.userId) {
Expand All @@ -12,3 +13,15 @@ Meteor.publish('users', function(): Mongo.Cursor<User> {
}
});
});

Meteor.publish('messages', function(chatId: string): Mongo.Cursor<Message> {
if (!this.userId || !chatId) {
return;
}

return Messages.collection.find({
chatId
}, {
sort: { createdAt: -1 }
});
});

0 comments on commit 0eac43f

Please sign in to comment.