diff options
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/activitypub/activity/block.rb | 7 | ||||
-rw-r--r-- | app/lib/entity_cache.rb | 2 | ||||
-rw-r--r-- | app/lib/extractor.rb | 8 | ||||
-rw-r--r-- | app/lib/feed_manager.rb | 6 | ||||
-rw-r--r-- | app/lib/formatter.rb | 2 | ||||
-rw-r--r-- | app/lib/request.rb | 2 | ||||
-rw-r--r-- | app/lib/sanitize_config.rb | 6 | ||||
-rw-r--r-- | app/lib/settings/scoped_settings.rb | 2 | ||||
-rw-r--r-- | app/lib/spam_check.rb | 4 | ||||
-rw-r--r-- | app/lib/webfinger.rb | 2 |
10 files changed, 23 insertions, 18 deletions
diff --git a/app/lib/activitypub/activity/block.rb b/app/lib/activitypub/activity/block.rb index 90477bf33..92a0f813f 100644 --- a/app/lib/activitypub/activity/block.rb +++ b/app/lib/activitypub/activity/block.rb @@ -11,8 +11,13 @@ class ActivityPub::Activity::Block < ActivityPub::Activity return end + UnfollowService.new.call(@account, target_account) if @account.following?(target_account) UnfollowService.new.call(target_account, @account) if target_account.following?(@account) + RejectFollowService.new.call(target_account, @account) if target_account.requested?(@account) - @account.block!(target_account, uri: @json['id']) unless delete_arrived_first?(@json['id']) + unless delete_arrived_first?(@json['id']) + BlockWorker.perform_async(@account.id, target_account.id) + @account.block!(target_account, uri: @json['id']) + end end end diff --git a/app/lib/entity_cache.rb b/app/lib/entity_cache.rb index e38a3adcd..5d51e8585 100644 --- a/app/lib/entity_cache.rb +++ b/app/lib/entity_cache.rb @@ -25,7 +25,7 @@ class EntityCache end unless uncached_ids.empty? - uncached = CustomEmoji.where(shortcode: shortcodes, domain: domain, disabled: false).each_with_object({}) { |item, h| h[item.shortcode] = item } + uncached = CustomEmoji.where(shortcode: shortcodes, domain: domain, disabled: false).index_by(&:shortcode) uncached.each_value { |item| Rails.cache.write(to_key(:emoji, item.shortcode, domain), item, expires_in: MAX_EXPIRATION) } end diff --git a/app/lib/extractor.rb b/app/lib/extractor.rb index 479689d60..6076458ad 100644 --- a/app/lib/extractor.rb +++ b/app/lib/extractor.rb @@ -7,14 +7,14 @@ module Extractor # :yields: username, list_slug, start, end def extract_mentions_or_lists_with_indices(text) - return [] unless text =~ Twitter::Regex[:at_signs] + return [] unless Twitter::Regex[:at_signs].match?(text) possible_entries = [] text.to_s.scan(Account::MENTION_RE) do |screen_name, _| match_data = $LAST_MATCH_INFO after = $' - unless after =~ Twitter::Regex[:end_mention_match] + unless Twitter::Regex[:end_mention_match].match?(after) start_position = match_data.char_begin(1) - 1 end_position = match_data.char_end(1) possible_entries << { @@ -33,7 +33,7 @@ module Extractor end def extract_hashtags_with_indices(text, **) - return [] unless text =~ /#/ + return [] unless /#/.match?(text) tags = [] text.scan(Tag::HASHTAG_RE) do |hash_text, _| @@ -41,7 +41,7 @@ module Extractor start_position = match_data.char_begin(1) - 1 end_position = match_data.char_end(1) after = $' - if after =~ %r{\A://} + if %r{\A://}.match?(after) hash_text.match(/(.+)(https?\Z)/) do |matched| hash_text = matched[1] end_position -= matched[2].char_length diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index ddd975c5f..2e70c2ce9 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -454,8 +454,8 @@ class FeedManager active_filters.map! do |filter| if filter.whole_word - sb = filter.phrase =~ /\A[[:word:]]/ ? '\b' : '' - eb = filter.phrase =~ /[[:word:]]\z/ ? '\b' : '' + sb = /\A[[:word:]]/.match?(filter.phrase) ? '\b' : '' + eb = /[[:word:]]\z/.match?(filter.phrase) ? '\b' : '' /(?mix:#{sb}#{Regexp.escape(filter.phrase)}#{eb})/ else @@ -475,7 +475,7 @@ class FeedManager status.media_attachments.map(&:description).join("\n\n"), ].compact.join("\n\n") - !combined_regex.match(combined_text).nil? + combined_regex.match?(combined_text) end # Adds a status to an account's feed, returning true if a status was diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index e7bb0743d..1aeedac8a 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -287,7 +287,7 @@ class Formatter escaped = text.chars.map do |c| output = begin - if c.ord.to_s(16).length > 2 && UNICODE_ESCAPE_BLACKLIST_RE.match(c).nil? + if c.ord.to_s(16).length > 2 && !UNICODE_ESCAPE_BLACKLIST_RE.match?(c) CGI.escape(c) else c diff --git a/app/lib/request.rb b/app/lib/request.rb index 38048dad7..125dee3ea 100644 --- a/app/lib/request.rb +++ b/app/lib/request.rb @@ -145,7 +145,7 @@ class Request end def block_hidden_service? - !Rails.configuration.x.access_to_hidden_service && /\.(onion|i2p)$/.match(@url.host) + !Rails.configuration.x.access_to_hidden_service && /\.(onion|i2p)$/.match?(@url.host) end module ClientLimit diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb index 89373664a..fed504cf2 100644 --- a/app/lib/sanitize_config.rb +++ b/app/lib/sanitize_config.rb @@ -29,9 +29,9 @@ class Sanitize return unless class_list class_list.keep_if do |e| - next true if e =~ /^(h|p|u|dt|e)-/ # microformats classes - next true if e =~ /^(mention|hashtag)$/ # semantic classes - next true if e =~ /^(ellipsis|invisible)$/ # link formatting classes + next true if /^(h|p|u|dt|e)-/.match?(e) # microformats classes + next true if /^(mention|hashtag)$/.match?(e) # semantic classes + next true if /^(ellipsis|invisible)$/.match?(e) # link formatting classes end node['class'] = class_list.join(' ') diff --git a/app/lib/settings/scoped_settings.rb b/app/lib/settings/scoped_settings.rb index 9889940f3..95e195458 100644 --- a/app/lib/settings/scoped_settings.rb +++ b/app/lib/settings/scoped_settings.rb @@ -31,7 +31,7 @@ module Settings def all_as_records vars = thing_scoped - records = vars.each_with_object({}) { |r, h| h[r.var] = r } + records = vars.index_by(&:var) Setting.default_settings.each do |key, default_value| next if records.key?(key) || default_value.is_a?(Hash) diff --git a/app/lib/spam_check.rb b/app/lib/spam_check.rb index 68e586d00..dcb2db9ca 100644 --- a/app/lib/spam_check.rb +++ b/app/lib/spam_check.rb @@ -186,9 +186,9 @@ class SpamCheck def matching_status_ids if nilsimsa? - other_digests.select { |record| record.start_with?('nilsimsa') && nilsimsa_compare_value(digest, record.split(':')[1]) >= NILSIMSA_COMPARE_THRESHOLD }.filter_map { |record| record.split(':')[2] } + other_digests.filter_map { |record| record.split(':')[2] if record.start_with?('nilsimsa') && nilsimsa_compare_value(digest, record.split(':')[1]) >= NILSIMSA_COMPARE_THRESHOLD } else - other_digests.select { |record| record.start_with?('md5') && record.split(':')[1] == digest }.filter_map { |record| record.split(':')[2] } + other_digests.filter_map { |record| record.split(':')[2] if record.start_with?('md5') && record.split(':')[1] == digest } end end diff --git a/app/lib/webfinger.rb b/app/lib/webfinger.rb index c7aa43bb3..702365939 100644 --- a/app/lib/webfinger.rb +++ b/app/lib/webfinger.rb @@ -21,7 +21,7 @@ class Webfinger private def links - @links ||= @json['links'].map { |link| [link['rel'], link] }.to_h + @links ||= @json['links'].index_by { |link| link['rel'] } end end |