dmails: drop unneeded methods.

This commit is contained in:
evazion
2019-08-18 03:50:43 -05:00
parent 27a118dfc8
commit 17b2cd38cd
2 changed files with 4 additions and 28 deletions

View File

@@ -20,7 +20,7 @@ class Dmail < ApplicationRecord
after_create :update_recipient
after_commit :send_email, on: :create
rakismet_attrs author: :from_name, author_email: :from_email, content: :title_and_body, user_ip: :creator_ip_addr_str
rakismet_attrs author: -> { from.name }, author_email: -> { from.email }, content: -> { title + "\n\n" + body }, user_ip: -> { creator_ip_addr.to_s }
concerning :SpamMethods do
class_methods do
@@ -40,14 +40,6 @@ class Dmail < ApplicationRecord
end
end
def title_and_body
"#{title}\n\n#{body}"
end
def creator_ip_addr_str
creator_ip_addr.to_s
end
def spam?
return false if Danbooru.config.rakismet_key.blank?
return false if from.is_gold?
@@ -56,18 +48,6 @@ class Dmail < ApplicationRecord
end
module AddressMethods
def to_name
User.id_to_pretty_name(to_id)
end
def from_name
User.id_to_pretty_name(from_id)
end
def from_email
from.email
end
def to_name=(name)
self.to_id = User.name_to_id(name)
end
@@ -218,7 +198,7 @@ class Dmail < ApplicationRecord
end
def quoted_body
"[quote]\n#{from_name} said:\n\n#{body}\n[/quote]\n\n"
"[quote]\n#{from.pretty_name} said:\n\n#{body}\n[/quote]\n\n"
end
def send_email
@@ -253,12 +233,12 @@ class Dmail < ApplicationRecord
to.update(has_mail: true, unread_dmail_count: to.dmails.unread.count)
end
end
def key
verifier = ActiveSupport::MessageVerifier.new(Danbooru.config.email_key, serializer: JSON, digest: "SHA256")
verifier.generate("#{title} #{body}")
end
def visible_to?(user, key)
owner_id == user.id || (user.is_moderator? && key == self.key)
end

View File

@@ -156,10 +156,6 @@ class User < ApplicationRecord
where("lower(name) = ?", name.mb_chars.downcase.tr(" ", "_")).first
end
def id_to_pretty_name(user_id)
id_to_name(user_id).gsub(/([^_])_+(?=[^_])/, "\\1 \\2")
end
def normalize_name(name)
name.to_s.mb_chars.downcase.strip.tr(" ", "_").to_s
end