follow_request.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: follow_requests
  5. #
  6. # id :bigint(8) not null, primary key
  7. # created_at :datetime not null
  8. # updated_at :datetime not null
  9. # account_id :bigint(8) not null
  10. # target_account_id :bigint(8) not null
  11. # show_reblogs :boolean default(TRUE), not null
  12. # uri :string
  13. # notify :boolean default(FALSE), not null
  14. # languages :string is an Array
  15. #
  16. class FollowRequest < ApplicationRecord
  17. include Paginable
  18. include RelationshipCacheable
  19. include RateLimitable
  20. include FollowLimitable
  21. rate_limit by: :account, family: :follows
  22. belongs_to :account
  23. belongs_to :target_account, class_name: 'Account'
  24. has_one :notification, as: :activity, dependent: :destroy
  25. validates :account_id, uniqueness: { scope: :target_account_id }
  26. validates :languages, language: true
  27. def authorize!
  28. account.follow!(target_account, reblogs: show_reblogs, notify: notify, languages: languages, uri: uri, bypass_limit: true)
  29. MergeWorker.perform_async(target_account.id, account.id) if account.local?
  30. destroy!
  31. end
  32. alias reject! destroy!
  33. def local?
  34. false # Force uri_for to use uri attribute
  35. end
  36. before_validation :set_uri, only: :create
  37. private
  38. def set_uri
  39. self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil?
  40. end
  41. end