1
0

follow_request.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #
  14. class FollowRequest < ApplicationRecord
  15. include Paginable
  16. include RelationshipCacheable
  17. include RateLimitable
  18. rate_limit by: :account, family: :follows
  19. belongs_to :account
  20. belongs_to :target_account, class_name: 'Account'
  21. has_one :notification, as: :activity, dependent: :destroy
  22. validates :account_id, uniqueness: { scope: :target_account_id }
  23. validates_with FollowLimitValidator, on: :create
  24. def authorize!
  25. account.follow!(target_account, reblogs: show_reblogs, uri: uri)
  26. MergeWorker.perform_async(target_account.id, account.id) if account.local?
  27. destroy!
  28. end
  29. alias reject! destroy!
  30. def local?
  31. false # Force uri_for to use uri attribute
  32. end
  33. before_validation :set_uri, only: :create
  34. private
  35. def set_uri
  36. self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil?
  37. end
  38. end