Mute button progress so far. WIP, doesn't entirely work correctly.
This commit is contained in:
parent
89fc2d7f48
commit
442fdbfc53
26 changed files with 390 additions and 33 deletions
|
@ -46,6 +46,10 @@ class Account < ApplicationRecord
|
|||
has_many :block_relationships, class_name: 'Block', foreign_key: 'account_id', dependent: :destroy
|
||||
has_many :blocking, -> { order('blocks.id desc') }, through: :block_relationships, source: :target_account
|
||||
|
||||
# Mute relationships
|
||||
has_many :mute_relationships, class_name: 'Mute', foreign_key: 'account_id', dependent: :destroy
|
||||
has_many :muting, -> { order('mutes.id desc') }, through: :mute_relationships, source: :target_account
|
||||
|
||||
# Media
|
||||
has_many :media_attachments, dependent: :destroy
|
||||
|
||||
|
@ -73,6 +77,10 @@ class Account < ApplicationRecord
|
|||
block_relationships.where(target_account: other_account).first_or_create!(target_account: other_account)
|
||||
end
|
||||
|
||||
def mute!(other_account)
|
||||
mute_relationships.where(target_account: other_account).first_or_create!(target_account: other_account)
|
||||
end
|
||||
|
||||
def unfollow!(other_account)
|
||||
follow = active_relationships.find_by(target_account: other_account)
|
||||
follow&.destroy
|
||||
|
@ -83,6 +91,11 @@ class Account < ApplicationRecord
|
|||
block&.destroy
|
||||
end
|
||||
|
||||
def unmute!(other_account)
|
||||
mute = mute_relationships.find_by(target_account: other_account)
|
||||
mute&.destroy
|
||||
end
|
||||
|
||||
def following?(other_account)
|
||||
following.include?(other_account)
|
||||
end
|
||||
|
@ -91,6 +104,10 @@ class Account < ApplicationRecord
|
|||
blocking.include?(other_account)
|
||||
end
|
||||
|
||||
def muting?(other_account)
|
||||
muting.include?(other_account)
|
||||
end
|
||||
|
||||
def requested?(other_account)
|
||||
follow_requests.where(target_account: other_account).exists?
|
||||
end
|
||||
|
@ -188,6 +205,10 @@ class Account < ApplicationRecord
|
|||
follow_mapping(Block.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id)
|
||||
end
|
||||
|
||||
def muting_map(target_account_ids, account_id)
|
||||
follow_mapping(Mute.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id)
|
||||
end
|
||||
|
||||
def requested_map(target_account_ids, account_id)
|
||||
follow_mapping(FollowRequest.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id)
|
||||
end
|
||||
|
|
32
app/models/mute.rb
Normal file
32
app/models/mute.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Mute < ApplicationRecord
|
||||
include Paginable
|
||||
include Streamable
|
||||
|
||||
belongs_to :account
|
||||
belongs_to :target_account, class_name: 'Account'
|
||||
|
||||
validates :account, :target_account, presence: true
|
||||
validates :account_id, uniqueness: { scope: :target_account_id }
|
||||
|
||||
def verb
|
||||
destroyed? ? :unmute : :mute
|
||||
end
|
||||
|
||||
def target
|
||||
target_account
|
||||
end
|
||||
|
||||
def object_type
|
||||
:person
|
||||
end
|
||||
|
||||
def hidden?
|
||||
true
|
||||
end
|
||||
|
||||
def title
|
||||
destroyed? ? "#{account.acct} is no longer muting #{target_account.acct}" : "#{account.acct} muted #{target_account.acct}"
|
||||
end
|
||||
end
|
|
@ -103,7 +103,10 @@ class Status < ApplicationRecord
|
|||
|
||||
class << self
|
||||
def as_home_timeline(account)
|
||||
where(account: [account] + account.following)
|
||||
muted = Mute.where(account: account).pluck(:target_account_id)
|
||||
query = where(account: [account] + account.following)
|
||||
query = query.where('statuses.account_id NOT IN (?)', muted) unless muted.empty?
|
||||
query
|
||||
end
|
||||
|
||||
def as_public_timeline(account = nil, local_only = false)
|
||||
|
@ -169,8 +172,10 @@ class Status < ApplicationRecord
|
|||
|
||||
def filter_timeline(query, account)
|
||||
blocked = Block.where(account: account).pluck(:target_account_id) + Block.where(target_account: account).pluck(:account_id)
|
||||
query = query.where('statuses.account_id NOT IN (?)', blocked) unless blocked.empty?
|
||||
query = query.where('accounts.silenced = TRUE') if account.silenced?
|
||||
muted = Mute.where(account: account).pluck(:target_account_id)
|
||||
query = query.where('statuses.account_id NOT IN (?)', blocked) unless blocked.empty? # Only give us statuses from people we haven't blocked
|
||||
query = query.where('statuses.account_id NOT IN (?)', muted) unless muted.empty? # and out of those, only people we haven't muted
|
||||
query = query.where('accounts.silenced = TRUE') if account.silenced? # and if we're hellbanned, only people who are also hellbanned
|
||||
query
|
||||
end
|
||||
|
||||
|
@ -192,6 +197,6 @@ class Status < ApplicationRecord
|
|||
private
|
||||
|
||||
def filter_from_context?(status, account)
|
||||
account&.blocking?(status.account_id) || (status.account.silenced? && !account&.following?(status.account_id)) || !status.permitted?(account)
|
||||
account&.blocking?(status.account_id) || account&.muting?(status.account_id) || (status.account.silenced? && !account&.following?(status.account_id)) || !status.permitted?(account)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue