Model#search: factor out username search.

This commit is contained in:
evazion
2019-08-19 17:58:23 -05:00
parent 9a3e9747d8
commit c3ad7f6112
26 changed files with 41 additions and 189 deletions

View File

@@ -143,22 +143,8 @@ class Dmail < ApplicationRecord
q = q.attribute_matches(:title, params[:title_matches])
q = q.attribute_matches(:body, params[:message_matches], index_column: :message_index)
if params[:to_name].present?
q = q.to_name_matches(params[:to_name])
end
if params[:to_id].present?
q = q.where("to_id = ?", params[:to_id].to_i)
end
if params[:from_name].present?
q = q.from_name_matches(params[:from_name])
end
if params[:from_id].present?
q = q.where("from_id = ?", params[:from_id].to_i)
end
q = q.search_user_attribute(:to, params)
q = q.search_user_attribute(:from, params)
params[:is_spam] = false unless params[:is_spam].present?
q = q.attribute_matches(:is_spam, params[:is_spam])