Class: Comment

Inherits:
ApplicationRecord show all
Includes:
Federails::DataEntity, PublicIDable, Reportable
Defined in:
app/models/comment.rb

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::SAFE_NAME_LENGTH

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PublicIDable

#to_param

Methods inherited from ApplicationRecord

find_param

Class Method Details

.from_activitypub_object(note) ⇒ Object



36
37
38
39
40
# File 'app/models/comment.rb', line 36

def self.from_activitypub_object(note)
  ActivityPub::CommentDeserializer.new(note).send :deserialize
rescue ActiveRecord::RecordNotFound
  {}
end

.handle_federated_object?(note) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/models/comment.rb', line 32

def self.handle_federated_object?(note)
  ActivityPub::CommentDeserializer.can_handle?(note)
end

Instance Method Details

#federate? ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/models/comment.rb', line 20

def federate?
  ActivityPub::CommentSerializer.new(self).federate?
end

#federated_delete ⇒ Object



42
43
44
# File 'app/models/comment.rb', line 42

def federated_delete
  destroy
end

#name ⇒ Object



28
29
30
# File 'app/models/comment.rb', line 28

def name
  "#{created_at} @ #{commentable.name}"
end

#on_new_quote_request(quote_authorization) ⇒ Object



46
47
48
49
# File 'app/models/comment.rb', line 46

def on_new_quote_request(quote_authorization)
  # Auto accept quote requests for system comments
  system ? quote_authorization.accept! : quote_authorization.reject!
end

#public? ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/comment.rb', line 24

def public?
  (!commenter&.local? || commenter&.public?) && commentable&.public?
end

#to_activitypub_object ⇒ Object



16
17
18
# File 'app/models/comment.rb', line 16

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