follow_request.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. def authorize!
  22. account.follow!(target_account, reblogs: show_reblogs, uri: uri)
  23. MergeWorker.perform_async(target_account.id, account.id)
  24. destroy!
  25. end
  26. alias reject! destroy!
  27. def local?
  28. false # Force uri_for to use uri attribute
  29. end
  30. before_validation :set_uri, only: :create
  31. private
  32. def set_uri
  33. self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil?
  34. end
  35. end