Skip to content

Commit

Permalink
編集時にフィルターが機能しない問題を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Oct 2, 2023
1 parent 44b739a commit e1ac510
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/javascript/mastodon/reducers/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
19 changes: 18 additions & 1 deletion app/javascript/mastodon/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/rest/filter_serializer.rb
Original file line number Diff line number Diff line change
@@ -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?

Expand Down
5 changes: 3 additions & 2 deletions streaming/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit e1ac510

Please sign in to comment.