Kill trailing whitespace in ruby files
This commit is contained in:
@@ -11,7 +11,7 @@ class Dmail < ActiveRecord::Base
|
||||
after_create :update_recipient
|
||||
after_create :send_dmail
|
||||
attr_accessible :title, :body, :is_deleted, :to_id, :to, :to_name
|
||||
|
||||
|
||||
module AddressMethods
|
||||
def to_name
|
||||
User.id_to_pretty_name(to_id)
|
||||
@@ -26,19 +26,19 @@ class Dmail < ActiveRecord::Base
|
||||
return if user.nil?
|
||||
self.to_id = user.id
|
||||
end
|
||||
|
||||
|
||||
def initialize_from_id
|
||||
self.from_id = CurrentUser.id
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module FactoryMethods
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
|
||||
module ClassMethods
|
||||
def create_split(params)
|
||||
copy = nil
|
||||
|
||||
|
||||
Dmail.transaction do
|
||||
copy = Dmail.new(params)
|
||||
copy.owner_id = copy.to_id
|
||||
@@ -51,17 +51,17 @@ class Dmail < ActiveRecord::Base
|
||||
copy.is_read = true
|
||||
copy.save
|
||||
end
|
||||
|
||||
|
||||
copy
|
||||
end
|
||||
|
||||
|
||||
def new_blank
|
||||
Dmail.new do |dmail|
|
||||
dmail.from_id = CurrentUser.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def build_response(options = {})
|
||||
Dmail.new do |dmail|
|
||||
if title =~ /Re:/
|
||||
@@ -76,84 +76,84 @@ class Dmail < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module SearchMethods
|
||||
def for(user)
|
||||
where("owner_id = ?", user)
|
||||
end
|
||||
|
||||
|
||||
def inbox
|
||||
where("to_id = owner_id")
|
||||
end
|
||||
|
||||
|
||||
def sent
|
||||
where("from_id = owner_id")
|
||||
end
|
||||
|
||||
|
||||
def active
|
||||
where("is_deleted = ?", false)
|
||||
end
|
||||
|
||||
|
||||
def deleted
|
||||
where("is_deleted = ?", true)
|
||||
end
|
||||
|
||||
|
||||
def search_message(query)
|
||||
where("message_index @@ plainto_tsquery(?)", query.to_escaped_for_tsquery_split)
|
||||
end
|
||||
|
||||
|
||||
def unread
|
||||
where("is_read = false and is_deleted = false")
|
||||
end
|
||||
|
||||
|
||||
def visible
|
||||
where("owner_id = ?", CurrentUser.id)
|
||||
end
|
||||
|
||||
|
||||
def to_name_matches(name)
|
||||
where("to_id = (select _.id from users _ where lower(_.name) = ?)", name.downcase)
|
||||
end
|
||||
|
||||
|
||||
def from_name_matches(name)
|
||||
where("from_id = (select _.id from users _ where lower(_.name) = ?)", name.downcase)
|
||||
end
|
||||
|
||||
|
||||
def search(params)
|
||||
q = scoped
|
||||
return q if params.blank?
|
||||
|
||||
|
||||
if params[:message_matches].present?
|
||||
q = q.search_message(params[:message_matches])
|
||||
end
|
||||
|
||||
|
||||
if params[:owner_id].present?
|
||||
q = q.for(params[:owner_id].to_i)
|
||||
end
|
||||
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
include AddressMethods
|
||||
include FactoryMethods
|
||||
extend SearchMethods
|
||||
|
||||
|
||||
def validate_sender_is_not_banned
|
||||
if from.is_banned?
|
||||
errors[:base] = "Sender is banned and cannot send messages"
|
||||
@@ -162,29 +162,29 @@ class Dmail < ActiveRecord::Base
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def quoted_body
|
||||
"[quote]#{body}[/quote]"
|
||||
end
|
||||
|
||||
|
||||
def send_dmail
|
||||
if to.receive_email_notifications? && to.email.include?("@") && owner_id == CurrentUser.id
|
||||
UserMailer.dmail_notice(self).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def mark_as_read!
|
||||
update_column(:is_read, true)
|
||||
|
||||
|
||||
unless Dmail.exists?(["to_id = ? AND is_read = false", to_id])
|
||||
to.update_column(:has_mail, false)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def update_recipient
|
||||
to.update_column(:has_mail, true)
|
||||
end
|
||||
|
||||
|
||||
def visible_to?(user)
|
||||
user.is_moderator? || owner_id == user.id
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user