diff --git a/api/server/publications.ts b/api/server/publications.ts index b9be1aece..11d1db4e0 100644 --- a/api/server/publications.ts +++ b/api/server/publications.ts @@ -3,16 +3,29 @@ import { Users } from './collections/users'; import { Messages } from './collections/messages'; import { Chats } from './collections/chats'; -Meteor.publish('users', function(): Mongo.Cursor { +Meteor.publishComposite('users', function( + pattern: string +): PublishCompositeConfig { if (!this.userId) { return; } - return Users.collection.find({}, { - fields: { - profile: 1 + let selector = {}; + + if (pattern) { + selector = { + 'profile.name': { $regex: pattern, $options: 'i' } + }; + } + + return { + find: () => { + return Users.collection.find(selector, { + fields: { profile: 1 }, + limit: 15 + }); } - }); + }; }); Meteor.publish('messages', function(