You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.2 KiB

8 years ago
8 years ago
  1. class Status < ActiveRecord::Base
  2. belongs_to :account, inverse_of: :statuses
  3. belongs_to :thread, foreign_key: 'in_reply_to_id', class_name: 'Status'
  4. belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status'
  5. has_one :stream_entry, as: :activity, dependent: :destroy
  6. has_many :favourites, inverse_of: :status, dependent: :destroy
  7. has_many :reblogs, foreign_key: 'reblog_of_id', class_name: 'Status'
  8. has_many :replies, foreign_key: 'in_reply_to_id', class_name: 'Status'
  9. validates :account, presence: true
  10. validates :uri, uniqueness: true, unless: 'local?'
  11. def local?
  12. self.uri.nil?
  13. end
  14. def reblog?
  15. !self.reblog_of_id.nil?
  16. end
  17. def reply?
  18. !self.in_reply_to_id.nil?
  19. end
  20. def verb
  21. reblog? ? :share : :post
  22. end
  23. def object_type
  24. reply? ? :comment : :note
  25. end
  26. def content
  27. reblog? ? self.reblog.text : self.text
  28. end
  29. def target
  30. self.reblog
  31. end
  32. def title
  33. content.truncate(80, omission: "...")
  34. end
  35. def mentions
  36. m = []
  37. m << thread.account if reply?
  38. m << reblog.account if reblog?
  39. m
  40. end
  41. after_create do
  42. self.account.stream_entries.create!(activity: self)
  43. end
  44. end