Permalink
Browse files

Step 9.12: Publish messages

  • Loading branch information...
dotansimha authored and darkbasic committed Jan 24, 2017
1 parent 5f970eb commit 8d7ef3772914747186ec1549454bc200a9589b22
Showing with 14 additions and 1 deletion.
  1. +14 −1 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) {
@@ -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 8d7ef37

Please sign in to comment.