dmails: drop unneeded methods.
This commit is contained in:
@@ -20,7 +20,7 @@ class Dmail < ApplicationRecord
|
|||||||
after_create :update_recipient
|
after_create :update_recipient
|
||||||
after_commit :send_email, on: :create
|
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
|
concerning :SpamMethods do
|
||||||
class_methods do
|
class_methods do
|
||||||
@@ -40,14 +40,6 @@ class Dmail < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def title_and_body
|
|
||||||
"#{title}\n\n#{body}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def creator_ip_addr_str
|
|
||||||
creator_ip_addr.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
def spam?
|
def spam?
|
||||||
return false if Danbooru.config.rakismet_key.blank?
|
return false if Danbooru.config.rakismet_key.blank?
|
||||||
return false if from.is_gold?
|
return false if from.is_gold?
|
||||||
@@ -56,18 +48,6 @@ class Dmail < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
module AddressMethods
|
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)
|
def to_name=(name)
|
||||||
self.to_id = User.name_to_id(name)
|
self.to_id = User.name_to_id(name)
|
||||||
end
|
end
|
||||||
@@ -218,7 +198,7 @@ class Dmail < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def quoted_body
|
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
|
end
|
||||||
|
|
||||||
def send_email
|
def send_email
|
||||||
@@ -253,12 +233,12 @@ class Dmail < ApplicationRecord
|
|||||||
to.update(has_mail: true, unread_dmail_count: to.dmails.unread.count)
|
to.update(has_mail: true, unread_dmail_count: to.dmails.unread.count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def key
|
def key
|
||||||
verifier = ActiveSupport::MessageVerifier.new(Danbooru.config.email_key, serializer: JSON, digest: "SHA256")
|
verifier = ActiveSupport::MessageVerifier.new(Danbooru.config.email_key, serializer: JSON, digest: "SHA256")
|
||||||
verifier.generate("#{title} #{body}")
|
verifier.generate("#{title} #{body}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible_to?(user, key)
|
def visible_to?(user, key)
|
||||||
owner_id == user.id || (user.is_moderator? && key == self.key)
|
owner_id == user.id || (user.is_moderator? && key == self.key)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -156,10 +156,6 @@ class User < ApplicationRecord
|
|||||||
where("lower(name) = ?", name.mb_chars.downcase.tr(" ", "_")).first
|
where("lower(name) = ?", name.mb_chars.downcase.tr(" ", "_")).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def id_to_pretty_name(user_id)
|
|
||||||
id_to_name(user_id).gsub(/([^_])_+(?=[^_])/, "\\1 \\2")
|
|
||||||
end
|
|
||||||
|
|
||||||
def normalize_name(name)
|
def normalize_name(name)
|
||||||
name.to_s.mb_chars.downcase.strip.tr(" ", "_").to_s
|
name.to_s.mb_chars.downcase.strip.tr(" ", "_").to_s
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user