follow.rb 659 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. class Follow < ApplicationRecord
  3. include Paginable
  4. include Streamable
  5. belongs_to :account
  6. belongs_to :target_account, class_name: 'Account'
  7. has_one :notification, as: :activity, dependent: :destroy
  8. validates :account, :target_account, presence: true
  9. validates :account_id, uniqueness: { scope: :target_account_id }
  10. def verb
  11. destroyed? ? :unfollow : :follow
  12. end
  13. def target
  14. target_account
  15. end
  16. def object_type
  17. :person
  18. end
  19. def title
  20. destroyed? ? "#{account.acct} is no longer following #{target_account.acct}" : "#{account.acct} started following #{target_account.acct}"
  21. end
  22. end