mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-21 22:46:21 +00:00
feat: guardar la mención de le autore
This commit is contained in:
parent
f6b2895b58
commit
b972e53e48
3 changed files with 36 additions and 4 deletions
|
@ -29,8 +29,13 @@ class ActivityPub
|
|||
|
||||
object.update(content: content, type: ActivityPub::Object.type_from(content).name)
|
||||
|
||||
return if current_type == object.type
|
||||
|
||||
object = ::ActivityPub::Object.find(object_id)
|
||||
object.actor.save if object.actor_type?
|
||||
|
||||
# Arreglar las relaciones con actividades también
|
||||
ActivityPub.where(object_id: object.id).update_all(object_type: object.type) unless current_type == object.type
|
||||
ActivityPub.where(object_id: object.id).update_all(object_type: object.type)
|
||||
rescue FastJsonparser::ParseError => e
|
||||
ExceptionNotifier.notify_exception(e, data: { site: site.name, body: response.body })
|
||||
end
|
||||
|
|
|
@ -18,19 +18,22 @@ class ActivityPub
|
|||
# Les actores son únicxs a toda la base de datos
|
||||
validates :uri, presence: true, url: true, uniqueness: true
|
||||
|
||||
before_save :mentionize!
|
||||
|
||||
# Obtiene el nombre de la Actor como mención, solo si obtuvimos el
|
||||
# contenido de antemano.
|
||||
#
|
||||
# @return [String, nil]
|
||||
def mention
|
||||
def mentionize!
|
||||
return if mention.present?
|
||||
return if content['preferredUsername'].blank?
|
||||
return if instance.blank?
|
||||
|
||||
@mention ||= "@#{content['preferredUsername']}@#{instance.hostname}"
|
||||
self.mention ||= "@#{content['preferredUsername']}@#{instance.hostname}"
|
||||
end
|
||||
|
||||
def object
|
||||
@object ||= ActivityPub::Object::Person.find_or_initialize_by(uri: uri)
|
||||
@object ||= ActivityPub::Object.find_or_initialize_by(uri: uri)
|
||||
end
|
||||
|
||||
def content
|
||||
|
|
24
db/migrate/20240316203721_add_mention_to_actors.rb
Normal file
24
db/migrate/20240316203721_add_mention_to_actors.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Guarda la mención en la tabla de actores
|
||||
class AddMentionToActors < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
add_column :activity_pub_actors, :mention, :string, null: true
|
||||
|
||||
actor_types = %w[
|
||||
ActivityPub::Object::Application
|
||||
ActivityPub::Object::Group
|
||||
ActivityPub::Object::Organization
|
||||
ActivityPub::Object::Person
|
||||
ActivityPub::Object::Service
|
||||
]
|
||||
|
||||
ActivityPub::Object.where(type: actor_types).where.not(content: {}).find_each do |object|
|
||||
ActivityPub::Actor.find_by_uri(object.uri)&.save
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :activity_pub_actors, :mention
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue