Class: NewsmastMastodon::ReblogChannelsWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/newsmast_mastodon/reblog_channels_worker.rb

Instance Method Summary collapse

Instance Method Details

#perform(status_id, account_id) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/workers/newsmast_mastodon/reblog_channels_worker.rb', line 10

def perform(status_id, )
   = Account.find_by(id: )
  return false unless 

  community_user = User.find_by(account_id: .id)
  return false unless community_user

  community_admin = NewsmastMastodon::CommunityAdmin.includes(:community).find_by(account_id: .id, is_boost_bot: true)
  return false unless community_admin

  admin_access_token = NewsmastMastodon::FetchAdminAccessTokenService.new(community_user.id).call
  return false unless admin_access_token

  community = community_admin&.community
  return false unless community

  if community&.channel_type == 'newsmast'
    boost_by_newsmast_bot(community_admin, status_id)
  else
    begin
      NewsmastMastodon::ReblogRequestService.new.call(admin_access_token, status_id)
      channels = ENV.fetch('FOR_YOU_TIMELINE_CHANNELS', nil).presence&.split(/\s*,\s*/)&.reject(&:blank?)&.map(&:downcase) || []
      NewsmastMastodon::CustomBoostBotService.new(status_id, community_admin&.username).call if channels.include?(community_admin&.username.downcase)
    rescue => e
      Rails.logger.error "ReblogRequestService failed: - #{e.message}"
      false
    end
  end
end