Permalink
Browse files

Step 9.12: Publish messages

  • Loading branch information...
dotansimha authored and darkbasic committed Jan 24, 2017
1 parent 2934dac commit a7ceaa0ae04e0d973170222cbbe9cb4d9c21bc49
Showing with 14 additions and 1 deletion.
  1. +14 −1 api/server/publications.ts
View
@@ -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 a7ceaa0

Please sign in to comment.