Class: Collection

Inherits:
ApplicationRecord show all
Includes:
CaberObject, Commentable, FaspClient::DataSharing::Lifecycle, Followable, Indexable, Linkable, PublicIDable, Sluggable, Talkative
Defined in:
app/models/collection.rb

Constant Summary

Constants included from Talkative

Talkative::TIMEOUT

Constants included from FederailsCommon

FederailsCommon::FEDIVERSE_USERNAMES

Constants inherited from ApplicationRecord

ApplicationRecord::SAFE_NAME_LENGTH

Instance Method Summary collapse

Methods included from Indexable

#ai_indexable?, #indexable?, #inherited_ai_indexable?, #inherited_indexable?, #public_and_indexable?

Methods included from PublicIDable

#to_param

Methods included from CaberObject

#just_became_public?, #matching_permission_preset, #owners, #private?, #public?, #set_default_permission_preset, #set_owner, #set_permissions_from_preset, #will_be_public?

Methods included from Talkative

#owning_actor

Methods included from Followable

#followed_by?, #followers

Methods included from FederailsCommon

#federails_actor, #local?, #remote?

Methods inherited from ApplicationRecord

find_param

Instance Method Details

#after_create ⇒ Object



76
77
78
# File 'app/models/collection.rb', line 76

def after_create
  Activity::CollectionPublishedJob.set(wait: 5.seconds).perform_later(id) if public?
end

#after_update ⇒ Object



80
81
82
# File 'app/models/collection.rb', line 80

def after_update
  Activity::CollectionPublishedJob.set(wait: 5.seconds).perform_later(id) if just_became_public?
end

#fasp_uri ⇒ Object



53
54
55
# File 'app/models/collection.rb', line 53

def fasp_uri
  federails_actor&.federated_url
end

#name_with_domain ⇒ Object



57
58
59
# File 'app/models/collection.rb', line 57

def name_with_domain
  remote? ? name + " (#{federails_actor.server})" : name
end

#publish_creator ⇒ Object



95
96
97
# File 'app/models/collection.rb', line 95

def publish_creator
  creator&.update!(caber_relations_attributes: [{permission: "view", subject: nil}]) unless creator&.public?
end

#to_activitypub_object ⇒ Object



72
73
74
# File 'app/models/collection.rb', line 72

def to_activitypub_object
  ActivityPub::CollectionSerializer.new(self).serialize
end

#validate_publishable ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'app/models/collection.rb', line 84

def validate_publishable
  # If the model will be public
  if caber_relations.find { it.subject.nil? }
    # Check required fields
    # i18n-tasks-use t("activerecord.errors.models.collection.attributes.creator.private")
    errors.add :creator, :private if creator && !creator.public?
    # i18n-tasks-use t("activerecord.errors.models.collection.attributes.collection.private")
    errors.add :collection, :private if collection && !collection.public?
  end
end