Module: Federails::ActorEntity::ClassMethods

Defined in:
app/models/concerns/federails/actor_entity.rb

Overview

Class methods automatically included in the concern.

Instance Method Summary collapse

Instance Method Details

#acts_as_federails_actor(name_field:, username_field:, profile_url_method: nil, actor_type: 'Person', user_count_method: nil, auto_create_actors: true) ⇒ Object

Configures the mapping between entity and actor

rubocop:disable Metrics/ParameterLists

Examples:

acts_as_federails_actor username_field: :username, name_field: :display_name, profile_url_method: :url_for, actor_type: 'Person'

Parameters:

  • username_field (Symbol)

    The method or attribute name that returns the preferred username for ActivityPub

  • name_field (Symbol)

    The method or attribute name that returns the preferred name for ActivityPub

  • profile_url_method (Symbol) (defaults to: nil)

    The route method name that will generate the profile URL for ActivityPub

  • actor_type (String) (defaults to: 'Person')

    The ActivityStreams Actor type for this entity; defaults to ‘Person’

  • user_count_method (Symbol) (defaults to: nil)

    A class method to call to count active users. Leave unspecified to leave this entity out of user counts. Method signature should accept a single parameter which will specify a date range If parameter is nil, the total user count should be returned. If the parameter is specified, the number of users active during the time period should be returned.

  • auto_create_actors (Boolean) (defaults to: true)

    Whether to automatically create an actor when the entity is created



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/concerns/federails/actor_entity.rb', line 42

def acts_as_federails_actor(
  name_field:,
  username_field:,
  profile_url_method: nil,
  actor_type: 'Person',
  user_count_method: nil,
  auto_create_actors: true
)
  Federails::Configuration.register_actor_class(
    self,
    username_field:     username_field,
    name_field:         name_field,
    profile_url_method: profile_url_method,
    actor_type:         actor_type,
    user_count_method:  user_count_method,
    auto_create_actors: auto_create_actors
  )
end

#after_activity_received(activity_type, object_type, method_name) ⇒ Object

Define a method that will be called after an activity has been received

Examples:

after_activity_received 'Create', 'Note', :create_note

Parameters:

  • activity_type (String)

    The activity action to handle, e.g. ‘Create’. If you specify ‘*’, the handler will be called for any activity type.

  • object_type (String)

    The object type to handle, e.g. ‘Note’. If you specify ‘*’, the handler will be called for any object type.

  • method_name (Symbol)

    The name of the class method to call. The method will receive the complete activity payload as a parameter.



92
93
94
# File 'app/models/concerns/federails/actor_entity.rb', line 92

def after_activity_received(activity_type, object_type, method_name)
  Fediverse::Inbox.register_handler(activity_type, object_type, self, method_name)
end

#after_follow_accepted(method_name) ⇒ Object

Define a method that will be called after a follow request made by the entity is accepted The accepted follow request will be passed as an argument to the method.

Examples:

after_follow_accepted :follow_accepted

Parameters:

  • method_name (Symbol)

    The name of the method to call, or a block that will be called directly



80
81
82
# File 'app/models/concerns/federails/actor_entity.rb', line 80

def after_follow_accepted(method_name)
  @after_follow_accepted = method_name
end

#after_followed(method_name) ⇒ Object

Define a method that will be called after the entity receives a follow request. The follow request will be passed as an argument to the method.

Examples:

after_followed :accept_follow

Parameters:

  • method_name (Symbol)

    The name of the method to call, or a block that will be called directly



69
70
71
# File 'app/models/concerns/federails/actor_entity.rb', line 69

def after_followed(method_name)
  @after_followed = method_name
end