The code powering m.abunchtell.com https://m.abunchtell.com
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

72 строки
1.5 KiB

  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. has_many :mentioned_accounts, class_name: 'Mention', dependent: :destroy
  10. validates :account, presence: true
  11. validates :uri, uniqueness: true, unless: 'local?'
  12. def local?
  13. self.uri.nil?
  14. end
  15. def reblog?
  16. !self.reblog_of_id.nil?
  17. end
  18. def reply?
  19. !self.in_reply_to_id.nil?
  20. end
  21. def verb
  22. reblog? ? :share : :post
  23. end
  24. def object_type
  25. reply? ? :comment : :note
  26. end
  27. def content
  28. reblog? ? self.reblog.text : self.text
  29. end
  30. def target
  31. self.reblog
  32. end
  33. def title
  34. content.truncate(80, omission: "...")
  35. end
  36. def mentions
  37. m = []
  38. m << thread.account if reply?
  39. m << reblog.account if reblog?
  40. unless reblog?
  41. self.text.scan(Account::MENTION_RE).each do |match|
  42. uri = match.first
  43. username, domain = uri.split('@')
  44. account = Account.find_by(username: username, domain: domain)
  45. m << account unless account.nil?
  46. end
  47. end
  48. m
  49. end
  50. after_create do
  51. self.account.stream_entries.create!(activity: self)
  52. end
  53. end