The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/publications/userAutocomplete.js

54 lines
1.2 KiB

import { Meteor } from 'meteor/meteor';
import _ from 'underscore';
import { hasPermission } from '../../app/authorization/server';
import { Users } from '../../app/models/server';
Meteor.publish('userAutocomplete', function(selector) {
const uid = this.userId;
if (!uid) {
return this.ready();
}
if (!_.isObject(selector)) {
return this.ready();
}
if (!hasPermission(uid, 'view-outside-room')) {
return this.ready();
}
const options = {
fields: {
name: 1,
username: 1,
status: 1,
},
sort: {
username: 1,
},
limit: 10,
};
const pub = this;
const exceptions = selector.exceptions || [];
const conditions = selector.conditions || {};
const cursorHandle = Users.findActiveByUsernameOrNameRegexWithExceptionsAndConditions(selector.term, exceptions, conditions, options).observeChanges({
added(_id, record) {
return pub.added('autocompleteRecords', _id, record);
},
changed(_id, record) {
return pub.changed('autocompleteRecords', _id, record);
},
removed(_id, record) {
return pub.removed('autocompleteRecords', _id, record);
},
});
this.ready();
this.onStop(function() {
return cursorHandle.stop();
});
});