From 620d0d80293bef80753ecfcec1c4c5226e67cd6d Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 19 May 2017 01:14:30 +0200 Subject: Account domain blocks (#2381) * Add tag to Atom input/output Only uses ref attribute (not href) because href would be the alternate link that's always included also. Creates new conversation for every non-reply status. Carries over conversation for every reply. Keeps remote URIs verbatim, generates local URIs on the fly like the rest of them. * Conversation muting - prevents notifications that reference a conversation (including replies, favourites, reblogs) from being created. API endpoints /api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute Currently no way to tell when a status/conversation is muted, so the web UI only has a "disable notifications" button, doesn't work as a toggle * Display "Dismiss notifications" on all statuses in notifications column, not just own * Add "muted" as a boolean attribute on statuses JSON For now always false on contained reblogs, since it's only relevant for statuses returned from the notifications endpoint, which are not nested Remove "Disable notifications" from detailed status view, since it's only relevant in the notifications column * Up max class length * Remove pending test for conversation mute * Add tests, clean up * Rename to "mute conversation" and "unmute conversation" * Raise validation error when trying to mute/unmute status without conversation * Adding account domain blocks that filter notifications and public timelines * Add tests for domain blocks in notifications, public timelines Filter reblogs of blocked domains from home * Add API for listing and creating account domain blocks * API for creating/deleting domain blocks, tests for Status#ancestors and Status#descendants, filter domain blocks from them * Filter domains in streaming API * Update account_domain_block_spec.rb --- app/models/account.rb | 109 +++----------------------------------------------- 1 file changed, 5 insertions(+), 104 deletions(-) (limited to 'app/models/account.rb') diff --git a/app/models/account.rb b/app/models/account.rb index 03e7db398..f418a0f8b 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -43,6 +43,7 @@ class Account < ApplicationRecord include AccountAvatar include AccountHeader + include AccountInteractions include Attachmentable include Remotable include Targetable @@ -67,26 +68,6 @@ class Account < ApplicationRecord has_many :mentions, inverse_of: :account, dependent: :destroy has_many :notifications, inverse_of: :account, dependent: :destroy - # Follow relations - has_many :follow_requests, dependent: :destroy - - has_many :active_relationships, class_name: 'Follow', foreign_key: 'account_id', dependent: :destroy - has_many :passive_relationships, class_name: 'Follow', foreign_key: 'target_account_id', dependent: :destroy - - has_many :following, -> { order('follows.id desc') }, through: :active_relationships, source: :target_account - has_many :followers, -> { order('follows.id desc') }, through: :passive_relationships, source: :account - - # Block relationships - 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 - has_many :blocked_by_relationships, class_name: 'Block', foreign_key: :target_account_id, dependent: :destroy - has_many :blocked_by, -> { order('blocks.id desc') }, through: :blocked_by_relationships, source: :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 - has_many :conversation_mutes - # Media has_many :media_attachments, dependent: :destroy @@ -120,62 +101,6 @@ class Account < ApplicationRecord delegate :allowed_languages, to: :user, prefix: false, allow_nil: true - def follow!(other_account) - active_relationships.find_or_create_by!(target_account: other_account) - end - - def block!(other_account) - block_relationships.find_or_create_by!(target_account: other_account) - end - - def mute!(other_account) - mute_relationships.find_or_create_by!(target_account: other_account) - end - - def mute_conversation!(conversation) - conversation_mutes.find_or_create_by!(conversation: conversation) - end - - def unfollow!(other_account) - follow = active_relationships.find_by(target_account: other_account) - follow&.destroy - end - - def unblock!(other_account) - block = block_relationships.find_by(target_account: other_account) - block&.destroy - end - - def unmute!(other_account) - mute = mute_relationships.find_by(target_account: other_account) - mute&.destroy - end - - def unmute_conversation!(conversation) - mute = conversation_mutes.find_by(conversation: conversation) - mute&.destroy! - end - - def following?(other_account) - following.include?(other_account) - end - - def blocking?(other_account) - blocking.include?(other_account) - end - - def muting?(other_account) - muting.include?(other_account) - end - - def muting_conversation?(conversation) - conversation_mutes.where(conversation: conversation).exists? - end - - def requested?(other_account) - follow_requests.where(target_account: other_account).exists? - end - def local? domain.nil? end @@ -200,14 +125,6 @@ class Account < ApplicationRecord followers.reorder(nil).pluck('distinct accounts.domain') end - def favourited?(status) - status.proper.favourites.where(account: self).exists? - end - - def reblogged?(status) - status.proper.reblogs.where(account: self).exists? - end - def keypair OpenSSL::PKey::RSA.new(private_key || public_key) end @@ -238,6 +155,10 @@ class Account < ApplicationRecord Rails.cache.fetch("exclude_account_ids_for:#{id}") { blocking.pluck(:target_account_id) + blocked_by.pluck(:account_id) + muting.pluck(:target_account_id) } end + def excluded_from_timeline_domains + Rails.cache.fetch("exclude_domains_for:#{id}") { domain_blocks.pluck(:domain) } + end + class << self def find_local!(username) find_remote!(username, nil) @@ -321,26 +242,6 @@ class Account < ApplicationRecord find_by_sql([sql, account.id, account.id, limit]) end - def following_map(target_account_ids, account_id) - follow_mapping(Follow.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id) - end - - def followed_by_map(target_account_ids, account_id) - follow_mapping(Follow.where(account_id: target_account_ids, target_account_id: account_id), :account_id) - end - - def blocking_map(target_account_ids, account_id) - 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 - private def generate_query_for_search(terms) -- cgit