Skip to content

Commit

Permalink
Step 9.12: Add messages publication
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB committed Feb 13, 2017
1 parent a2d9ad1 commit c48f660
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions server/publications.ts
@@ -1,7 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { Users } from '../imports/collections';
import { User } from '../imports/models';
import { Messages, Users } from '../imports/collections';
import { Message, User } from '../imports/models';

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

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 c48f660

Please sign in to comment.