add ability to search own posts by prepending `me:` to searches

staging
multiple creatures 2019-08-15 11:09:36 -05:00
parent 5ae918d968
commit bbb025be69
1 changed files with 7 additions and 1 deletions

View File

@ -339,9 +339,15 @@ class Status < ApplicationRecord
class << self
def search_for(term, limit = 33, account = nil)
return none if account.nil?
if term.start_with?('me:')
term = term.split(nil, 2)[1]
scope = account.statuses
else
scope = Status
end
pattern = sanitize_sql_like(term)
pattern = "#{pattern}"
scope = Status.without_reblogs.where("tsv @@ plainto_tsquery('english', ?)", pattern)
scope = scope.without_reblogs.where("tsv @@ plainto_tsquery('english', ?)", pattern)
query = scope.where(account: account)
.or(scope.where(account: account.following, visibility: [:private, :local, :unlisted]))
.or(scope.where(id: account.mentions.select(:status_id)))