Skip to content

Commit 8d7ef37

Browse files
dotansimhadarkbasic
authored andcommitted
Step 9.12: Publish messages
1 parent 5f970eb commit 8d7ef37

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

api/server/publications.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { User } from './models';
1+
import { User, Message } from './models';
22
import { Users } from './collections/users';
3+
import { Messages } from './collections/messages';
34

45
Meteor.publish('users', function(): Mongo.Cursor<User> {
56
if (!this.userId) {
@@ -12,3 +13,15 @@ Meteor.publish('users', function(): Mongo.Cursor<User> {
1213
}
1314
});
1415
});
16+
17+
Meteor.publish('messages', function(chatId: string): Mongo.Cursor<Message> {
18+
if (!this.userId || !chatId) {
19+
return;
20+
}
21+
22+
return Messages.collection.find({
23+
chatId
24+
}, {
25+
sort: { createdAt: -1 }
26+
});
27+
});

0 commit comments

Comments
 (0)