Class: Fediverse::Inbox
- Inherits:
-
Object
- Object
- Fediverse::Inbox
- Defined in:
- lib/fediverse/inbox.rb
Constant Summary collapse
- @@handlers =
rubocop:todo Style/ClassVars
{}
Class Method Summary collapse
-
.dispatch_request(payload) ⇒ Object
Executes the registered handler for an incoming object.
-
.register_handler(activity_type, object_type, klass, method) ⇒ Object
Registers a handler for incoming data.
Class Method Details
.dispatch_request(payload) ⇒ Object
Executes the registered handler for an incoming object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fediverse/inbox.rb', line 27 def dispatch_request(payload) return dispatch_delete_request(payload) if payload['type'] == 'Delete' payload['object'] = Fediverse::Request.dereference(payload['object']) if payload.key? 'object' handlers = get_handlers(payload['type'], payload.dig('object', 'type')) handlers.each_pair do |klass, method| klass.send method, payload end return true unless handlers.empty? Rails.logger.debug { "Unhandled activity type: #{payload['type']}" } false end |
.register_handler(activity_type, object_type, klass, method) ⇒ Object
Registers a handler for incoming data
Unless a specific type is not implemented in Federails, you should leave the ‘Delete’ activity to Federails: it will dispatch a ‘on_federails_delete_requested` event on the right objects.
18 19 20 21 22 |
# File 'lib/fediverse/inbox.rb', line 18 def register_handler(activity_type, object_type, klass, method) @@handlers[activity_type] ||= {} @@handlers[activity_type][object_type] ||= {} @@handlers[activity_type][object_type][klass] = method end |