Retrospring/app/models/user/relationship/mute.rb

35 lines
1.1 KiB
Ruby
Raw Normal View History

2022-12-27 17:59:51 -08:00
# frozen_string_literal: true
class User
module Relationship
module Mute
extend ActiveSupport::Concern
included do
has_many :active_mute_relationships, class_name: "Relationships::Mute",
2022-12-28 20:17:04 -08:00
foreign_key: "source_id",
dependent: :destroy
2022-12-27 17:59:51 -08:00
has_many :passive_mute_relationships, class_name: "Relationships::Mute",
2022-12-28 20:17:04 -08:00
foreign_key: "target_id",
dependent: :destroy
2022-12-27 17:59:51 -08:00
has_many :muted_users, through: :active_mute_relationships, source: :target
2022-12-28 20:17:04 -08:00
has_many :muted_by_users, through: :passive_mute_relationships, source: :source
2022-12-27 17:59:51 -08:00
end
def mute(target_user)
raise Errors::MutingSelf if target_user == self
create_relationship(active_mute_relationships, target_user)
end
def unmute(target_user)
destroy_relationship(active_mute_relationships, target_user)
end
def muting?(target_user)
relationship_active?(muted_users, target_user)
end
end
end
end