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.

57 lines
996 B

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
  6. has_many :favourites, inverse_of: :status
  7. validates :account, presence: true
  8. validates :uri, uniqueness: true, unless: 'local?'
  9. def local?
  10. self.uri.nil?
  11. end
  12. def reblog?
  13. !self.reblog_of_id.nil?
  14. end
  15. def reply?
  16. !self.in_reply_to_id.nil?
  17. end
  18. def verb
  19. reblog? ? :share : :post
  20. end
  21. def object_type
  22. reply? ? :comment : :note
  23. end
  24. def content
  25. reblog? ? self.reblog.text : self.text
  26. end
  27. def target
  28. self.reblog
  29. end
  30. def title
  31. content.truncate(80, omission: "...")
  32. end
  33. def mentions
  34. m = []
  35. m << thread.account if reply?
  36. m << reblog.account if reblog?
  37. m
  38. end
  39. after_create do
  40. self.account.stream_entries.create!(activity: self)
  41. end
  42. end