From e2a3ebb271017d800a448ad3ef3e8324ac1fab3b Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Sat, 18 Feb 2023 06:37:47 -0500 Subject: Autofix Rubocop Style/IfUnlessModifier (#23697) --- app/models/concerns/account_interactions.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'app/models/concerns/account_interactions.rb') diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb index de8bf338f..325619774 100644 --- a/app/models/concerns/account_interactions.rb +++ b/app/models/concerns/account_interactions.rb @@ -151,9 +151,7 @@ module AccountInteractions remove_potential_friendship(other_account) # When toggling a mute between hiding and allowing notifications, the mute will already exist, so the find_or_create_by! call will return the existing Mute without updating the hide_notifications attribute. Therefore, we check that hide_notifications? is what we want and set it if it isn't. - if mute.hide_notifications? != notifications - mute.update!(hide_notifications: notifications) - end + mute.update!(hide_notifications: notifications) if mute.hide_notifications? != notifications mute end -- cgit From d2dcb6c45a9db5439772f0553046e2c03a739a16 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Mon, 20 Feb 2023 00:51:43 -0500 Subject: Autofix Rubocop Style/UnpackFirst (#23741) --- .rubocop_todo.yml | 7 ------- app/models/concerns/account_interactions.rb | 4 ++-- lib/paperclip/gif_transcoder.rb | 4 ++-- 3 files changed, 4 insertions(+), 11 deletions(-) (limited to 'app/models/concerns/account_interactions.rb') diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 86a48a170..0f98d25d6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -2617,10 +2617,3 @@ Style/SymbolArray: Style/SymbolProc: Exclude: - 'spec/lib/request_spec.rb' - -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -Style/UnpackFirst: - Exclude: - - 'app/models/concerns/account_interactions.rb' - - 'lib/paperclip/gif_transcoder.rb' diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb index 325619774..1898516b0 100644 --- a/app/models/concerns/account_interactions.rb +++ b/app/models/concerns/account_interactions.rb @@ -278,7 +278,7 @@ module AccountInteractions followers.where(Account.arel_table[:uri].matches("#{Account.sanitize_sql_like(url_prefix)}/%", false, true)).or(followers.where(uri: url_prefix)).pluck_each(:uri) do |uri| Xorcist.xor!(digest, Digest::SHA256.digest(uri)) end - digest.unpack('H*')[0] + digest.unpack1('H*') end end @@ -288,7 +288,7 @@ module AccountInteractions followers.where(domain: nil).pluck_each(:username) do |username| Xorcist.xor!(digest, Digest::SHA256.digest(ActivityPub::TagManager.instance.uri_for_username(username))) end - digest.unpack('H*')[0] + digest.unpack1('H*') end end diff --git a/lib/paperclip/gif_transcoder.rb b/lib/paperclip/gif_transcoder.rb index d14465c01..f385b00a3 100644 --- a/lib/paperclip/gif_transcoder.rb +++ b/lib/paperclip/gif_transcoder.rb @@ -57,7 +57,7 @@ class GifReader end # Skip lzw min code size - raise InvalidValue unless s.read(1).unpack('C')[0] >= 2 + raise InvalidValue unless s.read(1).unpack1('C') >= 2 # Skip image data sub-blocks skip_sub_blocks!(s) @@ -77,7 +77,7 @@ class GifReader private def skip_extension_block!(file) - if EXTENSION_LABELS.include?(file.read(1).unpack('C')[0]) + if EXTENSION_LABELS.include?(file.read(1).unpack1('C')) block_size, = file.read(1).unpack('C') file.seek(block_size, IO::SEEK_CUR) end -- cgit From 38c84f57b6d2de1683974f91d726c30ba7f1491b Mon Sep 17 00:00:00 2001 From: Takeshi Umeda Date: Tue, 21 Mar 2023 18:32:58 +0900 Subject: Refactoring relations_map (#24195) --- app/models/concerns/account_interactions.rb | 15 +++++++++++++++ app/models/concerns/status_threading_concern.rb | 14 +------------- app/services/import_service.rb | 12 +----------- app/services/search_service.rb | 12 +----------- 4 files changed, 18 insertions(+), 35 deletions(-) (limited to 'app/models/concerns/account_interactions.rb') diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb index 1898516b0..48ab1349d 100644 --- a/app/models/concerns/account_interactions.rb +++ b/app/models/concerns/account_interactions.rb @@ -292,6 +292,21 @@ module AccountInteractions end end + def relations_map(account_ids, domains = nil, **options) + relations = { + blocked_by: Account.blocked_by_map(account_ids, id), + following: Account.following_map(account_ids, id), + } + + return relations if options[:skip_blocking_and_muting] + + relations.merge!({ + blocking: Account.blocking_map(account_ids, id), + muting: Account.muting_map(account_ids, id), + domain_blocking_by_domain: Account.domain_blocking_map_by_domain(domains, id), + }) + end + private def remove_potential_friendship(other_account) diff --git a/app/models/concerns/status_threading_concern.rb b/app/models/concerns/status_threading_concern.rb index 8b628beea..2ca3b66c2 100644 --- a/app/models/concerns/status_threading_concern.rb +++ b/app/models/concerns/status_threading_concern.rb @@ -79,7 +79,7 @@ module StatusThreadingConcern statuses = Status.with_accounts(ids).to_a account_ids = statuses.map(&:account_id).uniq domains = statuses.filter_map(&:account_domain).uniq - relations = relations_map_for_account(account, account_ids, domains) + relations = account&.relations_map(account_ids, domains) || {} statuses.reject! { |status| StatusFilter.new(status, account, relations).filtered? } @@ -108,16 +108,4 @@ module StatusThreadingConcern arr end - - def relations_map_for_account(account, account_ids, domains) - return {} if account.nil? - - { - blocking: Account.blocking_map(account_ids, account.id), - blocked_by: Account.blocked_by_map(account_ids, account.id), - muting: Account.muting_map(account_ids, account.id), - following: Account.following_map(account_ids, account.id), - domain_blocking_by_domain: Account.domain_blocking_map_by_domain(domains, account.id), - } - end end diff --git a/app/services/import_service.rb b/app/services/import_service.rb index 940c236d4..56f191c1f 100644 --- a/app/services/import_service.rb +++ b/app/services/import_service.rb @@ -120,7 +120,7 @@ class ImportService < BaseService end account_ids = statuses.map(&:account_id) - preloaded_relations = relations_map_for_account(@account, account_ids) + preloaded_relations = @account.relations_map(account_ids, skip_blocking_and_muting: true) statuses.keep_if { |status| StatusPolicy.new(@account, status, preloaded_relations).show? } @@ -138,14 +138,4 @@ class ImportService < BaseService def import_data Paperclip.io_adapters.for(@import.data).read.force_encoding(Encoding::UTF_8) end - - def relations_map_for_account(account, account_ids) - { - blocking: {}, - blocked_by: Account.blocked_by_map(account_ids, account.id), - muting: {}, - following: Account.following_map(account_ids, account.id), - domain_blocking_by_domain: {}, - } - end end diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 93b72fa0c..b1ce5453f 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -49,7 +49,7 @@ class SearchService < BaseService results = definition.limit(@limit).offset(@offset).objects.compact account_ids = results.map(&:account_id) account_domains = results.map(&:account_domain) - preloaded_relations = relations_map_for_account(@account, account_ids, account_domains) + preloaded_relations = @account.relations_map(account_ids, account_domains) results.reject { |status| StatusFilter.new(status, @account, preloaded_relations).filtered? } rescue Faraday::ConnectionFailed, Parslet::ParseFailed @@ -111,16 +111,6 @@ class SearchService < BaseService @options[:type].blank? || @options[:type] == 'statuses' end - def relations_map_for_account(account, account_ids, domains) - { - blocking: Account.blocking_map(account_ids, account.id), - blocked_by: Account.blocked_by_map(account_ids, account.id), - muting: Account.muting_map(account_ids, account.id), - following: Account.following_map(account_ids, account.id), - domain_blocking_by_domain: Account.domain_blocking_map_by_domain(domains, account.id), - } - end - def parsed_query SearchQueryTransformer.new.apply(SearchQueryParser.new.parse(@query)) end -- cgit