1
0

follow_request.rb 1.2 KB

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