about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'app/services')
-rw-r--r--app/services/base_service.rb2
-rw-r--r--app/services/block_domain_service.rb2
-rw-r--r--app/services/block_service.rb4
-rw-r--r--app/services/fan_out_on_write_service.rb2
-rw-r--r--app/services/favourite_service.rb2
-rw-r--r--app/services/fetch_atom_service.rb20
-rw-r--r--app/services/fetch_remote_account_service.rb6
-rw-r--r--app/services/fetch_remote_status_service.rb8
-rw-r--r--app/services/follow_remote_account_service.rb6
-rw-r--r--app/services/follow_service.rb4
-rw-r--r--app/services/post_status_service.rb2
-rw-r--r--app/services/precompute_feed_service.rb6
-rw-r--r--app/services/process_feed_service.rb12
-rw-r--r--app/services/process_hashtags_service.rb6
-rw-r--r--app/services/process_interaction_service.rb8
-rw-r--r--app/services/process_mentions_service.rb2
-rw-r--r--app/services/reblog_service.rb2
-rw-r--r--app/services/remove_status_service.rb4
-rw-r--r--app/services/search_service.rb10
-rw-r--r--app/services/send_interaction_service.rb2
-rw-r--r--app/services/subscribe_service.rb2
-rw-r--r--app/services/unblock_service.rb2
-rw-r--r--app/services/unfavourite_service.rb2
-rw-r--r--app/services/unfollow_service.rb4
-rw-r--r--app/services/update_remote_profile_service.rb12
25 files changed, 85 insertions, 47 deletions
diff --git a/app/services/base_service.rb b/app/services/base_service.rb
index 10c558109..6653255f2 100644
--- a/app/services/base_service.rb
+++ b/app/services/base_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class BaseService
   include ActionView::Helpers::TextHelper
   include ActionView::Helpers::SanitizeHelper
diff --git a/app/services/block_domain_service.rb b/app/services/block_domain_service.rb
index 93987af29..a8fafe412 100644
--- a/app/services/block_domain_service.rb
+++ b/app/services/block_domain_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class BlockDomainService < BaseService
   def call(domain)
     DomainBlock.find_or_create_by!(domain: domain)
diff --git a/app/services/block_service.rb b/app/services/block_service.rb
index 6c841d25b..388a592e0 100644
--- a/app/services/block_service.rb
+++ b/app/services/block_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class BlockService < BaseService
   def call(account, target_account)
     return if account.id == target_account.id
@@ -20,6 +22,6 @@ class BlockService < BaseService
   end
 
   def redis
-    $redis
+    Redis.current
   end
 end
diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb
index 43e36c138..70cf06e02 100644
--- a/app/services/fan_out_on_write_service.rb
+++ b/app/services/fan_out_on_write_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class FanOutOnWriteService < BaseService
   # Push a status into home and mentions feeds
   # @param [Status] status
diff --git a/app/services/favourite_service.rb b/app/services/favourite_service.rb
index ab7f8aea1..9c6f12478 100644
--- a/app/services/favourite_service.rb
+++ b/app/services/favourite_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class FavouriteService < BaseService
   # Favourite a status and notify remote user
   # @param [Account] account
diff --git a/app/services/fetch_atom_service.rb b/app/services/fetch_atom_service.rb
index 5f00bf801..98ee1db84 100644
--- a/app/services/fetch_atom_service.rb
+++ b/app/services/fetch_atom_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class FetchAtomService < BaseService
   def call(url)
     response = http_client.head(url)
@@ -9,15 +11,9 @@ class FetchAtomService < BaseService
     Rails.logger.debug "Remote status GET request returned code #{response.code}"
 
     return nil if response.code != 200
-
-    if response.mime_type == 'application/atom+xml'
-      return [url, fetch(url)]
-    elsif !response['Link'].blank?
-      return process_headers(url, response)
-    else
-      return process_html(fetch(url))
-    end
-
+    return [url, fetch(url)] if response.mime_type == 'application/atom+xml'
+    return process_headers(url, response) unless response['Link'].blank?
+    process_html(fetch(url))
   rescue OpenSSL::SSL::SSLError => e
     Rails.logger.debug "SSL error: #{e}"
   end
@@ -31,17 +27,17 @@ class FetchAtomService < BaseService
     alternate_link = page.xpath('//link[@rel="alternate"]').find { |link| link['type'] == 'application/atom+xml' }
 
     return nil if alternate_link.nil?
-    return [alternate_link['href'], fetch(alternate_link['href'])]
+    [alternate_link['href'], fetch(alternate_link['href'])]
   end
 
   def process_headers(url, response)
     Rails.logger.debug 'Processing link header'
 
     link_header    = LinkHeader.parse(response['Link'].is_a?(Array) ? response['Link'].first : response['Link'])
-    alternate_link = link_header.find_link(['rel', 'alternate'], ['type', 'application/atom+xml'])
+    alternate_link = link_header.find_link(%w(rel alternate), %w(type application/atom+xml))
 
     return process_html(fetch(url)) if alternate_link.nil?
-    return [alternate_link.href, fetch(alternate_link.href)]
+    [alternate_link.href, fetch(alternate_link.href)]
   end
 
   def fetch(url)
diff --git a/app/services/fetch_remote_account_service.rb b/app/services/fetch_remote_account_service.rb
index 7cbc9f6ec..3c3694a65 100644
--- a/app/services/fetch_remote_account_service.rb
+++ b/app/services/fetch_remote_account_service.rb
@@ -1,9 +1,11 @@
+# frozen_string_literal: true
+
 class FetchRemoteAccountService < BaseService
   def call(url)
     atom_url, body = FetchAtomService.new.call(url)
 
     return nil if atom_url.nil?
-    return process_atom(atom_url, body)
+    process_atom(atom_url, body)
   end
 
   private
@@ -25,7 +27,7 @@ class FetchRemoteAccountService < BaseService
     Rails.logger.debug "Unparseable URL given: #{url}"
     nil
   rescue Nokogiri::XML::XPath::SyntaxError
-    Rails.logger.debug "Invalid XML or missing namespace"
+    Rails.logger.debug 'Invalid XML or missing namespace'
     nil
   end
 end
diff --git a/app/services/fetch_remote_status_service.rb b/app/services/fetch_remote_status_service.rb
index e4537d61f..7063231e4 100644
--- a/app/services/fetch_remote_status_service.rb
+++ b/app/services/fetch_remote_status_service.rb
@@ -1,9 +1,11 @@
+# frozen_string_literal: true
+
 class FetchRemoteStatusService < BaseService
   def call(url)
     atom_url, body = FetchAtomService.new.call(url)
 
     return nil if atom_url.nil?
-    return process_atom(atom_url, body)
+    process_atom(atom_url, body)
   end
 
   private
@@ -20,7 +22,7 @@ class FetchRemoteStatusService < BaseService
 
     statuses = ProcessFeedService.new.call(body, account)
 
-    return statuses.first
+    statuses.first
   end
 
   def extract_author(url, xml)
@@ -34,7 +36,7 @@ class FetchRemoteStatusService < BaseService
 
     return FollowRemoteAccountService.new.call("#{username}@#{domain}")
   rescue Nokogiri::XML::XPath::SyntaxError
-    Rails.logger.debug "Invalid XML or missing namespace"
+    Rails.logger.debug 'Invalid XML or missing namespace'
     nil
   end
 end
diff --git a/app/services/follow_remote_account_service.rb b/app/services/follow_remote_account_service.rb
index b309425a8..37339d8ed 100644
--- a/app/services/follow_remote_account_service.rb
+++ b/app/services/follow_remote_account_service.rb
@@ -1,7 +1,9 @@
+# frozen_string_literal: true
+
 class FollowRemoteAccountService < BaseService
   include OStatus2::MagicKey
 
-  DFRN_NS = 'http://purl.org/macgirvin/dfrn/1.0'.freeze
+  DFRN_NS = 'http://purl.org/macgirvin/dfrn/1.0'
 
   # Find or create a local account for a remote user.
   # When creating, look up the user's webfinger and fetch all
@@ -49,7 +51,7 @@ class FollowRemoteAccountService < BaseService
     get_profile(xml, account)
     account.save!
 
-    return account
+    account
   end
 
   private
diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb
index 2a9dc82c3..3b97840cb 100644
--- a/app/services/follow_service.rb
+++ b/app/services/follow_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class FollowService < BaseService
   # Follow a remote user, notify remote user about the follow
   # @param [Account] source_account From which to follow
@@ -35,7 +37,7 @@ class FollowService < BaseService
   end
 
   def redis
-    $redis
+    Redis.current
   end
 
   def follow_remote_account_service
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index b23808a7c..cf824ff99 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class PostStatusService < BaseService
   # Post a text status update, fetch and notify remote users mentioned
   # @param [Account] account Account from which to post
diff --git a/app/services/precompute_feed_service.rb b/app/services/precompute_feed_service.rb
index 3094c50fd..54d11b631 100644
--- a/app/services/precompute_feed_service.rb
+++ b/app/services/precompute_feed_service.rb
@@ -1,10 +1,10 @@
+# frozen_string_literal: true
+
 class PrecomputeFeedService < BaseService
   # Fill up a user's home/mentions feed from DB and return a subset
   # @param [Symbol] type :home or :mentions
   # @param [Account] account
   def call(type, account)
-    instant_return = []
-
     Status.send("as_#{type}_timeline", account).limit(FeedManager::MAX_ITEMS).each do |status|
       next if FeedManager.instance.filter?(type, status, account)
       redis.zadd(FeedManager.instance.key(type, account.id), status.id, status.reblog? ? status.reblog_of_id : status.id)
@@ -14,6 +14,6 @@ class PrecomputeFeedService < BaseService
   private
 
   def redis
-    $redis
+    Redis.current
   end
 end
diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb
index b671c809d..561feb032 100644
--- a/app/services/process_feed_service.rb
+++ b/app/services/process_feed_service.rb
@@ -1,6 +1,8 @@
+# frozen_string_literal: true
+
 class ProcessFeedService < BaseService
-  ACTIVITY_NS = 'http://activitystrea.ms/spec/1.0/'.freeze
-  THREAD_NS   = 'http://purl.org/syndication/thread/1.0'.freeze
+  ACTIVITY_NS = 'http://activitystrea.ms/spec/1.0/'
+  THREAD_NS   = 'http://purl.org/syndication/thread/1.0'
 
   def call(body, account)
     xml = Nokogiri::XML(body)
@@ -89,13 +91,13 @@ class ProcessFeedService < BaseService
         account = @account
       end
 
-      status = Status.create!({
+      status = Status.create!(
         uri: id(entry),
         url: url(entry),
         account: account,
         text: content(entry),
-        created_at: published(entry),
-      })
+        created_at: published(entry)
+      )
 
       if thread?(entry)
         Rails.logger.debug "Trying to attach #{status.id} (#{id(entry)}) to #{thread(entry).first}"
diff --git a/app/services/process_hashtags_service.rb b/app/services/process_hashtags_service.rb
index df30f73ae..3bf3471ec 100644
--- a/app/services/process_hashtags_service.rb
+++ b/app/services/process_hashtags_service.rb
@@ -1,8 +1,8 @@
+# frozen_string_literal: true
+
 class ProcessHashtagsService < BaseService
   def call(status, tags = [])
-    if status.local?
-      tags = status.text.scan(Tag::HASHTAG_RE).map(&:first)
-    end
+    tags = status.text.scan(Tag::HASHTAG_RE).map(&:first) if status.local?
 
     tags.map(&:downcase).uniq.each do |tag|
       status.tags << Tag.where(name: tag).first_or_initialize(name: tag)
diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb
index be78ebb58..ecd3c2b2c 100644
--- a/app/services/process_interaction_service.rb
+++ b/app/services/process_interaction_service.rb
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
 class ProcessInteractionService < BaseService
-  ACTIVITY_NS = 'http://activitystrea.ms/spec/1.0/'.freeze
+  ACTIVITY_NS = 'http://activitystrea.ms/spec/1.0/'
 
   # Record locally the remote interaction with our user
   # @param [String] envelope Salmon envelope
@@ -76,9 +78,7 @@ class ProcessInteractionService < BaseService
 
     return if status.nil?
 
-    if account.id == status.account_id
-      remove_status_service.call(status)
-    end
+    remove_status_service.call(status) if account.id == status.account_id
   end
 
   def favourite!(xml, from_account)
diff --git a/app/services/process_mentions_service.rb b/app/services/process_mentions_service.rb
index 8baa03d07..fd5a02ffe 100644
--- a/app/services/process_mentions_service.rb
+++ b/app/services/process_mentions_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class ProcessMentionsService < BaseService
   # Scan status for mentions and fetch remote mentioned users, create
   # local mention pointers, send Salmon notifications to mentioned
diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb
index 627d4e0e8..884d911a4 100644
--- a/app/services/reblog_service.rb
+++ b/app/services/reblog_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class ReblogService < BaseService
   # Reblog a status and notify its remote author
   # @param [Account] account Account to reblog from
diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb
index 66fa1be18..689abc97b 100644
--- a/app/services/remove_status_service.rb
+++ b/app/services/remove_status_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class RemoveStatusService < BaseService
   def call(status)
     remove_from_self(status) if status.account.local?
@@ -62,6 +64,6 @@ class RemoveStatusService < BaseService
   end
 
   def redis
-    $redis
+    Redis.current
   end
 end
diff --git a/app/services/search_service.rb b/app/services/search_service.rb
index 9e8ee6220..c4cffda13 100644
--- a/app/services/search_service.rb
+++ b/app/services/search_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class SearchService < BaseService
   def call(query, limit, resolve = false)
     return if query.blank?
@@ -5,10 +7,10 @@ class SearchService < BaseService
     username, domain = query.split('@')
 
     results = if domain.nil?
-      Account.search_for(username)
-    else
-      Account.search_for("#{username} #{domain}")
-    end
+                Account.search_for(username)
+              else
+                Account.search_for("#{username} #{domain}")
+              end
 
     results = results.limit(limit).with_counters
 
diff --git a/app/services/send_interaction_service.rb b/app/services/send_interaction_service.rb
index a425dcc8e..05a1e77e3 100644
--- a/app/services/send_interaction_service.rb
+++ b/app/services/send_interaction_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class SendInteractionService < BaseService
   # Send an Atom representation of an interaction to a remote Salmon endpoint
   # @param [StreamEntry] stream_entry
diff --git a/app/services/subscribe_service.rb b/app/services/subscribe_service.rb
index 427a5e198..820b208e9 100644
--- a/app/services/subscribe_service.rb
+++ b/app/services/subscribe_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class SubscribeService < BaseService
   def call(account)
     account.secret = SecureRandom.hex
diff --git a/app/services/unblock_service.rb b/app/services/unblock_service.rb
index d24161423..3658dcd71 100644
--- a/app/services/unblock_service.rb
+++ b/app/services/unblock_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class UnblockService < BaseService
   def call(account, target_account)
     account.unblock!(target_account) if account.blocking?(target_account)
diff --git a/app/services/unfavourite_service.rb b/app/services/unfavourite_service.rb
index 2491c194f..de6e84e7d 100644
--- a/app/services/unfavourite_service.rb
+++ b/app/services/unfavourite_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class UnfavouriteService < BaseService
   def call(account, status)
     favourite = Favourite.find_by!(account: account, status: status)
diff --git a/app/services/unfollow_service.rb b/app/services/unfollow_service.rb
index d22451a74..b3386a99c 100644
--- a/app/services/unfollow_service.rb
+++ b/app/services/unfollow_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class UnfollowService < BaseService
   # Unfollow and notify the remote user
   # @param [Account] source_account Where to unfollow from
@@ -21,6 +23,6 @@ class UnfollowService < BaseService
   end
 
   def redis
-    $redis
+    Redis.current
   end
 end
diff --git a/app/services/update_remote_profile_service.rb b/app/services/update_remote_profile_service.rb
index 14f8cc868..2909ae12a 100644
--- a/app/services/update_remote_profile_service.rb
+++ b/app/services/update_remote_profile_service.rb
@@ -1,14 +1,16 @@
+# frozen_string_literal: true
+
 class UpdateRemoteProfileService < BaseService
   POCO_NS = 'http://portablecontacts.net/spec/1.0'
 
   def call(author_xml, account)
     return if author_xml.nil?
 
-    if author_xml.at_xpath('./poco:displayName', poco: POCO_NS).nil?
-      account.display_name = account.username
-    else
-      account.display_name = author_xml.at_xpath('./poco:displayName', poco: POCO_NS).content
-    end
+    account.display_name = if author_xml.at_xpath('./poco:displayName', poco: POCO_NS).nil?
+                             account.username
+                           else
+                             author_xml.at_xpath('./poco:displayName', poco: POCO_NS).content
+                           end
 
     unless author_xml.at_xpath('./poco:note').nil?
       account.note = author_xml.at_xpath('./poco:note', poco: POCO_NS).content