Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved user search (name and username) #3322

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Template.permissionsRole.helpers
filter:
exceptions: Template.instance().usersInRole.get()?.fetch()
selector: (match) ->
return { username: match }
return { term: match }
sort: 'username'
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Template.mailMessagesInstructions.helpers
filter:
exceptions: Template.instance().selectedUsers.get()
selector: (match) ->
return { username: match }
return { term: match }
sort: 'username'
}
]
Expand Down
19 changes: 15 additions & 4 deletions packages/rocketchat-lib/server/models/Users.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,24 @@ RocketChat.models.Users = new class extends RocketChat.models._Base

return @find query, options

findActiveByUsernameRegexWithExceptions: (username, exceptions = [], options = {}) ->
findActiveByUsernameOrNameRegexWithExceptions: (searchTerm, exceptions = [], options = {}) ->
if not _.isArray exceptions
exceptions = [ exceptions ]

usernameRegex = new RegExp username, "i"
termRegex = new RegExp searchTerm, "i"
query =
$and: [
{ active: true }
{ username: { $nin: exceptions } }
{ username: usernameRegex }
{'$or': [
{'$and': [
{ username: { $nin: exceptions } }
{ username: termRegex }
]}
{'$and': [
{ name: { $nin: exceptions } }
{ name: termRegex }
]}
]}
]
type:
$in: ['user', 'bot']
Expand Down Expand Up @@ -150,6 +158,9 @@ RocketChat.models.Users = new class extends RocketChat.models._Base

return @find(query, options)?.fetch?()?[0]?.lastLogin

getDisplayName: (_id) ->
return "display name"

findUsersByUsernames: (usernames, options) ->
query =
username:
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-livechat/app/client/views/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{/if}}
</span>
<div class="body" dir="auto">
{{{body}}}
{{{body}}} dasds
</div>
</li>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ Template.membersList.helpers
noMatchTemplate: Template.userSearchEmpty
matchAll: true
filter:
exceptions: [Meteor.user().username]
exceptions: [Meteor.user().username, Meteor.user().name]
selector: (match) ->
return { username: match }
return { term: match }
sort: 'username'
}
]
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-ui-message/message/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{#if avatarFromUsername}}
<button class="thumb user-card-message" data-username="{{u.username}}" tabindex="1">{{> avatar username=avatarFromUsername}}</button>
{{else}}
<button class="thumb user-card-message" data-username="{{u.username}}" tabindex="1">
<button class="thumb user-card-message" data-username="{{u.username}} {{u.name}}" tabindex="1">
<div class="avatar">
<div class="avatar-image" style="background-image:url({{avatar}});"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Template.createChannelFlex.helpers
filter:
exceptions: [Meteor.user().username].concat(Template.instance().selectedUsers.get())
selector: (match) ->
return { username: match }
return { term: match }
sort: 'username'
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Template.directMessagesFlex.helpers
noMatchTemplate: Template.userSearchEmpty
matchAll: true
filter:
exceptions: [Meteor.user().username]
exceptions: [Meteor.user().username, Meteor.user().name]
selector: (match) ->
return { username: match }
return { term: match }
sort: 'username'
}
},
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Template.privateGroupsFlex.helpers
filter:
exceptions: [Meteor.user().username].concat(Template.instance().selectedUsers.get())
selector: (match) ->
return { username: match }
return { term: match }
sort: 'username'
}
]
Expand Down
2 changes: 1 addition & 1 deletion server/publications/userAutocomplete.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Meteor.publish 'userAutocomplete', (selector) ->

exceptions = selector.exceptions or []

cursorHandle = RocketChat.models.Users.findActiveByUsernameRegexWithExceptions(selector.username, exceptions, options).observeChanges
cursorHandle = RocketChat.models.Users.findActiveByUsernameOrNameRegexWithExceptions(selector.term, exceptions, options).observeChanges
added: (_id, record) ->
pub.added("autocompleteRecords", _id, record)
changed: (_id, record) ->
Expand Down