The code powering m.abunchtell.com https://m.abunchtell.com
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

53 lines
1.4 KiB

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: follows
  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 Follow < ApplicationRecord
  15. include Paginable
  16. include RelationshipCacheable
  17. belongs_to :account, counter_cache: :following_count
  18. belongs_to :target_account,
  19. class_name: 'Account',
  20. counter_cache: :followers_count
  21. has_one :notification, as: :activity, dependent: :destroy
  22. validates :account_id, uniqueness: { scope: :target_account_id }
  23. scope :recent, -> { reorder(id: :desc) }
  24. def local?
  25. false # Force uri_for to use uri attribute
  26. end
  27. def revoke_request!
  28. FollowRequest.create!(account: account, target_account: target_account, show_reblogs: show_reblogs, uri: uri)
  29. destroy!
  30. end
  31. before_validation :set_uri, only: :create
  32. after_destroy :remove_endorsements
  33. private
  34. def set_uri
  35. self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil?
  36. end
  37. def remove_endorsements
  38. AccountPin.where(target_account_id: target_account_id, account_id: account_id).delete_all
  39. end
  40. end