mirror of
https://github.com/manyfold3d/manyfold.git
synced 2026-10-23 04:02:19 -05:00
51 lines
1.3 KiB
Ruby
51 lines
1.3 KiB
Ruby
require "fedipub/data_transformer/note"
|
|
|
|
class Comment < ApplicationRecord
|
|
# i18n-tasks-use t("activerecord.models.comment")
|
|
|
|
include PublicIDable
|
|
include Fedipub::DataEntity
|
|
include Reportable
|
|
|
|
belongs_to :commenter, polymorphic: true, optional: true
|
|
belongs_to :commentable, polymorphic: true
|
|
|
|
acts_as_fedipub_data handles: "Note", actor_entity_method: :commenter, url_param: :public_id, should_federate_method: :federate?, route_path_segment: :comments
|
|
on_fedipub_delete_requested :federated_delete
|
|
|
|
def to_activitypub_object
|
|
ActivityPub::CommentSerializer.new(self).serialize
|
|
end
|
|
|
|
def federate?
|
|
ActivityPub::CommentSerializer.new(self).federate?
|
|
end
|
|
|
|
def public?
|
|
(!commenter&.local? || commenter&.public?) && commentable&.public?
|
|
end
|
|
|
|
def name
|
|
"#{created_at} @ #{commentable.name}"
|
|
end
|
|
|
|
def self.handle_federated_object?(note)
|
|
ActivityPub::CommentDeserializer.can_handle?(note)
|
|
end
|
|
|
|
def self.from_activitypub_object(note)
|
|
ActivityPub::CommentDeserializer.new(note).send :deserialize
|
|
rescue ActiveRecord::RecordNotFound
|
|
{}
|
|
end
|
|
|
|
def federated_delete
|
|
destroy
|
|
end
|
|
|
|
def on_new_quote_request(quote_authorization)
|
|
# Auto accept quote requests for system comments
|
|
system ? quote_authorization.accept! : quote_authorization.reject!
|
|
end
|
|
end
|