diff options
author | Fire Demon <firedemon@creature.cafe> | 2020-09-17 12:05:45 -0500 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-09-17 12:08:35 -0500 |
commit | e56e3d187f8ddd3db72fc90c5d200f552d5c1c04 (patch) | |
tree | 59204082c7f9731d301716f08865f8639149452c | |
parent | 4a1b8bcf34ce834ee8c30f1ac94c29f4e56a2b41 (diff) |
[Filters] Merge thread muting and hiding into a single action
-rw-r--r-- | app/controllers/api/v1/statuses/mutes_controller.rb | 2 | ||||
-rw-r--r-- | app/lib/feed_manager.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/account_interactions.rb | 10 | ||||
-rw-r--r-- | app/models/status.rb | 6 | ||||
-rw-r--r-- | app/presenters/status_relationships_presenter.rb | 8 | ||||
-rw-r--r-- | app/serializers/rest/status_serializer.rb | 9 | ||||
-rw-r--r-- | app/services/mute_conversation_service.rb | 6 | ||||
-rw-r--r-- | db/migrate/20200720211530_add_hidden_to_conversation_mute.rb | 7 | ||||
-rw-r--r-- | streaming/index.js | 2 |
9 files changed, 12 insertions, 40 deletions
diff --git a/app/controllers/api/v1/statuses/mutes_controller.rb b/app/controllers/api/v1/statuses/mutes_controller.rb index 73d9df734..418c19840 100644 --- a/app/controllers/api/v1/statuses/mutes_controller.rb +++ b/app/controllers/api/v1/statuses/mutes_controller.rb @@ -9,7 +9,7 @@ class Api::V1::Statuses::MutesController < Api::BaseController before_action :set_conversation def create - MuteConversationService.new.call(current_account, @status.conversation, hidden: truthy_param?(:hide)) + MuteConversationService.new.call(current_account, @status.conversation) @mutes_map = { @conversation.id => true } render json: @status, serializer: REST::StatusSerializer diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index 4659f6c4d..4e34e3b61 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -494,7 +494,7 @@ class FeedManager crutches[:muting] = Mute.where(account_id: receiver_id, target_account_id: check_for_blocks).pluck(:target_account_id).each_with_object({}) { |id, mapping| mapping[id] = true } crutches[:domain_blocking] = AccountDomainBlock.where(account_id: receiver_id, domain: statuses.map { |s| s.reblog&.account&.domain }.compact).pluck(:domain).each_with_object({}) { |domain, mapping| mapping[domain] = true } crutches[:blocked_by] = Block.where(target_account_id: receiver_id, account_id: statuses.map { |s| s.reblog&.account_id }.compact).pluck(:account_id).each_with_object({}) { |id, mapping| mapping[id] = true } - crutches[:hiding_thread] = ConversationMute.where(account_id: receiver_id, conversation_id: statuses.map(&:conversation_id).compact, hidden: true).pluck(:conversation_id).each_with_object({}) { |id, mapping| mapping[id] = true } + crutches[:hiding_thread] = ConversationMute.where(account_id: receiver_id, conversation_id: statuses.map(&:conversation_id).compact).pluck(:conversation_id).each_with_object({}) { |id, mapping| mapping[id] = true } crutches end diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb index 538e92f41..cf8e638e7 100644 --- a/app/models/concerns/account_interactions.rb +++ b/app/models/concerns/account_interactions.rb @@ -138,10 +138,8 @@ module AccountInteractions mute end - def mute_conversation!(conversation, hidden: false) - mute = conversation_mutes.find_or_create_by!(conversation: conversation) - mute.update(hidden: hidden) if hidden.present? && mute.hidden? != hidden - mute + def mute_conversation!(conversation) + conversation_mutes.find_or_create_by!(conversation: conversation) end def block_domain!(other_domain) @@ -202,10 +200,6 @@ module AccountInteractions conversation_mutes.where(conversation: conversation).exists? end - def hiding_conversation?(conversation) - conversation_mutes.where(conversation: conversation, hidden: true).exists? - end - def muting_notifications?(other_account) mute_relationships.where(target_account: other_account, hide_notifications: true).exists? end diff --git a/app/models/status.rb b/app/models/status.rb index 1a98f12c3..83ab58418 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -144,7 +144,7 @@ class Status < ApplicationRecord scope :ready_to_publish, -> { unpublished.where('statuses.publish_at IS NOT NULL AND statuses.publish_at < ?', Time.now.utc) } scope :not_hidden_by_account, ->(account) do - left_outer_joins(:mutes, :conversation_mute).where('(status_mutes.account_id IS NULL OR status_mutes.account_id != ?) AND (conversation_mutes.account_id IS NULL OR (conversation_mutes.account_id != ? AND conversation_mutes.hidden = TRUE))', account.id, account.id) + left_outer_joins(:mutes, :conversation_mute).where('(status_mutes.account_id IS NULL OR status_mutes.account_id != ?) AND (conversation_mutes.account_id IS NULL OR conversation_mutes.account_id != ?)', account.id, account.id) end cache_associated :application, @@ -484,10 +484,6 @@ class Status < ApplicationRecord ConversationMute.select('conversation_id').where(conversation_id: conversation_ids).where(account_id: account_id).each_with_object({}) { |m, h| h[m.conversation_id] = true } end - def hidden_conversations_map(conversation_ids, account_id) - ConversationMute.select('conversation_id').where(conversation_id: conversation_ids, hidden: true).where(account_id: account_id).each_with_object({}) { |m, h| h[m.conversation_id] = true } - end - def hidden_statuses_map(status_ids, account_id) StatusMute.select('status_id').where(status_id: status_ids).where(account_id: account_id).each_with_object({}) { |m, h| h[m.status_id] = true } end diff --git a/app/presenters/status_relationships_presenter.rb b/app/presenters/status_relationships_presenter.rb index 260ea48fe..d898a9188 100644 --- a/app/presenters/status_relationships_presenter.rb +++ b/app/presenters/status_relationships_presenter.rb @@ -4,7 +4,7 @@ class StatusRelationshipsPresenter attr_reader :reblogs_map, :favourites_map, :mutes_map, :pins_map, :bookmarks_map - attr_reader :hidden_conversations_map, :hidden_statuses_map + attr_reader :hidden_statuses_map def initialize(statuses, current_account_id = nil, **options) if current_account_id.nil? @@ -14,8 +14,7 @@ class StatusRelationshipsPresenter @mutes_map = {} @pins_map = {} - @hidden_conversations_map = {} - @hidden_statuses_map = {} + @hidden_statuses_map = {} else statuses = statuses.compact status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.uniq.compact @@ -28,8 +27,7 @@ class StatusRelationshipsPresenter @mutes_map = Status.mutes_map(conversation_ids, current_account_id).merge(options[:mutes_map] || {}) @pins_map = Status.pins_map(pinnable_status_ids, current_account_id).merge(options[:pins_map] || {}) - @hidden_conversations_map = Status.hidden_conversations_map(conversation_ids, current_account_id).merge(options[:hidden_conversations_map] || {}) - @hidden_statuses_map = Status.hidden_statuses_map(status_ids, current_account_id).merge(options[:hidden_statuses_map] || {}) + @hidden_statuses_map = Status.hidden_statuses_map(status_ids, current_account_id).merge(options[:hidden_statuses_map] || {}) end end end diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb index c172a37af..39d812185 100644 --- a/app/serializers/rest/status_serializer.rb +++ b/app/serializers/rest/status_serializer.rb @@ -22,7 +22,6 @@ class REST::StatusSerializer < ActiveModel::Serializer attribute :published if :local? attribute :hidden, if: :current_user? - attribute :conversation_hidden, if: :current_user? attribute :notify, if: :locally_owned? attribute :title?, key: :article attribute :article_content, if: :title? @@ -140,14 +139,6 @@ class REST::StatusSerializer < ActiveModel::Serializer end end - def conversation_hidden - if instance_options && instance_options[:relationships] - instance_options[:relationships].hidden_conversations_map[object.conversation_id] || false - else - current_user.account.hiding_conversation?(object.conversation) - end - end - def hidden if instance_options && instance_options[:relationships] instance_options[:relationships].hidden_statuses_map[object.id] || false diff --git a/app/services/mute_conversation_service.rb b/app/services/mute_conversation_service.rb index 46adb98dc..56defae52 100644 --- a/app/services/mute_conversation_service.rb +++ b/app/services/mute_conversation_service.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true class MuteConversationService < BaseService - def call(account, conversation, hidden: false) + def call(account, conversation) return if account.blank? || conversation.blank? - account.mute_conversation!(conversation, hidden: hidden) - MuteConversationWorker.perform_async(account.id, conversation.id) if hidden + account.mute_conversation!(conversation) + MuteConversationWorker.perform_async(account.id, conversation.id) unless account.id == conversation.account_id end end diff --git a/db/migrate/20200720211530_add_hidden_to_conversation_mute.rb b/db/migrate/20200720211530_add_hidden_to_conversation_mute.rb deleted file mode 100644 index aa7b31d8b..000000000 --- a/db/migrate/20200720211530_add_hidden_to_conversation_mute.rb +++ /dev/null @@ -1,7 +0,0 @@ -class AddHiddenToConversationMute < ActiveRecord::Migration[5.2] - def change - safety_assured do - add_column :conversation_mutes, :hidden, :boolean, default: false, null: false - end - end -end diff --git a/streaming/index.js b/streaming/index.js index 3a68e6de5..62f6b5fe0 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -578,7 +578,7 @@ const startWorker = (workerId) => { } const queries = [ - client.query(`SELECT 1 FROM blocks WHERE (account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 2)})) OR (account_id = $2 AND target_account_id = $1) UNION SELECT 1 FROM mutes WHERE account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 2)})`, [req.accountId, unpackedPayload.account.id].concat(targetAccountIds)), + client.query(`SELECT 1 FROM blocks WHERE (account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 4)})) OR (account_id = $2 AND target_account_id = $1) UNION SELECT 1 FROM mutes WHERE account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 4)}) UNION SELECT 1 FROM conversation_mutes WHERE account_id = $1 AND conversation_id = $3 UNION SELECT 1 FROM status_mutes WHERE account_id = $1 AND status_id = $4`, [req.accountId, unpackedPayload.account.id, unpackedPayload.conversation_id, unpackedPayload.id].concat(targetAccountIds)), ]; if (accountDomain) { |