闭社主体 forked from https://github.com/tootsuite/mastodon
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.

37 lines
776 B

  1. class Follow < ActiveRecord::Base
  2. belongs_to :account
  3. belongs_to :target_account, class_name: 'Account'
  4. has_one :stream_entry, as: :activity, dependent: :destroy
  5. validates :account, :target_account, presence: true
  6. validates :account_id, uniqueness: { scope: :target_account_id }
  7. def verb
  8. self.destroyed? ? :unfollow : :follow
  9. end
  10. def target
  11. self.target_account
  12. end
  13. def object_type
  14. target.object_type
  15. end
  16. def content
  17. self.destroyed? ? "#{self.account.acct} is no longer following #{self.target_account.acct}" : "#{self.account.acct} started following #{self.target_account.acct}"
  18. end
  19. def title
  20. content
  21. end
  22. def mentions
  23. []
  24. end
  25. after_create do
  26. self.account.stream_entries.create!(activity: self)
  27. end
  28. end