mirror of
https://github.com/kikobar/mastodon.git
synced 2024-12-28 16:54:18 +00:00
Add from:me
syntax to search (#26660)
This commit is contained in:
parent
9d9de8d219
commit
67166de865
|
@ -85,8 +85,9 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
class PrefixClause
|
class PrefixClause
|
||||||
attr_reader :type, :filter, :operator, :term
|
attr_reader :type, :filter, :operator, :term
|
||||||
|
|
||||||
def initialize(prefix, operator, term)
|
def initialize(prefix, operator, term, options = {})
|
||||||
@negated = operator == '-'
|
@negated = operator == '-'
|
||||||
|
@options = options
|
||||||
@operator = :filter
|
@operator = :filter
|
||||||
|
|
||||||
case prefix
|
case prefix
|
||||||
|
@ -105,15 +106,15 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
when 'before'
|
when 'before'
|
||||||
@filter = :created_at
|
@filter = :created_at
|
||||||
@type = :range
|
@type = :range
|
||||||
@term = { lt: term }
|
@term = { lt: term, time_zone: @options[:current_account]&.user_time_zone || 'UTC' }
|
||||||
when 'after'
|
when 'after'
|
||||||
@filter = :created_at
|
@filter = :created_at
|
||||||
@type = :range
|
@type = :range
|
||||||
@term = { gt: term }
|
@term = { gt: term, time_zone: @options[:current_account]&.user_time_zone || 'UTC' }
|
||||||
when 'during'
|
when 'during'
|
||||||
@filter = :created_at
|
@filter = :created_at
|
||||||
@type = :range
|
@type = :range
|
||||||
@term = { gte: term, lte: term }
|
@term = { gte: term, lte: term, time_zone: @options[:current_account]&.user_time_zone || 'UTC' }
|
||||||
else
|
else
|
||||||
raise Mastodon::SyntaxError
|
raise Mastodon::SyntaxError
|
||||||
end
|
end
|
||||||
|
@ -126,6 +127,8 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
private
|
private
|
||||||
|
|
||||||
def account_id_from_term(term)
|
def account_id_from_term(term)
|
||||||
|
return @options[:current_account]&.id || -1 if term == 'me'
|
||||||
|
|
||||||
username, domain = term.gsub(/\A@/, '').split('@')
|
username, domain = term.gsub(/\A@/, '').split('@')
|
||||||
domain = nil if TagManager.instance.local_domain?(domain)
|
domain = nil if TagManager.instance.local_domain?(domain)
|
||||||
account = Account.find_remote(username, domain)
|
account = Account.find_remote(username, domain)
|
||||||
|
@ -141,7 +144,7 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
operator = clause[:operator]&.to_s
|
operator = clause[:operator]&.to_s
|
||||||
|
|
||||||
if clause[:prefix]
|
if clause[:prefix]
|
||||||
PrefixClause.new(prefix, operator, clause[:term].to_s)
|
PrefixClause.new(prefix, operator, clause[:term].to_s, current_account: current_account)
|
||||||
elsif clause[:term]
|
elsif clause[:term]
|
||||||
TermClause.new(prefix, operator, clause[:term].to_s)
|
TermClause.new(prefix, operator, clause[:term].to_s)
|
||||||
elsif clause[:shortcode]
|
elsif clause[:shortcode]
|
||||||
|
|
|
@ -59,6 +59,6 @@ class StatusesSearchService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def parsed_query
|
def parsed_query
|
||||||
SearchQueryTransformer.new.apply(SearchQueryParser.new.parse(@query))
|
SearchQueryTransformer.new.apply(SearchQueryParser.new.parse(@query), current_account: @account)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue