Skip to content

Commit

Permalink
Fix: #404 フィルターでhalf_warnを設定してると、クライアントアプリでタイムラインが読み込まれない
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Jan 3, 2024
1 parent 7356f77 commit 5d4f1a3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/javascript/mastodon/actions/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function updateNotifications(notification, intlMessages, intlLocale) {
if (['mention', 'status'].includes(notification.type) && notification.status.filtered) {
const filters = notification.status.filtered.filter(result => result.filter.context.includes('notifications'));

if (filters.some(result => result.filter.filter_action === 'hide')) {
if (filters.some(result => result.filter.filter_action_ex === 'hide')) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/components/status.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class Status extends ImmutablePureComponent {
moveDown: this.handleHotkeyMoveDown,
};

if (status.get('filter_action') === 'half_warn') {
if (status.get('filter_action_ex') === 'half_warn') {
return (
<HotKeys handlers={minHandlers}>
<div className='status__wrapper status__wrapper--filtered focusable' tabIndex={0} ref={this.handleRef}>
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/reducers/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const normalizeFilter = (state, filter) => {
title: filter.title,
context: filter.context,
filter_action: filter.filter_action,
filter_action_ex: filter.filter_action_ex,
keywords: filter.keywords,
expires_at: filter.expires_at ? Date.parse(filter.expires_at) : null,
with_quote: filter.with_quote,
Expand Down
5 changes: 3 additions & 2 deletions app/javascript/mastodon/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ export const makeGetStatus = () => {
}
}

if (filterResults.some((result) => filters.getIn([result.get('filter'), 'filter_action']) === 'hide')) {
if (filterResults.some((result) => filters.getIn([result.get('filter'), 'filter_action_ex']) === 'hide')) {
return null;
}
filterResults = filterResults.filter(result => filters.has(result.get('filter')));
if (!filterResults.isEmpty()) {
filtered = filterResults.map(result => filters.getIn([result.get('filter'), 'title']));
filterAction = filterResults.some((result) => filters.getIn([result.get('filter'), 'filter_action']) === 'warn') ? 'warn' : 'half_warn';
filterAction = filterResults.some((result) => filters.getIn([result.get('filter'), 'filter_action_ex']) === 'warn') ? 'warn' : 'half_warn';
}
}

Expand All @@ -72,6 +72,7 @@ export const makeGetStatus = () => {
map.set('account', accountBase);
map.set('matched_filters', filtered);
map.set('filter_action', filterAction);
map.set('filter_action_ex', filterAction);
});
},
);
Expand Down
12 changes: 11 additions & 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, :with_quote, :context, :expires_at, :filter_action
attributes :id, :title, :exclude_follows, :exclude_localusers, :with_quote, :context, :expires_at, :filter_action, :filter_action_ex
has_many :keywords, serializer: REST::FilterKeywordSerializer, if: :rules_requested?
has_many :statuses, serializer: REST::FilterStatusSerializer, if: :rules_requested?

Expand All @@ -12,4 +12,14 @@ def id
def rules_requested?
instance_options[:rules_requested]
end

def filter_action
return :hide if object.half_warn_action?

object.filter_action
end

def filter_action_ex
object.filter_action
end
end
5 changes: 3 additions & 2 deletions streaming/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,9 @@ const startServer = async () => {
// custom_filters.action database column, it is an integer
// representing a value in an enum defined by Ruby on Rails:
//
// enum { warn: 0, hide: 1 }
filter_action: ['warn', 'hide', 'half_warn'][filter.filter_action],
// enum { warn: 0, hide: 1, half_warn: 2 }
filter_action: ['warn', 'hide', 'half_warn'][Math.min(filter.filter_action, 1)],
filter_action_ex: ['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 5d4f1a3

Please sign in to comment.