diff --git a/server/publications.ts b/server/publications.ts index c868b47..8738e81 100644 --- a/server/publications.ts +++ b/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 { if (!this.userId) { @@ -13,4 +13,16 @@ Meteor.publish('users', function(): Mongo.Cursor { profile: 1 } }); +}); + +Meteor.publish('messages', function(chatId: string): Mongo.Cursor { + if (!this.userId || !chatId) { + return; + } + + return Messages.collection.find({ + chatId + }, { + sort: { createdAt: -1 } + }); }); \ No newline at end of file