severed_relationship.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: severed_relationships
  5. #
  6. # id :bigint(8) not null, primary key
  7. # relationship_severance_event_id :bigint(8) not null
  8. # local_account_id :bigint(8) not null
  9. # remote_account_id :bigint(8) not null
  10. # direction :integer not null
  11. # show_reblogs :boolean
  12. # notify :boolean
  13. # languages :string is an Array
  14. # created_at :datetime not null
  15. # updated_at :datetime not null
  16. #
  17. class SeveredRelationship < ApplicationRecord
  18. belongs_to :relationship_severance_event
  19. belongs_to :local_account, class_name: 'Account'
  20. belongs_to :remote_account, class_name: 'Account'
  21. enum :direction, {
  22. passive: 0, # analogous to `local_account.passive_relationships`
  23. active: 1, # analogous to `local_account.active_relationships`
  24. }
  25. scope :about_local_account, ->(account) { where(local_account: account) }
  26. scope :about_remote_account, ->(account) { where(remote_account: account) }
  27. scope :active, -> { where(direction: :active) }
  28. scope :passive, -> { where(direction: :passive) }
  29. def account
  30. active? ? local_account : remote_account
  31. end
  32. def target_account
  33. active? ? remote_account : local_account
  34. end
  35. end