Skip to content
Snippets Groups Projects
Unverified Commit 412598eb authored by Gabriel Engel's avatar Gabriel Engel
Browse files

code formatting to show that userAutocomplete and filteredUsers are identical

parent ca63d979
No related branches found
No related tags found
No related merge requests found
......@@ -79,7 +79,7 @@ RocketChat.models.Users = new class extends RocketChat.models._Base
if not _.isArray exceptions
exceptions = [ exceptions ]
termRegex = new RegExp s.escapeRegExp(searchTerm), "i"
termRegex = new RegExp s.escapeRegExp(searchTerm), 'i'
query =
$and: [
{ active: true }
......@@ -99,12 +99,16 @@ RocketChat.models.Users = new class extends RocketChat.models._Base
return @find query, options
findByActiveUsersUsernameExcept: (username, except, options) ->
findByActiveUsersUsernameExcept: (searchTerm, exceptions = [], options = {}) ->
if not _.isArray exceptions
exceptions = [ exceptions ]
termRegex = new RegExp s.escapeRegExp(searchTerm), 'i'
query =
active: true
$and: [
{username: {$nin: except}}
{username: username}
{ username: { $nin: exceptions } }
{ username: termRegex }
]
return @find query, options
......
Meteor.publish 'filteredUsers', (filter) ->
Meteor.publish 'filteredUsers', (selector) ->
unless this.userId
return this.ready()
if not _.isObject filter
if not _.isObject selector
return this.ready()
exp = new RegExp(s.escapeRegExp(filter.name), 'i')
options =
fields:
name: 1
username: 1
sort:
username: 1
limit: 5
pub = this
cursorHandle = RocketChat.models.Users.findByActiveUsersUsernameExcept(exp, filter.except, options).observeChanges
exceptions = selector.except or []
cursorHandle = RocketChat.models.Users.findByActiveUsersUsernameExcept(selector.name, exceptions, options).observeChanges
added: (_id, record) ->
pub.added('filtered-users', _id, record)
......
......@@ -2,26 +2,32 @@ Meteor.publish 'userAutocomplete', (selector) ->
unless this.userId
return this.ready()
pub = this
if not _.isObject selector
return this.ready()
options =
fields:
name: 1
username: 1
status: 1
limit: 10
sort:
name: 1
username: 1
limit: 10
pub = this
exceptions = selector.exceptions or []
cursorHandle = RocketChat.models.Users.findActiveByUsernameOrNameRegexWithExceptions(selector.term, exceptions, options).observeChanges
added: (_id, record) ->
pub.added("autocompleteRecords", _id, record)
changed: (_id, record) ->
pub.changed("autocompleteRecords", _id, record)
removed: (_id, record) ->
pub.removed("autocompleteRecords", _id, record)
@ready()
@onStop ->
cursorHandle.stop()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment