From 0cf94443bdc1ca9a4f9b6b27abba10b45e38247e Mon Sep 17 00:00:00 2001 From: Jeremy Kescher Date: Mon, 8 May 2023 19:37:56 +0200 Subject: [PATCH] Rubocop fixes --- app/lib/activitypub/activity/create.rb | 1 + app/lib/activitypub/activity/emoji_react.rb | 2 +- app/lib/activitypub/activity/like.rb | 2 +- app/models/notification.rb | 12 ++++----- app/models/status_reaction.rb | 1 + app/services/unreact_service.rb | 26 +++++++++---------- .../fabricators/status_reaction_fabricator.rb | 4 +-- 7 files changed, 25 insertions(+), 23 deletions(-) diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index a23e9e8f79..99ec67c4d7 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -222,6 +222,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity account = account_from_uri(tag['href']) begin return unless account || DeliveryFailureTracker.available?(tag['href']) + account = ActivityPub::FetchRemoteAccountService.new.call(tag['href'], request_id: @options[:request_id]) if account.nil? rescue HTTP::ConnectionError => e Rails.logger.info "Fetching account #{tag['href']} failed: #{e}" diff --git a/app/lib/activitypub/activity/emoji_react.rb b/app/lib/activitypub/activity/emoji_react.rb index 2730270fc7..526f22803d 100644 --- a/app/lib/activitypub/activity/emoji_react.rb +++ b/app/lib/activitypub/activity/emoji_react.rb @@ -10,7 +10,7 @@ class ActivityPub::Activity::EmojiReact < ActivityPub::Activity @account.reacted?(original_status, name) custom_emoji = nil - if name =~ /^:.*:$/ + if /^:.*:$/.match?(name) process_emoji_tags(@json['tag']) name.delete! ':' diff --git a/app/lib/activitypub/activity/like.rb b/app/lib/activitypub/activity/like.rb index 66d8e59c8f..8acc99b9db 100644 --- a/app/lib/activitypub/activity/like.rb +++ b/app/lib/activitypub/activity/like.rb @@ -22,7 +22,7 @@ class ActivityPub::Activity::Like < ActivityPub::Activity return false if name.nil? custom_emoji = nil - if name =~ /^:.*:$/ + if /^:.*:$/.match?(name) process_emoji_tags(@json['tag']) name.delete! ':' diff --git a/app/models/notification.rb b/app/models/notification.rb index 95453cf031..deffc6f756 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -20,13 +20,13 @@ class Notification < ApplicationRecord include Paginable LEGACY_TYPE_CLASS_MAP = { - 'Mention' => :mention, - 'Status' => :reblog, - 'Follow' => :follow, - 'FollowRequest' => :follow_request, - 'Favourite' => :favourite, + 'Mention' => :mention, + 'Status' => :reblog, + 'Follow' => :follow, + 'FollowRequest' => :follow_request, + 'Favourite' => :favourite, 'StatusReaction' => :reaction, - 'Poll' => :poll, + 'Poll' => :poll, }.freeze TYPES = %i( diff --git a/app/models/status_reaction.rb b/app/models/status_reaction.rb index 00be17e231..a54d03a309 100644 --- a/app/models/status_reaction.rb +++ b/app/models/status_reaction.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # == Schema Information # # Table name: status_reactions diff --git a/app/services/unreact_service.rb b/app/services/unreact_service.rb index 37dc1d7c53..7c1b32e94f 100644 --- a/app/services/unreact_service.rb +++ b/app/services/unreact_service.rb @@ -4,20 +4,20 @@ class UnreactService < BaseService include Payloadable def call(account, status, emoji) - name, domain = emoji.split('@') - custom_emoji = CustomEmoji.find_by(shortcode: name, domain: domain) - reaction = StatusReaction.find_by(account: account, status: status, name: name, custom_emoji: custom_emoji) - return if reaction.nil? + name, domain = emoji.split('@') + custom_emoji = CustomEmoji.find_by(shortcode: name, domain: domain) + reaction = StatusReaction.find_by(account: account, status: status, name: name, custom_emoji: custom_emoji) + return if reaction.nil? - reaction.destroy! + reaction.destroy! - json = Oj.dump(serialize_payload(reaction, ActivityPub::UndoEmojiReactionSerializer)) - if status.account.local? - ActivityPub::RawDistributionWorker.perform_async(json, status.account.id) - else - ActivityPub::DeliveryWorker.perform_async(json, reaction.account_id, status.account.inbox_url) - end - - reaction + json = Oj.dump(serialize_payload(reaction, ActivityPub::UndoEmojiReactionSerializer)) + if status.account.local? + ActivityPub::RawDistributionWorker.perform_async(json, status.account.id) + else + ActivityPub::DeliveryWorker.perform_async(json, reaction.account_id, status.account.inbox_url) end + + reaction + end end diff --git a/spec/fabricators/status_reaction_fabricator.rb b/spec/fabricators/status_reaction_fabricator.rb index 3d4b93efe0..bd042ec07a 100644 --- a/spec/fabricators/status_reaction_fabricator.rb +++ b/spec/fabricators/status_reaction_fabricator.rb @@ -1,6 +1,6 @@ Fabricator(:status_reaction) do account nil status nil - name "MyString" + name 'MyString' custom_emoji nil -end \ No newline at end of file +end