From 17b2cd38cde94bb9e2b404a2002b8165d51deb5c Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 18 Aug 2019 03:50:43 -0500 Subject: [PATCH] dmails: drop unneeded methods. --- app/models/dmail.rb | 28 ++++------------------------ app/models/user.rb | 4 ---- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/app/models/dmail.rb b/app/models/dmail.rb index 2439a2370..f55613a82 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 0243dad15..ff64278e0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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