From b25e42a77f4b3472bc519e8a394b2cfe0e063e4c Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 31 May 2017 14:38:17 -0400 Subject: [PATCH] Misc tidying and clean ups (#3445) * Remove trailing whitespace in i18n mailers * Use query methods instead of #present? on AR attributes * Delegate Status#account_domain method * Delegate Mention #account_username and #account_acct methods --- app/lib/atom_serializer.rb | 2 +- app/models/mention.rb | 7 +++++++ app/models/status.rb | 4 +++- app/services/post_status_service.rb | 2 +- app/services/process_feed_service.rb | 2 +- app/views/api/v1/statuses/_mention.rabl | 4 ++-- .../user_mailer/confirmation_instructions.ar.text.erb | 2 +- .../user_mailer/confirmation_instructions.fa.text.erb | 4 ++-- 8 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/lib/atom_serializer.rb b/app/lib/atom_serializer.rb index 561bf7b59b2..21ee7deba5b 100644 --- a/app/lib/atom_serializer.rb +++ b/app/lib/atom_serializer.rb @@ -328,7 +328,7 @@ class AtomSerializer end def conversation_uri(conversation) - return conversation.uri if conversation.uri.present? + return conversation.uri if conversation.uri? TagManager.instance.unique_tag(conversation.created_at, conversation.id, 'Conversation') end diff --git a/app/models/mention.rb b/app/models/mention.rb index a8d243259cb..7450b1b852d 100644 --- a/app/models/mention.rb +++ b/app/models/mention.rb @@ -17,4 +17,11 @@ class Mention < ApplicationRecord has_one :notification, as: :activity, dependent: :destroy validates :account, uniqueness: { scope: :status } + + delegate( + :username, + :acct, + to: :account, + prefix: true + ) end diff --git a/app/models/status.rb b/app/models/status.rb index a371083d056..e75ac7070f6 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -73,6 +73,8 @@ class Status < ApplicationRecord cache_associated :account, :application, :media_attachments, :tags, :stream_entry, mentions: :account, reblog: [:account, :application, :stream_entry, :tags, :media_attachments, mentions: :account], thread: :account + delegate :domain, to: :account, prefix: true + def reply? !in_reply_to_id.nil? || attributes['reply'] end @@ -288,7 +290,7 @@ class Status < ApplicationRecord def filter_from_context?(status, account) should_filter = account&.blocking?(status.account_id) - should_filter ||= account&.domain_blocking?(status.account.domain) + should_filter ||= account&.domain_blocking?(status.account_domain) should_filter ||= account&.muting?(status.account_id) should_filter ||= (status.account.silenced? && !account&.following?(status.account_id)) should_filter ||= !StatusPolicy.new(account, status).show? diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index b665391e3f1..2e6fbb5c382 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -34,7 +34,7 @@ class PostStatusService < BaseService process_mentions_service.call(status) process_hashtags_service.call(status) - LinkCrawlWorker.perform_async(status.id) unless status.spoiler_text.present? + LinkCrawlWorker.perform_async(status.id) unless status.spoiler_text? DistributionWorker.perform_async(status.id) Pubsubhubbub::DistributionWorker.perform_async(status.stream_entry.id) diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb index 87ed68f7042..9402baf180a 100644 --- a/app/services/process_feed_service.rb +++ b/app/services/process_feed_service.rb @@ -77,7 +77,7 @@ class ProcessFeedService < BaseService Rails.logger.debug "Queuing remote status #{status.id} (#{id}) for distribution" - LinkCrawlWorker.perform_async(status.id) unless status.spoiler_text.present? + LinkCrawlWorker.perform_async(status.id) unless status.spoiler_text? DistributionWorker.perform_async(status.id) status diff --git a/app/views/api/v1/statuses/_mention.rabl b/app/views/api/v1/statuses/_mention.rabl index 498cca27571..8c95fc9bde7 100644 --- a/app/views/api/v1/statuses/_mention.rabl +++ b/app/views/api/v1/statuses/_mention.rabl @@ -1,4 +1,4 @@ node(:url) { |mention| TagManager.instance.url_for(mention.account) } -node(:acct) { |mention| mention.account.acct } +node(:acct) { |mention| mention.account_acct } node(:id) { |mention| mention.account_id } -node(:username) { |mention| mention.account.username } +node(:username) { |mention| mention.account_username } diff --git a/app/views/user_mailer/confirmation_instructions.ar.text.erb b/app/views/user_mailer/confirmation_instructions.ar.text.erb index 1b7b445a1ae..087c6a9ae4a 100644 --- a/app/views/user_mailer/confirmation_instructions.ar.text.erb +++ b/app/views/user_mailer/confirmation_instructions.ar.text.erb @@ -9,4 +9,4 @@ مع أجمل التحيات، -فريق <%= @instance %> +فريق <%= @instance %> diff --git a/app/views/user_mailer/confirmation_instructions.fa.text.erb b/app/views/user_mailer/confirmation_instructions.fa.text.erb index cbabed06d4e..904bd5bfe79 100644 --- a/app/views/user_mailer/confirmation_instructions.fa.text.erb +++ b/app/views/user_mailer/confirmation_instructions.fa.text.erb @@ -2,11 +2,11 @@ شما الان در <%= @instance %> حساب باز کردید. -برای تأیید عضویت، لطفاً روی پیوند زیر کلیک کنید: +برای تأیید عضویت، لطفاً روی پیوند زیر کلیک کنید: <%= confirmation_url(@resource, confirmation_token: @token) %> لطفاً همچنین شرایط و مقررات استفادهٔ ما را هم بخوانید <%= terms_url %> با احترام، -گردانندگان سرور <%= @instance %> +گردانندگان سرور <%= @instance %>