5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 12:36:21 +00:00

fix: recibir actividades correctamente

This commit is contained in:
f 2024-02-28 17:52:24 -03:00
parent aeb8f88493
commit 6eaf00c7ad
No known key found for this signature in database

View file

@ -5,6 +5,9 @@ module Api
module Webhooks module Webhooks
# Recibe webhooks de la Social Inbox # Recibe webhooks de la Social Inbox
# #
# @todo Mover todo a un Job que obtenga el objeto remoto antes de
# instanciar el objeto localmente en lugar de arreglarlo después y
# poder responder lo más rápido posible el webhook.
# @see {https://www.w3.org/TR/activitypub/} # @see {https://www.w3.org/TR/activitypub/}
class SocialInboxController < BaseController class SocialInboxController < BaseController
include Api::V1::Webhooks::Concerns::WebhookConcern include Api::V1::Webhooks::Concerns::WebhookConcern
@ -28,6 +31,7 @@ module Api
instance.present? instance.present?
object.present? object.present?
activity_pub.present? activity_pub.present?
activity.update_activity_pub_state! activity.update_activity_pub_state!
end end
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
@ -125,7 +129,7 @@ module Api
# #
# @return [ActivityPub] # @return [ActivityPub]
def activity_pub def activity_pub
@activity_pub ||= site.activity_pubs.find_or_create_by!(site: site, object: object) @activity_pub ||= site.activity_pubs.find_or_create_by!(site: site, instance: instance, object: object)
end end
# Crea la actividad y la vincula con el estado # Crea la actividad y la vincula con el estado
@ -135,7 +139,7 @@ module Api
@activity ||= @activity ||=
ActivityPub::Activity ActivityPub::Activity
.type_from(original_activity) .type_from(original_activity)
.find_or_initialize_by(uri: original_activity[:id], activity_pub: activity_pub).tap do |a| .find_or_initialize_by(uri: original_activity[:id], activity_pub: activity_pub, actor: actor).tap do |a|
a.content = original_activity.dup a.content = original_activity.dup
a.content[:object] = object.uri a.content[:object] = object.uri
a.save! a.save!