Class: NewsmastMastodon::UpdateChannelNameServices

Inherits:
BaseService
  • Object
show all
Includes:
NonChannelHelper
Defined in:
app/services/newsmast_mastodon/update_channel_name_services.rb

Instance Method Summary collapse

Methods included from NonChannelHelper

#is_non_channel?

Instance Method Details

#call(account, options = {}) ⇒ Object



9
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
# File 'app/services/newsmast_mastodon/update_channel_name_services.rb', line 9

def call(, options = {})
  return if is_non_channel?

  return unless options[:type] == 'channel_feed'

  return unless Object.const_defined?('NewsmastMastodon::CommunityAdmin')

  return unless defined?(NewsmastMastodon::CommunityAdmin) && NewsmastMastodon::CommunityAdmin.respond_to?(:find_by)
  return unless NewsmastMastodon::CommunityAdmin.table_exists?

  community_admin = NewsmastMastodon::CommunityAdmin.find_by(
    account_id: .id,
    is_boost_bot: true,
    account_status: NewsmastMastodon::CommunityAdmin.['active']
  )
  return unless community_admin

  community = community_admin.community

  community.update!(
    name: .display_name.strip.presence,
    description: .note,
    avatar_image: .avatar,
    banner_image: .header
  )
rescue ActiveRecord::RecordInvalid => e
  Rails.logger.error "[UpdateChannelNameServices] Community update failed: #{e.record.class} - #{e.message}"
end