Add mute relationship and user methods
This commit is contained in:
parent
6e30bc73cf
commit
361b8df798
|
@ -0,0 +1,4 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Relationships::Mute < Relationship
|
||||||
|
end
|
|
@ -4,6 +4,7 @@ class User < ApplicationRecord
|
||||||
include User::Relationship
|
include User::Relationship
|
||||||
include User::Relationship::Follow
|
include User::Relationship::Follow
|
||||||
include User::Relationship::Block
|
include User::Relationship::Block
|
||||||
|
include User::Relationship::Mute
|
||||||
include User::AnswerMethods
|
include User::AnswerMethods
|
||||||
include User::BanMethods
|
include User::BanMethods
|
||||||
include User::InboxMethods
|
include User::InboxMethods
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "errors"
|
||||||
|
|
||||||
|
class User
|
||||||
|
module Relationship
|
||||||
|
module Mute
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
has_many :active_mute_relationships, class_name: "Relationships::Mute",
|
||||||
|
foreign_key: "source_id",
|
||||||
|
dependent: :destroy
|
||||||
|
has_many :passive_mute_relationships, class_name: "Relationships::Mute",
|
||||||
|
foreign_key: "target_id",
|
||||||
|
dependent: :destroy
|
||||||
|
has_many :muted_users, through: :active_mute_relationships, source: :target
|
||||||
|
has_many :muted_by_users, through: :passive_mute_relationships, source: :source
|
||||||
|
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
|
|
@ -119,4 +119,7 @@ module Errors
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
|
class MutingSelf < SelfAction
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue