1
0

relationship_severance_event.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: relationship_severance_events
  5. #
  6. # id :bigint(8) not null, primary key
  7. # type :integer not null
  8. # target_name :string not null
  9. # purged :boolean default(FALSE), not null
  10. # created_at :datetime not null
  11. # updated_at :datetime not null
  12. #
  13. class RelationshipSeveranceEvent < ApplicationRecord
  14. self.inheritance_column = nil
  15. has_many :severed_relationships, inverse_of: :relationship_severance_event, dependent: :delete_all
  16. enum :type, {
  17. domain_block: 0,
  18. user_domain_block: 1,
  19. account_suspension: 2,
  20. }
  21. scope :about_local_account, ->(account) { where(id: SeveredRelationship.about_local_account(account).select(:relationship_severance_event_id)) }
  22. def import_from_active_follows!(follows)
  23. import_from_follows!(follows, true)
  24. end
  25. def import_from_passive_follows!(follows)
  26. import_from_follows!(follows, false)
  27. end
  28. def affected_local_accounts
  29. Account.where(id: severed_relationships.select(:local_account_id))
  30. end
  31. private
  32. def import_from_follows!(follows, active)
  33. SeveredRelationship.insert_all(
  34. follows.pluck(:account_id, :target_account_id, :show_reblogs, :notify, :languages).map do |account_id, target_account_id, show_reblogs, notify, languages|
  35. {
  36. local_account_id: active ? account_id : target_account_id,
  37. remote_account_id: active ? target_account_id : account_id,
  38. show_reblogs: show_reblogs,
  39. notify: notify,
  40. languages: languages,
  41. relationship_severance_event_id: id,
  42. direction: active ? :active : :passive,
  43. }
  44. end
  45. )
  46. end
  47. end