From e1ac510c655933f3c86613436aaf69bd1186dbe3 Mon Sep 17 00:00:00 2001 From: KMY Date: Mon, 2 Oct 2023 11:58:12 +0900 Subject: [PATCH] =?UTF-8?q?=E7=B7=A8=E9=9B=86=E6=99=82=E3=81=AB=E3=83=95?= =?UTF-8?q?=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=81=8C=E6=A9=9F=E8=83=BD?= =?UTF-8?q?=E3=81=97=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/mastodon/reducers/filters.js | 1 + app/javascript/mastodon/selectors/index.js | 19 ++++++++++++++++++- app/serializers/rest/filter_serializer.rb | 2 +- streaming/index.js | 5 +++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/javascript/mastodon/reducers/filters.js b/app/javascript/mastodon/reducers/filters.js index 566ad0c6ca3486..28f0c3e6e4877b 100644 --- a/app/javascript/mastodon/reducers/filters.js +++ b/app/javascript/mastodon/reducers/filters.js @@ -11,6 +11,7 @@ const normalizeFilter = (state, filter) => { filter_action: filter.filter_action, keywords: filter.keywords, expires_at: filter.expires_at ? Date.parse(filter.expires_at) : null, + with_quote: filter.with_quote, }); if (is(state.get(filter.id), normalizedFilter)) { diff --git a/app/javascript/mastodon/selectors/index.js b/app/javascript/mastodon/selectors/index.js index 9446b77c7fcb6e..aaf22a0588821b 100644 --- a/app/javascript/mastodon/selectors/index.js +++ b/app/javascript/mastodon/selectors/index.js @@ -37,12 +37,14 @@ export const makeGetStatus = () => { [ (state, { id }) => state.getIn(['statuses', id]), (state, { id }) => state.getIn(['statuses', state.getIn(['statuses', id, 'reblog'])]), + (state, { id }) => state.getIn(['statuses', state.getIn(['statuses', id, 'quote_id'])]), (state, { id }) => state.getIn(['accounts', state.getIn(['statuses', id, 'account'])]), (state, { id }) => state.getIn(['accounts', state.getIn(['statuses', state.getIn(['statuses', id, 'reblog']), 'account'])]), + (state, { id }) => state.getIn(['accounts', state.getIn(['statuses', state.getIn(['statuses', id, 'quote_id']), 'account'])]), getFilters, ], - (statusBase, statusReblog, accountBase, accountReblog, filters) => { + (statusBase, statusReblog, statusQuote, accountBase, accountReblog, accountQuote, filters) => { if (!statusBase || statusBase.get('isLoading')) { return null; } @@ -53,6 +55,12 @@ export const makeGetStatus = () => { statusReblog = null; } + if (statusQuote) { + statusQuote = statusQuote.set('account', accountQuote); + } else { + statusQuote = null; + } + if (hideBlockingQuote && statusBase.getIn(['quote', 'quote_muted'])) { return null; } @@ -61,6 +69,14 @@ export const makeGetStatus = () => { let filterAction = 'warn'; if ((accountReblog || accountBase).get('id') !== me && filters) { let filterResults = statusReblog?.get('filtered') || statusBase.get('filtered') || ImmutableList(); + const quoteFilterResults = statusQuote?.get('filtered'); + if (quoteFilterResults) { + const filterWithQuote = quoteFilterResults.some((result) => filters.getIn([result.get('filter'), 'with_quote'])); + if (filterWithQuote) { + filterResults = filterResults.concat(quoteFilterResults); + } + } + if (filterResults.some((result) => filters.getIn([result.get('filter'), 'filter_action']) === 'hide')) { return null; } @@ -73,6 +89,7 @@ export const makeGetStatus = () => { return statusBase.withMutations(map => { map.set('reblog', statusReblog); + map.set('quote', statusQuote); map.set('account', accountBase); map.set('matched_filters', filtered); map.set('filter_action', filterAction); diff --git a/app/serializers/rest/filter_serializer.rb b/app/serializers/rest/filter_serializer.rb index 1b5d70dffda750..08fadda5827a0a 100644 --- a/app/serializers/rest/filter_serializer.rb +++ b/app/serializers/rest/filter_serializer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class REST::FilterSerializer < ActiveModel::Serializer - attributes :id, :title, :exclude_follows, :exclude_localusers, :context, :expires_at, :filter_action + attributes :id, :title, :exclude_follows, :exclude_localusers, :with_quote, :context, :expires_at, :filter_action has_many :keywords, serializer: REST::FilterKeywordSerializer, if: :rules_requested? has_many :statuses, serializer: REST::FilterStatusSerializer, if: :rules_requested? diff --git a/streaming/index.js b/streaming/index.js index b31da1fa7a4a4c..f0bdf436be7ca1 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -864,7 +864,7 @@ const startServer = async () => { } if (!payload.filtered && !req.cachedFilters) { - queries.push(client.query('SELECT filter.id AS id, filter.phrase AS title, filter.context AS context, filter.expires_at AS expires_at, filter.action AS filter_action, keyword.keyword AS keyword, keyword.whole_word AS whole_word, filter.exclude_follows AS exclude_follows, filter.exclude_localusers AS exclude_localusers FROM custom_filter_keywords keyword JOIN custom_filters filter ON keyword.custom_filter_id = filter.id WHERE filter.account_id = $1 AND (filter.expires_at IS NULL OR filter.expires_at > NOW())', [req.accountId])); + queries.push(client.query('SELECT filter.id AS id, filter.phrase AS title, filter.context AS context, filter.expires_at AS expires_at, filter.action AS filter_action, filter.with_quote AS with_quote, keyword.keyword AS keyword, keyword.whole_word AS whole_word, filter.exclude_follows AS exclude_follows, filter.exclude_localusers AS exclude_localusers FROM custom_filter_keywords keyword JOIN custom_filters filter ON keyword.custom_filter_id = filter.id WHERE filter.account_id = $1 AND (filter.expires_at IS NULL OR filter.expires_at > NOW())', [req.accountId])); } if (!payload.filtered) { queries.push(client.query(`SELECT 1 @@ -913,7 +913,8 @@ const startServer = async () => { // representing a value in an enum defined by Ruby on Rails: // // enum { warn: 0, hide: 1 } - filter_action: ['warn', 'hide'][filter.filter_action], + filter_action: ['warn', 'hide', 'half_warn'][filter.filter_action], + with_quote: filter.with_quote, excludeFollows: filter.exclude_follows, excludeLocalusers: filter.exclude_localusers, },