From 85c45d48236f0a7040e2e23545ee08bfc6f2fb9e Mon Sep 17 00:00:00 2001 From: f Date: Fri, 1 Mar 2024 17:29:08 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20no=20duplicar=20c=C3=B3digo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/webhooks/social_inbox_controller.rb | 7 +------ app/models/activity_pub.rb | 3 ++- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/v1/webhooks/social_inbox_controller.rb b/app/controllers/api/v1/webhooks/social_inbox_controller.rb index dec2ee97..fda51f49 100644 --- a/app/controllers/api/v1/webhooks/social_inbox_controller.rb +++ b/app/controllers/api/v1/webhooks/social_inbox_controller.rb @@ -89,12 +89,7 @@ module Api # # @return [String] def object_uri - @object_uri ||= - case original_activity[:object] - when Array then original_activity[:object].first - when String then original_activity[:object] - when Hash then original_activity.dig(:object, :id) - end + @object_uri ||= ::ActivityPub.uri_from_object(original_activity[:object]) ensure raise ActiveRecord::RecordNotFound, 'object id missing' if @object_uri.blank? end diff --git a/app/models/activity_pub.rb b/app/models/activity_pub.rb index 1afeee96..86c3f240 100644 --- a/app/models/activity_pub.rb +++ b/app/models/activity_pub.rb @@ -24,8 +24,9 @@ class ActivityPub < ApplicationRecord # @return [String, nil] def self.uri_from_object(object) case object + when Array then uri_from_object(object.first) when String then object - when Hash then object['id'] + when Hash then (object['id'] || object[:id]) end end