Skip to content

Commit

Permalink
Search for by:me and emoji:@me
Browse files Browse the repository at this point in the history
  • Loading branch information
edemaine committed Jan 24, 2021
1 parent 27c2f94 commit 0c28a69
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ support, but it has proved useful in other fields too.
spaces act as an AND query.
* Connect words/phrases with `|` to get an OR query instead.
* `by:username` searches for messages coauthored by a specified username
(which can include `*`s or use regular expressions via `regex:`)
(which can include `*`s or use regular expressions via `regex:`);
`by:me` is shorthand for searching for your own username.
* `tag:...` does an exact match for a specified tag; it can be negated.
* `emoji:heart`, `emoji:thumbs-up`, `emoji:thumbs*`, `emoji:*` etc. search
for messages with (certain) emoji symbol responses;
`emoji:@username` searches for messages with emoji response by
a specific user, defaulting to yourself
(`emoji:@` finds your own emoji responses);
a specific user (`emoji:@me` finds your own emoji responses);
or you can combine the two with e.g. `emoji:thumbs*@username`.
* `is:root` matches root messages (tops of threads).
* `is:file` matches file messages (made via Attach).
Expand Down
15 changes: 10 additions & 5 deletions lib/search.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ unescapeRegExp = (regex) ->
wants.push "tags.#{escapeTag token}": $exists: not negate
when 'emoji:'
if 0 <= atIndex = token.indexOf '@'
username = regexForWord token[atIndex+1..]
unless username? # default username is self
username = token[atIndex+1..]
if username == 'me'
username = Meteor.user()?.username
else
username = regexForWord username
token = token[...atIndex]
else
username = undefined
Expand Down Expand Up @@ -148,8 +150,11 @@ unescapeRegExp = (regex) ->
else
console.warn "No emoji match query #{regex}" if Meteor.isClient
when 'by:'
token = token[1..] if token.startsWith '@'
regex = regexForWord token
if token == 'me'
regex = Meteor.user()?.username
else
token = token[1..] if token.startsWith '@'
regex = regexForWord token
continue unless regex?
if negate
wants.push coauthors: $not: regex
Expand Down Expand Up @@ -384,7 +389,7 @@ formatParsedSearch = (query, group) ->

formatUserSearch = (value) ->
formatParsedSearch value
.replace /^“(.*)” whole-word$/, '$1' # simplify normal usernames
.replace /^“(.*)”( whole-word)?$/, '$1' # simplify normal usernames

emojiLike = /^(no )?([\-\w]+) emoji(.*)$/
checkAllEmoji = (parts, group) ->
Expand Down
4 changes: 3 additions & 1 deletion lib/users.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ import React from 'react'
display

@validUsername = (username) ->
validKey(username) and not username.match /[\s@]/
validKey(username) and
not username.match(/[\s@]/) and # bad characters for at-mentions
username.toLowerCase() != 'me' # used in search as shorthand for self

## Need to escape dots in usernames.
@escapeUser = escapeKey
Expand Down

0 comments on commit 0c28a69

Please sign in to comment.