Browse Source

Fix rubocop issues, introduce usage of frozen literal to improve performance

Eugen Rochko 2 years ago
parent
commit
fdc17bea58
96 changed files with 329 additions and 126 deletions
  1. 32
    4
      .rubocop.yml
  2. 2
    0
      Gemfile
  3. 2
    0
      app/channels/application_cable/channel.rb
  4. 2
    0
      app/channels/application_cable/connection.rb
  5. 2
    0
      app/channels/hashtag_channel.rb
  6. 2
    0
      app/channels/public_channel.rb
  7. 2
    0
      app/channels/timeline_channel.rb
  8. 2
    0
      app/controllers/about_controller.rb
  9. 3
    4
      app/controllers/accounts_controller.rb
  10. 2
    0
      app/controllers/api/salmon_controller.rb
  11. 2
    0
      app/controllers/api/subscriptions_controller.rb
  12. 5
    3
      app/controllers/api/v1/accounts_controller.rb
  13. 2
    0
      app/controllers/api/v1/apps_controller.rb
  14. 2
    0
      app/controllers/api/v1/follows_controller.rb
  15. 2
    0
      app/controllers/api/v1/media_controller.rb
  16. 5
    3
      app/controllers/api/v1/statuses_controller.rb
  17. 6
    4
      app/controllers/api/v1/timelines_controller.rb
  18. 5
    3
      app/controllers/api_controller.rb
  19. 2
    0
      app/controllers/application_controller.rb
  20. 2
    0
      app/controllers/auth/confirmations_controller.rb
  21. 2
    0
      app/controllers/auth/passwords_controller.rb
  22. 2
    0
      app/controllers/auth/registrations_controller.rb
  23. 2
    0
      app/controllers/auth/sessions_controller.rb
  24. 2
    0
      app/controllers/home_controller.rb
  25. 2
    0
      app/controllers/media_controller.rb
  26. 2
    0
      app/controllers/oauth/authorizations_controller.rb
  27. 2
    0
      app/controllers/settings/preferences_controller.rb
  28. 2
    0
      app/controllers/settings/profiles_controller.rb
  29. 3
    3
      app/controllers/stream_entries_controller.rb
  30. 2
    0
      app/controllers/tags_controller.rb
  31. 6
    4
      app/controllers/xrd_controller.rb
  32. 2
    0
      app/helpers/about_helper.rb
  33. 5
    3
      app/helpers/accounts_helper.rb
  34. 2
    0
      app/helpers/application_helper.rb
  35. 8
    2
      app/helpers/atom_builder_helper.rb
  36. 3
    1
      app/helpers/home_helper.rb
  37. 2
    0
      app/helpers/routing_helper.rb
  38. 2
    0
      app/helpers/stream_entries_helper.rb
  39. 2
    0
      app/helpers/tags_helper.rb
  40. 2
    0
      app/helpers/xrd_helper.rb
  41. 15
    13
      app/lib/feed_manager.rb
  42. 4
    2
      app/lib/formatter.rb
  43. 3
    1
      app/lib/tag_manager.rb
  44. 2
    0
      app/mailers/application_mailer.rb
  45. 2
    0
      app/mailers/notification_mailer.rb
  46. 6
    4
      app/models/account.rb
  47. 2
    0
      app/models/application_record.rb
  48. 2
    0
      app/models/block.rb
  49. 2
    0
      app/models/concerns/paginable.rb
  50. 2
    0
      app/models/concerns/streamable.rb
  51. 2
    0
      app/models/concerns/targetable.rb
  52. 2
    0
      app/models/domain_block.rb
  53. 2
    0
      app/models/favourite.rb
  54. 3
    1
      app/models/feed.rb
  55. 2
    0
      app/models/follow.rb
  56. 2
    0
      app/models/follow_suggestion.rb
  57. 12
    10
      app/models/media_attachment.rb
  58. 2
    0
      app/models/mention.rb
  59. 6
    9
      app/models/status.rb
  60. 7
    1
      app/models/stream_entry.rb
  61. 2
    0
      app/models/tag.rb
  62. 2
    0
      app/models/user.rb
  63. 2
    0
      app/services/base_service.rb
  64. 2
    0
      app/services/block_domain_service.rb
  65. 3
    1
      app/services/block_service.rb
  66. 2
    0
      app/services/fan_out_on_write_service.rb
  67. 2
    0
      app/services/favourite_service.rb
  68. 8
    12
      app/services/fetch_atom_service.rb
  69. 4
    2
      app/services/fetch_remote_account_service.rb
  70. 5
    3
      app/services/fetch_remote_status_service.rb
  71. 4
    2
      app/services/follow_remote_account_service.rb
  72. 3
    1
      app/services/follow_service.rb
  73. 2
    0
      app/services/post_status_service.rb
  74. 3
    3
      app/services/precompute_feed_service.rb
  75. 7
    5
      app/services/process_feed_service.rb
  76. 3
    3
      app/services/process_hashtags_service.rb
  77. 4
    4
      app/services/process_interaction_service.rb
  78. 2
    0
      app/services/process_mentions_service.rb
  79. 2
    0
      app/services/reblog_service.rb
  80. 3
    1
      app/services/remove_status_service.rb
  81. 6
    4
      app/services/search_service.rb
  82. 2
    0
      app/services/send_interaction_service.rb
  83. 2
    0
      app/services/subscribe_service.rb
  84. 2
    0
      app/services/unblock_service.rb
  85. 2
    0
      app/services/unfavourite_service.rb
  86. 3
    1
      app/services/unfollow_service.rb
  87. 7
    5
      app/services/update_remote_profile_service.rb
  88. 2
    0
      app/workers/distribution_worker.rb
  89. 2
    0
      app/workers/hub_ping_worker.rb
  90. 2
    0
      app/workers/notification_worker.rb
  91. 2
    0
      app/workers/processing_worker.rb
  92. 2
    0
      app/workers/regeneration_worker.rb
  93. 2
    0
      app/workers/thread_resolve_worker.rb
  94. 1
    0
      config.ru
  95. 4
    2
      config/initializers/redis.rb
  96. 4
    2
      lib/tasks/mastodon.rake

+ 32
- 4
.rubocop.yml View File

@@ -18,9 +18,29 @@ Metrics/MethodLength:
18 18
   CountComments: false
19 19
   Max: 10
20 20
 
21
-Metrics/ModuleLength:
21
+Metrics/AbcSize:
22 22
   Max: 100
23 23
 
24
+Metrics/BlockNesting:
25
+  Max: 3
26
+
27
+Metrics/ClassLength:
28
+  CountComments: false
29
+  Max: 200
30
+
31
+Metrics/CyclomaticComplexity:
32
+  Max: 15
33
+
34
+Metrics/MethodLength:
35
+  Max: 55
36
+
37
+Metrics/ModuleLength:
38
+  CountComments: false
39
+  Max: 200
40
+
41
+Metrics/PerceivedComplexity:
42
+  Max: 10
43
+
24 44
 Metrics/ParameterLists:
25 45
   Max: 4
26 46
   CountKeywordArgs: true
@@ -37,10 +57,10 @@ Style/Documentation:
37 57
   Enabled: false
38 58
 
39 59
 Style/DoubleNegation:
40
-  Enabled: false
60
+  Enabled: true
41 61
 
42 62
 Style/FrozenStringLiteralComment:
43
-  Enabled: false
63
+  Enabled: true
44 64
 
45 65
 Style/SpaceInsideHashLiteralBraces:
46 66
   EnforcedStyle: space
@@ -51,10 +71,18 @@ Style/TrailingCommaInLiteral:
51 71
 Style/RegexpLiteral:
52 72
   Enabled: false
53 73
 
74
+Style/Lambda:
75
+  Enabled: false
76
+
77
+Rails/HasAndBelongsToMany:
78
+  Enabled: false
79
+
54 80
 AllCops:
55
-  TargetRubyVersion: 2.2
81
+  TargetRubyVersion: 2.3
56 82
   Exclude:
57 83
   - 'spec/**/*'
58 84
   - 'db/**/*'
59 85
   - 'app/views/**/*'
60 86
   - 'config/**/*'
87
+  - 'bin/*'
88
+  - 'Rakefile'

+ 2
- 0
Gemfile View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 source 'https://rubygems.org'
2 4
 
3 5
 gem 'rails', '5.0.0.1'

+ 2
- 0
app/channels/application_cable/channel.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 module ApplicationCable
2 4
   class Channel < ActionCable::Channel::Base
3 5
     protected

+ 2
- 0
app/channels/application_cable/connection.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 module ApplicationCable
2 4
   class Connection < ActionCable::Connection::Base
3 5
     identified_by :current_user

+ 2
- 0
app/channels/hashtag_channel.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class HashtagChannel < ApplicationCable::Channel
2 4
   def subscribed
3 5
     tag = params[:tag].downcase

+ 2
- 0
app/channels/public_channel.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class PublicChannel < ApplicationCable::Channel
2 4
   def subscribed
3 5
     stream_from 'timeline:public', lambda { |encoded_message|

+ 2
- 0
app/channels/timeline_channel.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class TimelineChannel < ApplicationCable::Channel
2 4
   def subscribed
3 5
     stream_from "timeline:#{current_user.account_id}"

+ 2
- 0
app/controllers/about_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class AboutController < ApplicationController
2 4
   before_action :set_body_classes
3 5
 

+ 3
- 4
app/controllers/accounts_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class AccountsController < ApplicationController
2 4
   layout 'public'
3 5
 
@@ -41,10 +43,7 @@ class AccountsController < ApplicationController
41 43
   end
42 44
 
43 45
   def set_link_headers
44
-    response.headers['Link'] = LinkHeader.new([
45
-      [webfinger_account_url, [['rel', 'lrdd'], ['type', 'application/xrd+xml']]],
46
-      [account_url(@account, format: 'atom'), [['rel', 'alternate'], ['type', 'application/atom+xml']]]
47
-    ])
46
+    response.headers['Link'] = LinkHeader.new([[webfinger_account_url, [%w(rel lrdd), %w(type application/xrd+xml)]], [account_url(@account, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]]])
48 47
   end
49 48
 
50 49
   def webfinger_account_url

+ 2
- 0
app/controllers/api/salmon_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Api::SalmonController < ApiController
2 4
   before_action :set_account
3 5
   respond_to :txt

+ 2
- 0
app/controllers/api/subscriptions_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Api::SubscriptionsController < ApiController
2 4
   before_action :set_account
3 5
   respond_to :txt

+ 5
- 3
app/controllers/api/v1/accounts_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Api::V1::AccountsController < ApiController
2 4
   before_action -> { doorkeeper_authorize! :read }, except: [:follow, :unfollow, :block, :unblock]
3 5
   before_action -> { doorkeeper_authorize! :follow }, only: [:follow, :unfollow, :block, :unblock]
@@ -20,7 +22,7 @@ class Api::V1::AccountsController < ApiController
20 22
     @accounts = results.map { |f| accounts[f.target_account_id] }
21 23
 
22 24
     next_path = following_api_v1_account_url(max_id: results.last.id)    if results.size == DEFAULT_ACCOUNTS_LIMIT
23
-    prev_path = following_api_v1_account_url(since_id: results.first.id) if results.size > 0
25
+    prev_path = following_api_v1_account_url(since_id: results.first.id) unless results.empty?
24 26
 
25 27
     set_pagination_headers(next_path, prev_path)
26 28
 
@@ -33,7 +35,7 @@ class Api::V1::AccountsController < ApiController
33 35
     @accounts = results.map { |f| accounts[f.account_id] }
34 36
 
35 37
     next_path = followers_api_v1_account_url(max_id: results.last.id)    if results.size == DEFAULT_ACCOUNTS_LIMIT
36
-    prev_path = followers_api_v1_account_url(since_id: results.first.id) if results.size > 0
38
+    prev_path = followers_api_v1_account_url(since_id: results.first.id) unless results.empty?
37 39
 
38 40
     set_pagination_headers(next_path, prev_path)
39 41
 
@@ -56,7 +58,7 @@ class Api::V1::AccountsController < ApiController
56 58
     set_maps(@statuses)
57 59
 
58 60
     next_path = statuses_api_v1_account_url(max_id: @statuses.last.id)    if @statuses.size == DEFAULT_STATUSES_LIMIT
59
-    prev_path = statuses_api_v1_account_url(since_id: @statuses.first.id) if @statuses.size > 0
61
+    prev_path = statuses_api_v1_account_url(since_id: @statuses.first.id) unless @statuses.empty?
60 62
 
61 63
     set_pagination_headers(next_path, prev_path)
62 64
   end

+ 2
- 0
app/controllers/api/v1/apps_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Api::V1::AppsController < ApiController
2 4
   respond_to :json
3 5
 

+ 2
- 0
app/controllers/api/v1/follows_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Api::V1::FollowsController < ApiController
2 4
   before_action -> { doorkeeper_authorize! :follow }
3 5
   before_action :require_user!

+ 2
- 0
app/controllers/api/v1/media_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Api::V1::MediaController < ApiController
2 4
   before_action -> { doorkeeper_authorize! :write }
3 5
   before_action :require_user!

+ 5
- 3
app/controllers/api/v1/statuses_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Api::V1::StatusesController < ApiController
2 4
   before_action -> { doorkeeper_authorize! :read }, except: [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
3 5
   before_action -> { doorkeeper_authorize! :write }, only:  [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
@@ -10,7 +12,7 @@ class Api::V1::StatusesController < ApiController
10 12
   end
11 13
 
12 14
   def context
13
-    @context = OpenStruct.new({ ancestors: @status.ancestors, descendants: @status.descendants })
15
+    @context = OpenStruct.new(ancestors: @status.ancestors, descendants: @status.descendants)
14 16
     set_maps([@status] + @context[:ancestors] + @context[:descendants])
15 17
   end
16 18
 
@@ -20,7 +22,7 @@ class Api::V1::StatusesController < ApiController
20 22
     @accounts = results.map { |r| accounts[r.account_id] }
21 23
 
22 24
     next_path = reblogged_by_api_v1_status_url(max_id: results.last.id)    if results.size == DEFAULT_ACCOUNTS_LIMIT
23
-    prev_path = reblogged_by_api_v1_status_url(since_id: results.first.id) if results.size > 0
25
+    prev_path = reblogged_by_api_v1_status_url(since_id: results.first.id) unless results.empty?
24 26
 
25 27
     set_pagination_headers(next_path, prev_path)
26 28
 
@@ -33,7 +35,7 @@ class Api::V1::StatusesController < ApiController
33 35
     @accounts = results.map { |f| accounts[f.account_id] }
34 36
 
35 37
     next_path = favourited_by_api_v1_status_url(max_id: results.last.id)    if results.size == DEFAULT_ACCOUNTS_LIMIT
36
-    prev_path = favourited_by_api_v1_status_url(since_id: results.first.id) if results.size > 0
38
+    prev_path = favourited_by_api_v1_status_url(since_id: results.first.id) unless results.empty?
37 39
 
38 40
     set_pagination_headers(next_path, prev_path)
39 41
 

+ 6
- 4
app/controllers/api/v1/timelines_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Api::V1::TimelinesController < ApiController
2 4
   before_action -> { doorkeeper_authorize! :read }
3 5
   before_action :require_user!, only: [:home, :mentions]
@@ -10,7 +12,7 @@ class Api::V1::TimelinesController < ApiController
10 12
     set_maps(@statuses)
11 13
 
12 14
     next_path = api_v1_home_timeline_url(max_id: @statuses.last.id)    if @statuses.size == DEFAULT_STATUSES_LIMIT
13
-    prev_path = api_v1_home_timeline_url(since_id: @statuses.first.id) if @statuses.size > 0
15
+    prev_path = api_v1_home_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
14 16
 
15 17
     set_pagination_headers(next_path, prev_path)
16 18
 
@@ -23,7 +25,7 @@ class Api::V1::TimelinesController < ApiController
23 25
     set_maps(@statuses)
24 26
 
25 27
     next_path = api_v1_mentions_timeline_url(max_id: @statuses.last.id)    if @statuses.size == DEFAULT_STATUSES_LIMIT
26
-    prev_path = api_v1_mentions_timeline_url(since_id: @statuses.first.id) if @statuses.size > 0
28
+    prev_path = api_v1_mentions_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
27 29
 
28 30
     set_pagination_headers(next_path, prev_path)
29 31
 
@@ -36,7 +38,7 @@ class Api::V1::TimelinesController < ApiController
36 38
     set_maps(@statuses)
37 39
 
38 40
     next_path = api_v1_public_timeline_url(max_id: @statuses.last.id)    if @statuses.size == DEFAULT_STATUSES_LIMIT
39
-    prev_path = api_v1_public_timeline_url(since_id: @statuses.first.id) if @statuses.size > 0
41
+    prev_path = api_v1_public_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
40 42
 
41 43
     set_pagination_headers(next_path, prev_path)
42 44
 
@@ -50,7 +52,7 @@ class Api::V1::TimelinesController < ApiController
50 52
     set_maps(@statuses)
51 53
 
52 54
     next_path = api_v1_hashtag_timeline_url(params[:id], max_id: @statuses.last.id)    if @statuses.size == DEFAULT_STATUSES_LIMIT
53
-    prev_path = api_v1_hashtag_timeline_url(params[:id], since_id: @statuses.first.id) if @statuses.size > 0
55
+    prev_path = api_v1_hashtag_timeline_url(params[:id], since_id: @statuses.first.id) unless @statuses.empty?
54 56
 
55 57
     set_pagination_headers(next_path, prev_path)
56 58
 

+ 5
- 3
app/controllers/api_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class ApiController < ApplicationController
2 4
   DEFAULT_STATUSES_LIMIT = 20
3 5
   DEFAULT_ACCOUNTS_LIMIT = 40
@@ -51,8 +53,8 @@ class ApiController < ApplicationController
51 53
 
52 54
   def set_pagination_headers(next_path = nil, prev_path = nil)
53 55
     links = []
54
-    links << [next_path, [['rel', 'next']]] if next_path
55
-    links << [prev_path, [['rel', 'prev']]] if prev_path
56
+    links << [next_path, [%w(rel next)]] if next_path
57
+    links << [prev_path, [%w(rel prev)]] if prev_path
56 58
     response.headers['Link'] = LinkHeader.new(links)
57 59
   end
58 60
 
@@ -76,7 +78,7 @@ class ApiController < ApplicationController
76 78
     render json: {}, status: 200
77 79
   end
78 80
 
79
-  def set_maps(statuses)
81
+  def set_maps(statuses) # rubocop:disable Style/AccessorMethodName
80 82
     if current_account.nil?
81 83
       @reblogs_map    = {}
82 84
       @favourites_map = {}

+ 2
- 0
app/controllers/application_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class ApplicationController < ActionController::Base
2 4
   # Prevent CSRF attacks by raising an exception.
3 5
   # For APIs, you may want to use :null_session instead.

+ 2
- 0
app/controllers/auth/confirmations_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Auth::ConfirmationsController < Devise::ConfirmationsController
2 4
   layout 'auth'
3 5
 end

+ 2
- 0
app/controllers/auth/passwords_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Auth::PasswordsController < Devise::PasswordsController
2 4
   layout 'auth'
3 5
 end

+ 2
- 0
app/controllers/auth/registrations_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Auth::RegistrationsController < Devise::RegistrationsController
2 4
   layout 'auth'
3 5
 

+ 2
- 0
app/controllers/auth/sessions_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Auth::SessionsController < Devise::SessionsController
2 4
   include Devise::Controllers::Rememberable
3 5
 

+ 2
- 0
app/controllers/home_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class HomeController < ApplicationController
2 4
   before_action :authenticate_user!
3 5
 

+ 2
- 0
app/controllers/media_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class MediaController < ApplicationController
2 4
   before_action :set_media_attachment
3 5
 

+ 2
- 0
app/controllers/oauth/authorizations_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController
2 4
   skip_before_action :authenticate_resource_owner!
3 5
 

+ 2
- 0
app/controllers/settings/preferences_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Settings::PreferencesController < ApplicationController
2 4
   layout 'auth'
3 5
 

+ 2
- 0
app/controllers/settings/profiles_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Settings::ProfilesController < ApplicationController
2 4
   layout 'auth'
3 5
 

+ 3
- 3
app/controllers/stream_entries_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class StreamEntriesController < ApplicationController
2 4
   layout 'public'
3 5
 
@@ -29,9 +31,7 @@ class StreamEntriesController < ApplicationController
29 31
   end
30 32
 
31 33
   def set_link_headers
32
-    response.headers['Link'] = LinkHeader.new([
33
-      [account_stream_entry_url(@account, @stream_entry, format: 'atom'), [['rel', 'alternate'], ['type', 'application/atom+xml']]]
34
-    ])
34
+    response.headers['Link'] = LinkHeader.new([[account_stream_entry_url(@account, @stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]]])
35 35
   end
36 36
 
37 37
   def set_stream_entry

+ 2
- 0
app/controllers/tags_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class TagsController < ApplicationController
2 4
   layout 'public'
3 5
 

+ 6
- 4
app/controllers/xrd_controller.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class XrdController < ApplicationController
2 4
   before_action :set_default_format_json, only: :webfinger
3 5
   before_action :set_default_format_xml, only: :host_meta
@@ -26,11 +28,11 @@ class XrdController < ApplicationController
26 28
   private
27 29
 
28 30
   def set_default_format_xml
29
-    request.format = 'xml' if request.headers["HTTP_ACCEPT"].nil? && params[:format].nil?
31
+    request.format = 'xml' if request.headers['HTTP_ACCEPT'].nil? && params[:format].nil?
30 32
   end
31 33
 
32 34
   def set_default_format_json
33
-    request.format = 'json' if request.headers["HTTP_ACCEPT"].nil? && params[:format].nil?
35
+    request.format = 'json' if request.headers['HTTP_ACCEPT'].nil? && params[:format].nil?
34 36
   end
35 37
 
36 38
   def username_from_resource
@@ -44,14 +46,14 @@ class XrdController < ApplicationController
44 46
 
45 47
   def pem_to_magic_key(public_key)
46 48
     modulus, exponent = [public_key.n, public_key.e].map do |component|
47
-      result = ''
49
+      result = []
48 50
 
49 51
       until component.zero?
50 52
         result << [component % 256].pack('C')
51 53
         component >>= 8
52 54
       end
53 55
 
54
-      result.reverse!
56
+      result.reverse.join
55 57
     end
56 58
 
57 59
     (['RSA'] + [modulus, exponent].map { |n| Base64.urlsafe_encode64(n) }).join('.')

+ 2
- 0
app/helpers/about_helper.rb View File

@@ -1,2 +1,4 @@
1
+# frozen_string_literal: true
2
+
1 3
 module AboutHelper
2 4
 end

+ 5
- 3
app/helpers/accounts_helper.rb View File

@@ -1,10 +1,12 @@
1
+# frozen_string_literal: true
2
+
1 3
 module AccountsHelper
2 4
   def pagination_options
3 5
     {
4
-      previous_label: "#{fa_icon('chevron-left')} Prev".html_safe,
5
-      next_label: "Next #{fa_icon('chevron-right')}".html_safe,
6
+      previous_label: safe_join([fa_icon('chevron-left'), 'Prev'], ' '),
7
+      next_label: safe_join(['Next', fa_icon('chevron-right')], ' '),
6 8
       inner_window: 1,
7
-      outer_window: 0
9
+      outer_window: 0,
8 10
     }
9 11
   end
10 12
 end

+ 2
- 0
app/helpers/application_helper.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 module ApplicationHelper
2 4
   def active_nav_class(path)
3 5
     current_page?(path) ? 'active' : ''

+ 8
- 2
app/helpers/atom_builder_helper.rb View File

@@ -1,6 +1,12 @@
1
+# frozen_string_literal: true
2
+
1 3
 module AtomBuilderHelper
2 4
   def stream_updated_at
3
-    @account.stream_entries.last ? (@account.updated_at > @account.stream_entries.last.created_at ? @account.updated_at : @account.stream_entries.last.created_at) : @account.updated_at
5
+    if @account.stream_entries.last
6
+      (@account.updated_at > @account.stream_entries.last.created_at ? @account.updated_at : @account.stream_entries.last.created_at)
7
+    else
8
+      @account.updated_at
9
+    end
4 10
   end
5 11
 
6 12
   def entry(xml, is_root = false, &block)
@@ -98,7 +104,7 @@ module AtomBuilderHelper
98 104
   end
99 105
 
100 106
   def in_reply_to(xml, uri, url)
101
-    xml['thr'].send('in-reply-to', { ref: uri, href: url, type: 'text/html' })
107
+    xml['thr'].send('in-reply-to', ref: uri, href: url, type: 'text/html')
102 108
   end
103 109
 
104 110
   def link_mention(xml, account)

+ 3
- 1
app/helpers/home_helper.rb View File

@@ -1,8 +1,10 @@
1
+# frozen_string_literal: true
2
+
1 3
 module HomeHelper
2 4
   def default_props
3 5
     {
4 6
       token: @token,
5
-      account: render(file: 'api/v1/accounts/show', locals: { account: current_user.account }, formats: :json)
7
+      account: render(file: 'api/v1/accounts/show', locals: { account: current_user.account }, formats: :json),
6 8
     }
7 9
   end
8 10
 end

+ 2
- 0
app/helpers/routing_helper.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 module RoutingHelper
2 4
   extend ActiveSupport::Concern
3 5
   include Rails.application.routes.url_helpers

+ 2
- 0
app/helpers/stream_entries_helper.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 module StreamEntriesHelper
2 4
   def display_name(account)
3 5
     account.display_name.blank? ? account.username : account.display_name

+ 2
- 0
app/helpers/tags_helper.rb View File

@@ -1,2 +1,4 @@
1
+# frozen_string_literal: true
2
+
1 3
 module TagsHelper
2 4
 end

+ 2
- 0
app/helpers/xrd_helper.rb View File

@@ -1,2 +1,4 @@
1
+# frozen_string_literal: true
2
+
1 3
 module XrdHelper
2 4
 end

+ 15
- 13
app/lib/feed_manager.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 require 'singleton'
2 4
 
3 5
 class FeedManager
@@ -60,29 +62,29 @@ class FeedManager
60 62
   private
61 63
 
62 64
   def redis
63
-    $redis
65
+    Redis.current
64 66
   end
65 67
 
66 68
   def filter_from_home?(status, receiver)
67 69
     should_filter = false
68 70
 
69
-    if status.reply? && !status.thread.account.nil?                                     # Filter out if it's a reply
70
-      should_filter = !receiver.following?(status.thread.account)                       # and I'm not following the person it's a reply to
71
-      should_filter = should_filter && !(receiver.id == status.thread.account_id)       # and it's not a reply to me
72
-      should_filter = should_filter && !(status.account_id == status.thread.account_id) # and it's not a self-reply
73
-    elsif status.reblog?                                                                # Filter out a reblog
74
-      should_filter = receiver.blocking?(status.reblog.account)                         # if I'm blocking the reblogged person
71
+    if status.reply? && !status.thread.account.nil?                      # Filter out if it's a reply
72
+      should_filter   = !receiver.following?(status.thread.account)      # and I'm not following the person it's a reply to
73
+      should_filter &&= !(receiver.id == status.thread.account_id)       # and it's not a reply to me
74
+      should_filter &&= !(status.account_id == status.thread.account_id) # and it's not a self-reply
75
+    elsif status.reblog?                                                 # Filter out a reblog
76
+      should_filter = receiver.blocking?(status.reblog.account)          # if I'm blocking the reblogged person
75 77
     end
76 78
 
77 79
     should_filter
78 80
   end
79 81
 
80 82
   def filter_from_mentions?(status, receiver)
81
-    should_filter = receiver.id == status.account_id                             # Filter if I'm mentioning myself
82
-    should_filter = should_filter || receiver.blocking?(status.account)          # or it's from someone I blocked
83
+    should_filter   = receiver.id == status.account_id            # Filter if I'm mentioning myself
84
+    should_filter ||= receiver.blocking?(status.account)          # or it's from someone I blocked
83 85
 
84
-    if status.reply? && !status.thread.account.nil?                              # or it's a reply
85
-      should_filter = should_filter || receiver.blocking?(status.thread.account) # to a user I blocked
86
+    if status.reply? && !status.thread.account.nil?               # or it's a reply
87
+      should_filter ||= receiver.blocking?(status.thread.account) # to a user I blocked
86 88
     end
87 89
 
88 90
     should_filter
@@ -92,9 +94,9 @@ class FeedManager
92 94
     should_filter = receiver.blocking?(status.account)
93 95
 
94 96
     if status.reply? && !status.thread.account.nil?
95
-      should_filter = should_filter || receiver.blocking?(status.thread.account)
97
+      should_filter ||= receiver.blocking?(status.thread.account)
96 98
     elsif status.reblog?
97
-      should_filter = should_filter || receiver.blocking?(status.reblog.account)
99
+      should_filter ||= receiver.blocking?(status.reblog.account)
98 100
     end
99 101
 
100 102
     should_filter

+ 4
- 2
app/lib/formatter.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 require 'singleton'
2 4
 
3 5
 class Formatter
@@ -17,7 +19,7 @@ class Formatter
17 19
     html = link_mentions(html, status.mentions)
18 20
     html = link_hashtags(html)
19 21
 
20
-    html.html_safe
22
+    html.html_safe # rubocop:disable Rails/OutputSafety
21 23
   end
22 24
 
23 25
   def reformat(html)
@@ -30,7 +32,7 @@ class Formatter
30 32
     html = encode(account.note)
31 33
     html = link_urls(html)
32 34
 
33
-    html.html_safe
35
+    html.html_safe # rubocop:disable Rails/OutputSafety
34 36
   end
35 37
 
36 38
   private

+ 3
- 1
app/lib/tag_manager.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 require 'singleton'
2 4
 
3 5
 class TagManager
@@ -18,7 +20,7 @@ class TagManager
18 20
   end
19 21
 
20 22
   def local_domain?(domain)
21
-    domain.nil? || domain.gsub(/[\/]/, '').downcase == Rails.configuration.x.local_domain.downcase
23
+    domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.local_domain).zero?
22 24
   end
23 25
 
24 26
   def uri_for(target)

+ 2
- 0
app/mailers/application_mailer.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class ApplicationMailer < ActionMailer::Base
2 4
   default from: (ENV['SMTP_FROM_ADDRESS'] || 'notifications@localhost')
3 5
   layout 'mailer'

+ 2
- 0
app/mailers/notification_mailer.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class NotificationMailer < ApplicationMailer
2 4
   helper StreamEntriesHelper
3 5
 

+ 6
- 4
app/models/account.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Account < ApplicationRecord
2 4
   include Targetable
3 5
   include PgSearch
@@ -92,11 +94,11 @@ class Account < ApplicationRecord
92 94
   end
93 95
 
94 96
   def favourited?(status)
95
-    (status.reblog? ? status.reblog : status).favourites.where(account: self).count > 0
97
+    (status.reblog? ? status.reblog : status).favourites.where(account: self).count.positive?
96 98
   end
97 99
 
98 100
   def reblogged?(status)
99
-    (status.reblog? ? status.reblog : status).reblogs.where(account: self).count > 0
101
+    (status.reblog? ? status.reblog : status).reblogs.where(account: self).count.positive?
100 102
   end
101 103
 
102 104
   def keypair
@@ -115,8 +117,8 @@ class Account < ApplicationRecord
115 117
   def avatar_remote_url=(url)
116 118
     self.avatar = URI.parse(url) unless self[:avatar_remote_url] == url
117 119
     self[:avatar_remote_url] = url
118
-  rescue OpenURI::HTTPError
119
-    #
120
+  rescue OpenURI::HTTPError => e
121
+    Rails.logger.debug "Error fetching remote avatar: #{e}"
120 122
   end
121 123
 
122 124
   def object_type

+ 2
- 0
app/models/application_record.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class ApplicationRecord < ActiveRecord::Base
2 4
   self.abstract_class = true
3 5
 end

+ 2
- 0
app/models/block.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Block < ApplicationRecord
2 4
   belongs_to :account
3 5
   belongs_to :target_account, class_name: 'Account'

+ 2
- 0
app/models/concerns/paginable.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 module Paginable
2 4
   extend ActiveSupport::Concern
3 5
 

+ 2
- 0
app/models/concerns/streamable.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 module Streamable
2 4
   extend ActiveSupport::Concern
3 5
 

+ 2
- 0
app/models/concerns/targetable.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 module Targetable
2 4
   extend ActiveSupport::Concern
3 5
 

+ 2
- 0
app/models/domain_block.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class DomainBlock < ApplicationRecord
2 4
   validates :domain, presence: true, uniqueness: true
3 5
 

+ 2
- 0
app/models/favourite.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Favourite < ApplicationRecord
2 4
   include Paginable
3 5
   include Streamable

+ 3
- 1
app/models/feed.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Feed
2 4
   def initialize(type, account)
3 5
     @type    = type
@@ -28,6 +30,6 @@ class Feed
28 30
   end
29 31
 
30 32
   def redis
31
-    $redis
33
+    Redis.current
32 34
   end
33 35
 end

+ 2
- 0
app/models/follow.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Follow < ApplicationRecord
2 4
   include Paginable
3 5
   include Streamable

+ 2
- 0
app/models/follow_suggestion.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class FollowSuggestion
2 4
   class << self
3 5
     def get(for_account_id, limit = 10)

+ 12
- 10
app/models/media_attachment.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class MediaAttachment < ApplicationRecord
2 4
   IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'].freeze
3 5
   VIDEO_MIME_TYPES = ['video/webm', 'video/mp4'].freeze
@@ -6,9 +8,9 @@ class MediaAttachment < ApplicationRecord
6 8
   belongs_to :status,  inverse_of: :media_attachments
7 9
 
8 10
   has_attached_file :file,
9
-    styles: -> (f) { file_styles f },
10
-    processors: -> (f) { f.video? ? [:transcoder] : [:thumbnail] },
11
-    convert_options: { all: "-strip" }
11
+                    styles: -> (f) { file_styles f },
12
+                    processors: -> (f) { f.video? ? [:transcoder] : [:thumbnail] },
13
+                    convert_options: { all: '-strip' }
12 14
   validates_attachment_content_type :file, content_type: IMAGE_MIME_TYPES + VIDEO_MIME_TYPES
13 15
   validates_attachment_size :file, less_than: 4.megabytes
14 16
 
@@ -20,8 +22,8 @@ class MediaAttachment < ApplicationRecord
20 22
 
21 23
   def file_remote_url=(url)
22 24
     self.file = URI.parse(url)
23
-  rescue OpenURI::HTTPError
24
-    #
25
+  rescue OpenURI::HTTPError => e
26
+    Rails.logger.debug "Error fetching remote attachment: #{e}"
25 27
   end
26 28
 
27 29
   def image?
@@ -43,19 +45,19 @@ class MediaAttachment < ApplicationRecord
43 45
       if f.instance.image?
44 46
         {
45 47
           original: '100%',
46
-          small: '510x680>'
48
+          small: '510x680>',
47 49
         }
48 50
       else
49 51
         {
50 52
           small: {
51 53
             convert_options: {
52 54
               output: {
53
-                vf: 'scale=\'min(510\, iw):min(680\, ih)\':force_original_aspect_ratio=decrease'
54
-              }
55
+                vf: 'scale=\'min(510\, iw):min(680\, ih)\':force_original_aspect_ratio=decrease',
56
+              },
55 57
             },
56 58
             format: 'png',
57
-            time: 1
58
-          }
59
+            time: 1,
60
+          },
59 61
         }
60 62
       end
61 63
     end

+ 2
- 0
app/models/mention.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Mention < ApplicationRecord
2 4
   belongs_to :account, inverse_of: :mentions
3 5
   belongs_to :status

+ 6
- 9
app/models/status.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Status < ApplicationRecord
2 4
   include Paginable
3 5
   include Streamable
@@ -89,22 +91,17 @@ class Status < ApplicationRecord
89 91
 
90 92
     def as_public_timeline(account = nil)
91 93
       query = joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id').where('accounts.silenced = FALSE')
92
-
93
-      unless account.nil?
94
-        query = filter_timeline(query, account)
95
-      end
94
+      query = filter_timeline(query, account) unless account.nil?
96 95
 
97 96
       query.with_includes.with_counters
98 97
     end
99 98
 
100 99
     def as_tag_timeline(tag, account = nil)
101 100
       query = tag.statuses
102
-        .joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id')
103
-        .where('accounts.silenced = FALSE')
101
+                 .joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id')
102
+                 .where('accounts.silenced = FALSE')
104 103
 
105
-      unless account.nil?
106
-        query = filter_timeline(query, account)
107
-      end
104
+      query = filter_timeline(query, account) unless account.nil?
108 105
 
109 106
       query.with_includes.with_counters
110 107
     end

+ 7
- 1
app/models/stream_entry.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class StreamEntry < ApplicationRecord
2 4
   include Paginable
3 5
 
@@ -15,7 +17,11 @@ class StreamEntry < ApplicationRecord
15 17
   scope :with_includes, -> { includes(:account, status: STATUS_INCLUDES, favourite: [:account, :stream_entry, status: STATUS_INCLUDES], follow: [:target_account, :stream_entry]) }
16 18
 
17 19
   def object_type
18
-    orphaned? ? :activity : (targeted? ? :activity : activity.object_type)
20
+    if orphaned?
21
+      :activity
22
+    else
23
+      targeted? ? :activity : activity.object_type
24
+    end
19 25
   end
20 26
 
21 27
   def verb

+ 2
- 0
app/models/tag.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class Tag < ApplicationRecord
2 4
   has_and_belongs_to_many :statuses
3 5
 

+ 2
- 0
app/models/user.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class User < ApplicationRecord
2 4
   devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable
3 5
 

+ 2
- 0
app/services/base_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class BaseService
2 4
   include ActionView::Helpers::TextHelper
3 5
   include ActionView::Helpers::SanitizeHelper

+ 2
- 0
app/services/block_domain_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class BlockDomainService < BaseService
2 4
   def call(domain)
3 5
     DomainBlock.find_or_create_by!(domain: domain)

+ 3
- 1
app/services/block_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class BlockService < BaseService
2 4
   def call(account, target_account)
3 5
     return if account.id == target_account.id
@@ -20,6 +22,6 @@ class BlockService < BaseService
20 22
   end
21 23
 
22 24
   def redis
23
-    $redis
25
+    Redis.current
24 26
   end
25 27
 end

+ 2
- 0
app/services/fan_out_on_write_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class FanOutOnWriteService < BaseService
2 4
   # Push a status into home and mentions feeds
3 5
   # @param [Status] status

+ 2
- 0
app/services/favourite_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class FavouriteService < BaseService
2 4
   # Favourite a status and notify remote user
3 5
   # @param [Account] account

+ 8
- 12
app/services/fetch_atom_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class FetchAtomService < BaseService
2 4
   def call(url)
3 5
     response = http_client.head(url)
@@ -9,15 +11,9 @@ class FetchAtomService < BaseService
9 11
     Rails.logger.debug "Remote status GET request returned code #{response.code}"
10 12
 
11 13
     return nil if response.code != 200
12
-
13
-    if response.mime_type == 'application/atom+xml'
14
-      return [url, fetch(url)]
15
-    elsif !response['Link'].blank?
16
-      return process_headers(url, response)
17
-    else
18
-      return process_html(fetch(url))
19
-    end
20
-
14
+    return [url, fetch(url)] if response.mime_type == 'application/atom+xml'
15
+    return process_headers(url, response) unless response['Link'].blank?
16
+    process_html(fetch(url))
21 17
   rescue OpenSSL::SSL::SSLError => e
22 18
     Rails.logger.debug "SSL error: #{e}"
23 19
   end
@@ -31,17 +27,17 @@ class FetchAtomService < BaseService
31 27
     alternate_link = page.xpath('//link[@rel="alternate"]').find { |link| link['type'] == 'application/atom+xml' }
32 28
 
33 29
     return nil if alternate_link.nil?
34
-    return [alternate_link['href'], fetch(alternate_link['href'])]
30
+    [alternate_link['href'], fetch(alternate_link['href'])]
35 31
   end
36 32
 
37 33
   def process_headers(url, response)
38 34
     Rails.logger.debug 'Processing link header'
39 35
 
40 36
     link_header    = LinkHeader.parse(response['Link'].is_a?(Array) ? response['Link'].first : response['Link'])
41
-    alternate_link = link_header.find_link(['rel', 'alternate'], ['type', 'application/atom+xml'])
37
+    alternate_link = link_header.find_link(%w(rel alternate), %w(type application/atom+xml))
42 38
 
43 39
     return process_html(fetch(url)) if alternate_link.nil?
44
-    return [alternate_link.href, fetch(alternate_link.href)]
40
+    [alternate_link.href, fetch(alternate_link.href)]
45 41
   end
46 42
 
47 43
   def fetch(url)

+ 4
- 2
app/services/fetch_remote_account_service.rb View File

@@ -1,9 +1,11 @@
1
+# frozen_string_literal: true
2
+
1 3
 class FetchRemoteAccountService < BaseService
2 4
   def call(url)
3 5
     atom_url, body = FetchAtomService.new.call(url)
4 6
 
5 7
     return nil if atom_url.nil?
6
-    return process_atom(atom_url, body)
8
+    process_atom(atom_url, body)
7 9
   end
8 10
 
9 11
   private
@@ -25,7 +27,7 @@ class FetchRemoteAccountService < BaseService
25 27
     Rails.logger.debug "Unparseable URL given: #{url}"
26 28
     nil
27 29
   rescue Nokogiri::XML::XPath::SyntaxError
28
-    Rails.logger.debug "Invalid XML or missing namespace"
30
+    Rails.logger.debug 'Invalid XML or missing namespace'
29 31
     nil
30 32
   end
31 33
 end

+ 5
- 3
app/services/fetch_remote_status_service.rb View File

@@ -1,9 +1,11 @@
1
+# frozen_string_literal: true
2
+
1 3
 class FetchRemoteStatusService < BaseService
2 4
   def call(url)
3 5
     atom_url, body = FetchAtomService.new.call(url)
4 6
 
5 7
     return nil if atom_url.nil?
6
-    return process_atom(atom_url, body)
8
+    process_atom(atom_url, body)
7 9
   end
8 10
 
9 11
   private
@@ -20,7 +22,7 @@ class FetchRemoteStatusService < BaseService
20 22
 
21 23
     statuses = ProcessFeedService.new.call(body, account)
22 24
 
23
-    return statuses.first
25
+    statuses.first
24 26
   end
25 27
 
26 28
   def extract_author(url, xml)
@@ -34,7 +36,7 @@ class FetchRemoteStatusService < BaseService
34 36
 
35 37
     return FollowRemoteAccountService.new.call("#{username}@#{domain}")
36 38
   rescue Nokogiri::XML::XPath::SyntaxError
37
-    Rails.logger.debug "Invalid XML or missing namespace"
39
+    Rails.logger.debug 'Invalid XML or missing namespace'
38 40
     nil
39 41
   end
40 42
 end

+ 4
- 2
app/services/follow_remote_account_service.rb View File

@@ -1,7 +1,9 @@
1
+# frozen_string_literal: true
2
+
1 3
 class FollowRemoteAccountService < BaseService
2 4
   include OStatus2::MagicKey
3 5
 
4
-  DFRN_NS = 'http://purl.org/macgirvin/dfrn/1.0'.freeze
6
+  DFRN_NS = 'http://purl.org/macgirvin/dfrn/1.0'
5 7
 
6 8
   # Find or create a local account for a remote user.
7 9
   # When creating, look up the user's webfinger and fetch all
@@ -49,7 +51,7 @@ class FollowRemoteAccountService < BaseService
49 51
     get_profile(xml, account)
50 52
     account.save!
51 53
 
52
-    return account
54
+    account
53 55
   end
54 56
 
55 57
   private

+ 3
- 1
app/services/follow_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class FollowService < BaseService
2 4
   # Follow a remote user, notify remote user about the follow
3 5
   # @param [Account] source_account From which to follow
@@ -35,7 +37,7 @@ class FollowService < BaseService
35 37
   end
36 38
 
37 39
   def redis
38
-    $redis
40
+    Redis.current
39 41
   end
40 42
 
41 43
   def follow_remote_account_service

+ 2
- 0
app/services/post_status_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class PostStatusService < BaseService
2 4
   # Post a text status update, fetch and notify remote users mentioned
3 5
   # @param [Account] account Account from which to post

+ 3
- 3
app/services/precompute_feed_service.rb View File

@@ -1,10 +1,10 @@
1
+# frozen_string_literal: true
2
+
1 3
 class PrecomputeFeedService < BaseService
2 4
   # Fill up a user's home/mentions feed from DB and return a subset
3 5
   # @param [Symbol] type :home or :mentions
4 6
   # @param [Account] account
5 7
   def call(type, account)
6
-    instant_return = []
7
-
8 8
     Status.send("as_#{type}_timeline", account).limit(FeedManager::MAX_ITEMS).each do |status|
9 9
       next if FeedManager.instance.filter?(type, status, account)
10 10
       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
14 14
   private
15 15
 
16 16
   def redis
17
-    $redis
17
+    Redis.current
18 18
   end
19 19
 end

+ 7
- 5
app/services/process_feed_service.rb View File

@@ -1,6 +1,8 @@
1
+# frozen_string_literal: true
2
+
1 3
 class ProcessFeedService < BaseService
2
-  ACTIVITY_NS = 'http://activitystrea.ms/spec/1.0/'.freeze
3
-  THREAD_NS   = 'http://purl.org/syndication/thread/1.0'.freeze
4
+  ACTIVITY_NS = 'http://activitystrea.ms/spec/1.0/'
5
+  THREAD_NS   = 'http://purl.org/syndication/thread/1.0'
4 6
 
5 7
   def call(body, account)
6 8
     xml = Nokogiri::XML(body)
@@ -89,13 +91,13 @@ class ProcessFeedService < BaseService
89 91
         account = @account
90 92
       end
91 93
 
92
-      status = Status.create!({
94
+      status = Status.create!(
93 95
         uri: id(entry),
94 96
         url: url(entry),
95 97
         account: account,
96 98
         text: content(entry),
97
-        created_at: published(entry),
98
-      })
99
+        created_at: published(entry)
100
+      )
99 101
 
100 102
       if thread?(entry)
101 103
         Rails.logger.debug "Trying to attach #{status.id} (#{id(entry)}) to #{thread(entry).first}"

+ 3
- 3
app/services/process_hashtags_service.rb View File

@@ -1,8 +1,8 @@
1
+# frozen_string_literal: true
2
+
1 3
 class ProcessHashtagsService < BaseService
2 4
   def call(status, tags = [])
3
-    if status.local?
4
-      tags = status.text.scan(Tag::HASHTAG_RE).map(&:first)
5
-    end
5
+    tags = status.text.scan(Tag::HASHTAG_RE).map(&:first) if status.local?
6 6
 
7 7
     tags.map(&:downcase).uniq.each do |tag|
8 8
       status.tags << Tag.where(name: tag).first_or_initialize(name: tag)

+ 4
- 4
app/services/process_interaction_service.rb View File

@@ -1,5 +1,7 @@
1
+# frozen_string_literal: true
2
+
1 3
 class ProcessInteractionService < BaseService
2
-  ACTIVITY_NS = 'http://activitystrea.ms/spec/1.0/'.freeze
4
+  ACTIVITY_NS = 'http://activitystrea.ms/spec/1.0/'
3 5
 
4 6
   # Record locally the remote interaction with our user
5 7
   # @param [String] envelope Salmon envelope
@@ -76,9 +78,7 @@ class ProcessInteractionService < BaseService
76 78
 
77 79
     return if status.nil?
78 80
 
79
-    if account.id == status.account_id
80
-      remove_status_service.call(status)
81
-    end
81
+    remove_status_service.call(status) if account.id == status.account_id
82 82
   end
83 83
 
84 84
   def favourite!(xml, from_account)

+ 2
- 0
app/services/process_mentions_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class ProcessMentionsService < BaseService
2 4
   # Scan status for mentions and fetch remote mentioned users, create
3 5
   # local mention pointers, send Salmon notifications to mentioned

+ 2
- 0
app/services/reblog_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class ReblogService < BaseService
2 4
   # Reblog a status and notify its remote author
3 5
   # @param [Account] account Account to reblog from

+ 3
- 1
app/services/remove_status_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class RemoveStatusService < BaseService
2 4
   def call(status)
3 5
     remove_from_self(status) if status.account.local?
@@ -62,6 +64,6 @@ class RemoveStatusService < BaseService
62 64
   end
63 65
 
64 66
   def redis
65
-    $redis
67
+    Redis.current
66 68
   end
67 69
 end

+ 6
- 4
app/services/search_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class SearchService < BaseService
2 4
   def call(query, limit, resolve = false)
3 5
     return if query.blank?
@@ -5,10 +7,10 @@ class SearchService < BaseService
5 7
     username, domain = query.split('@')
6 8
 
7 9
     results = if domain.nil?
8
-      Account.search_for(username)
9
-    else
10
-      Account.search_for("#{username} #{domain}")
11
-    end
10
+                Account.search_for(username)
11
+              else
12
+                Account.search_for("#{username} #{domain}")
13
+              end
12 14
 
13 15
     results = results.limit(limit).with_counters
14 16
 

+ 2
- 0
app/services/send_interaction_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class SendInteractionService < BaseService
2 4
   # Send an Atom representation of an interaction to a remote Salmon endpoint
3 5
   # @param [StreamEntry] stream_entry

+ 2
- 0
app/services/subscribe_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class SubscribeService < BaseService
2 4
   def call(account)
3 5
     account.secret = SecureRandom.hex

+ 2
- 0
app/services/unblock_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class UnblockService < BaseService
2 4
   def call(account, target_account)
3 5
     account.unblock!(target_account) if account.blocking?(target_account)

+ 2
- 0
app/services/unfavourite_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class UnfavouriteService < BaseService
2 4
   def call(account, status)
3 5
     favourite = Favourite.find_by!(account: account, status: status)

+ 3
- 1
app/services/unfollow_service.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class UnfollowService < BaseService
2 4
   # Unfollow and notify the remote user
3 5
   # @param [Account] source_account Where to unfollow from
@@ -21,6 +23,6 @@ class UnfollowService < BaseService
21 23
   end
22 24
 
23 25
   def redis
24
-    $redis
26
+    Redis.current
25 27
   end
26 28
 end

+ 7
- 5
app/services/update_remote_profile_service.rb View File

@@ -1,14 +1,16 @@
1
+# frozen_string_literal: true
2
+
1 3
 class UpdateRemoteProfileService < BaseService
2 4
   POCO_NS = 'http://portablecontacts.net/spec/1.0'
3 5
 
4 6
   def call(author_xml, account)
5 7
     return if author_xml.nil?
6 8
 
7
-    if author_xml.at_xpath('./poco:displayName', poco: POCO_NS).nil?
8
-      account.display_name = account.username
9
-    else
10
-      account.display_name = author_xml.at_xpath('./poco:displayName', poco: POCO_NS).content
11
-    end
9
+    account.display_name = if author_xml.at_xpath('./poco:displayName', poco: POCO_NS).nil?
10
+                             account.username
11
+                           else
12
+                             author_xml.at_xpath('./poco:displayName', poco: POCO_NS).content
13
+                           end
12 14
 
13 15
     unless author_xml.at_xpath('./poco:note').nil?
14 16
       account.note = author_xml.at_xpath('./poco:note', poco: POCO_NS).content

+ 2
- 0
app/workers/distribution_worker.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class DistributionWorker
2 4
   include Sidekiq::Worker
3 5
 

+ 2
- 0
app/workers/hub_ping_worker.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class HubPingWorker
2 4
   include Sidekiq::Worker
3 5
   include RoutingHelper

+ 2
- 0
app/workers/notification_worker.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class NotificationWorker
2 4
   include Sidekiq::Worker
3 5
 

+ 2
- 0
app/workers/processing_worker.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class ProcessingWorker
2 4
   include Sidekiq::Worker
3 5
 

+ 2
- 0
app/workers/regeneration_worker.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class RegenerationWorker
2 4
   include Sidekiq::Worker
3 5
 

+ 2
- 0
app/workers/thread_resolve_worker.rb View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 class ThreadResolveWorker
2 4
   include Sidekiq::Worker
3 5
 

+ 1
- 0
config.ru View File

@@ -1,3 +1,4 @@
1
+# frozen_string_literal: true
1 2
 # This file is used by Rack-based servers to start the application.
2 3
 
3 4
 require ::File.expand_path('../config/environment', __FILE__)

+ 4
- 2
config/initializers/redis.rb View File

@@ -1,5 +1,7 @@
1
-$redis = Redis.new({
1
+# frozen_string_literal: true
2
+
3
+Redis.current = Redis.new(
2 4
   host: ENV.fetch('REDIS_HOST') { 'localhost' },
3 5
   port: ENV.fetch('REDIS_PORT') { 6379 },
4 6
   driver: :hiredis
5
-})
7
+)

+ 4
- 2
lib/tasks/mastodon.rake View File

@@ -1,3 +1,5 @@
1
+# frozen_string_literal: true
2
+
1 3
 namespace :mastodon do
2 4
   namespace :media do
3 5
     desc 'Removes media attachments that have not been assigned to any status for longer than a day'
@@ -28,7 +30,7 @@ namespace :mastodon do
28 30
     task refresh: :environment do
29 31
       Account.expiring(1.day.from_now).find_each do |a|
30 32
         Rails.logger.debug "PuSH re-subscribing to #{a.acct}"
31
-        SubscribeService.new.(a)
33
+        SubscribeService.new.call(a)
32 34
       end
33 35
     end
34 36
   end
@@ -36,7 +38,7 @@ namespace :mastodon do
36 38
   namespace :feeds do
37 39
     desc 'Clears all timelines so that they would be regenerated on next hit'
38 40
     task clear: :environment do
39
-      $redis.keys('feed:*').each { |key| $redis.del(key) }
41
+      Redis.current.keys('feed:*').each { |key| Redis.current.del(key) }
40 42
     end
41 43
   end
42 44