mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Compare commits
4 commits
38a10f1c59
...
d8e0714ec4
Author | SHA1 | Date | |
---|---|---|---|
|
d8e0714ec4 | ||
|
a50c8e951f | ||
|
2c1e75727d | ||
|
8733975f13 |
10 changed files with 40 additions and 36 deletions
|
@ -29,5 +29,7 @@ class Api::V1::TagsController < Api::BaseController
|
||||||
return not_found unless Tag::HASHTAG_NAME_RE.match?(params[:id])
|
return not_found unless Tag::HASHTAG_NAME_RE.match?(params[:id])
|
||||||
|
|
||||||
@tag = Tag.find_normalized(params[:id]) || Tag.new(name: Tag.normalize(params[:id]), display_name: params[:id])
|
@tag = Tag.find_normalized(params[:id]) || Tag.new(name: Tag.normalize(params[:id]), display_name: params[:id])
|
||||||
|
|
||||||
|
not_found unless @tag.usable?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Api::V1::Timelines::TagController < Api::V1::Timelines::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_tag
|
def load_tag
|
||||||
@tag = Tag.find_normalized(params[:id])
|
@tag = Tag.usable.find_normalized(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_statuses
|
def load_statuses
|
||||||
|
|
|
@ -60,7 +60,7 @@ export interface BaseNotificationGroupJSON {
|
||||||
|
|
||||||
interface NotificationGroupWithStatusJSON extends BaseNotificationGroupJSON {
|
interface NotificationGroupWithStatusJSON extends BaseNotificationGroupJSON {
|
||||||
type: NotificationWithStatusType;
|
type: NotificationWithStatusType;
|
||||||
status: ApiStatusJSON;
|
status_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NotificationWithStatusJSON extends BaseNotificationJSON {
|
interface NotificationWithStatusJSON extends BaseNotificationJSON {
|
||||||
|
|
|
@ -49,21 +49,14 @@ export const FilteredNotificationsBanner: React.FC = () => {
|
||||||
<span>
|
<span>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='filtered_notifications_banner.pending_requests'
|
id='filtered_notifications_banner.pending_requests'
|
||||||
defaultMessage='Notifications from {count, plural, =0 {no one} one {one person} other {# people}} you may know'
|
defaultMessage='From {count, plural, =0 {no one} one {one person} other {# people}} you may know'
|
||||||
values={{ count: policy.summary.pending_requests_count }}
|
values={{ count: policy.summary.pending_requests_count }}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='filtered-notifications-banner__badge'>
|
<div className='filtered-notifications-banner__badge'>
|
||||||
<div className='filtered-notifications-banner__badge__badge'>
|
{toCappedNumber(policy.summary.pending_notifications_count)}
|
||||||
{toCappedNumber(policy.summary.pending_notifications_count)}
|
|
||||||
</div>
|
|
||||||
<FormattedMessage
|
|
||||||
id='filtered_notifications_banner.mentions'
|
|
||||||
defaultMessage='{count, plural, one {mention} other {mentions}}'
|
|
||||||
values={{ count: policy.summary.pending_notifications_count }}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
|
|
|
@ -300,8 +300,7 @@
|
||||||
"filter_modal.select_filter.subtitle": "Use an existing category or create a new one",
|
"filter_modal.select_filter.subtitle": "Use an existing category or create a new one",
|
||||||
"filter_modal.select_filter.title": "Filter this post",
|
"filter_modal.select_filter.title": "Filter this post",
|
||||||
"filter_modal.title.status": "Filter a post",
|
"filter_modal.title.status": "Filter a post",
|
||||||
"filtered_notifications_banner.mentions": "{count, plural, one {mention} other {mentions}}",
|
"filtered_notifications_banner.pending_requests": "From {count, plural, =0 {no one} one {one person} other {# people}} you may know",
|
||||||
"filtered_notifications_banner.pending_requests": "Notifications from {count, plural, =0 {no one} one {one person} other {# people}} you may know",
|
|
||||||
"filtered_notifications_banner.title": "Filtered notifications",
|
"filtered_notifications_banner.title": "Filtered notifications",
|
||||||
"firehose.all": "All",
|
"firehose.all": "All",
|
||||||
"firehose.local": "This server",
|
"firehose.local": "This server",
|
||||||
|
|
|
@ -124,9 +124,9 @@ export function createNotificationGroupFromJSON(
|
||||||
case 'mention':
|
case 'mention':
|
||||||
case 'poll':
|
case 'poll':
|
||||||
case 'update': {
|
case 'update': {
|
||||||
const { status, ...groupWithoutStatus } = group;
|
const { status_id: statusId, ...groupWithoutStatus } = group;
|
||||||
return {
|
return {
|
||||||
statusId: status.id,
|
statusId,
|
||||||
sampleAccountIds,
|
sampleAccountIds,
|
||||||
...groupWithoutStatus,
|
...groupWithoutStatus,
|
||||||
};
|
};
|
||||||
|
|
|
@ -10171,25 +10171,10 @@ noscript {
|
||||||
}
|
}
|
||||||
|
|
||||||
&__badge {
|
&__badge {
|
||||||
display: flex;
|
background: $ui-button-background-color;
|
||||||
align-items: center;
|
color: $white;
|
||||||
border-radius: 999px;
|
border-radius: 100px;
|
||||||
background: var(--background-border-color);
|
padding: 2px 8px;
|
||||||
color: $darker-text-color;
|
|
||||||
padding: 4px;
|
|
||||||
padding-inline-end: 8px;
|
|
||||||
gap: 6px;
|
|
||||||
font-weight: 500;
|
|
||||||
font-size: 11px;
|
|
||||||
line-height: 16px;
|
|
||||||
word-break: keep-all;
|
|
||||||
|
|
||||||
&__badge {
|
|
||||||
background: $ui-button-background-color;
|
|
||||||
color: $white;
|
|
||||||
border-radius: 100px;
|
|
||||||
padding: 2px 8px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
class Query
|
class Query
|
||||||
|
attr_reader :keywords
|
||||||
|
|
||||||
def initialize(clauses, options = {})
|
def initialize(clauses, options = {})
|
||||||
raise ArgumentError if options[:current_account].nil?
|
raise ArgumentError if options[:current_account].nil?
|
||||||
|
|
||||||
|
@ -20,6 +22,7 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
@options = options
|
@options = options
|
||||||
|
|
||||||
flags_from_clauses!
|
flags_from_clauses!
|
||||||
|
keywords_from_clauses!
|
||||||
end
|
end
|
||||||
|
|
||||||
def request
|
def request
|
||||||
|
@ -42,6 +45,10 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
@flags = clauses_by_operator.fetch(:flag, []).to_h { |clause| [clause.prefix, clause.term] }
|
@flags = clauses_by_operator.fetch(:flag, []).to_h { |clause| [clause.prefix, clause.term] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def keywords_from_clauses!
|
||||||
|
@keywords = must_clauses.flat_map(&:keywords).uniq
|
||||||
|
end
|
||||||
|
|
||||||
def must_clauses
|
def must_clauses
|
||||||
clauses_by_operator.fetch(:must, [])
|
clauses_by_operator.fetch(:must, [])
|
||||||
end
|
end
|
||||||
|
@ -128,6 +135,10 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
{ multi_match: { type: 'most_fields', query: @term, fields: ['text', 'text.stemmed'], operator: 'and' } }
|
{ multi_match: { type: 'most_fields', query: @term, fields: ['text', 'text.stemmed'], operator: 'and' } }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def keywords
|
||||||
|
@term.split
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class PhraseClause
|
class PhraseClause
|
||||||
|
@ -141,6 +152,10 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
def to_query
|
def to_query
|
||||||
{ match_phrase: { text: { query: @phrase } } }
|
{ match_phrase: { text: { query: @phrase } } }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def keywords
|
||||||
|
@phrase.split
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class PrefixClause
|
class PrefixClause
|
||||||
|
@ -193,6 +208,10 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def keywords
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def account_id_from_term(term)
|
def account_id_from_term(term)
|
||||||
|
|
|
@ -25,6 +25,8 @@ class StatusesSearchService < BaseService
|
||||||
private
|
private
|
||||||
|
|
||||||
def status_search_results
|
def status_search_results
|
||||||
|
return [] if contains_forbidden_terms?
|
||||||
|
|
||||||
request = parsed_query.request
|
request = parsed_query.request
|
||||||
results = request.collapse(field: :id).order(id: { order: :desc }).limit(@limit).offset(@offset).objects.compact
|
results = request.collapse(field: :id).order(id: { order: :desc }).limit(@limit).offset(@offset).objects.compact
|
||||||
account_ids = results.map(&:account_id)
|
account_ids = results.map(&:account_id)
|
||||||
|
@ -37,7 +39,7 @@ class StatusesSearchService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def parsed_query
|
def parsed_query
|
||||||
SearchQueryTransformer.new.apply(SearchQueryParser.new.parse(@query), current_account: @account)
|
@parsed_query ||= SearchQueryTransformer.new.apply(SearchQueryParser.new.parse(@query), current_account: @account)
|
||||||
end
|
end
|
||||||
|
|
||||||
def convert_deprecated_options!
|
def convert_deprecated_options!
|
||||||
|
@ -60,4 +62,8 @@ class StatusesSearchService < BaseService
|
||||||
|
|
||||||
@query = "#{@query} #{syntax_options.join(' ')}".strip if syntax_options.any?
|
@query = "#{@query} #{syntax_options.join(' ')}".strip if syntax_options.any?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def contains_forbidden_terms?
|
||||||
|
Tag.where(usable: false).matching_name(parsed_query.keywords).exists?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,7 @@ class TagSearchService < BaseService
|
||||||
|
|
||||||
normalized_query = Tag.normalize(@query)
|
normalized_query = Tag.normalize(@query)
|
||||||
exact_match = results.find { |tag| tag.name.downcase == normalized_query }
|
exact_match = results.find { |tag| tag.name.downcase == normalized_query }
|
||||||
exact_match ||= Tag.find_normalized(normalized_query)
|
exact_match ||= Tag.listable.find_normalized(normalized_query)
|
||||||
unless exact_match.nil?
|
unless exact_match.nil?
|
||||||
results.delete(exact_match)
|
results.delete(exact_match)
|
||||||
results = [exact_match] + results
|
results = [exact_match] + results
|
||||||
|
|
Loading…
Reference in a new issue