follow_request.rb 1.3 KB

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