diff --git a/app/controllers/filters_controller.rb b/app/controllers/filters_controller.rb index 769aea2afe5..fa56e52cd8a 100644 --- a/app/controllers/filters_controller.rb +++ b/app/controllers/filters_controller.rb @@ -12,7 +12,7 @@ class FiltersController < ApplicationController def new @filter = current_account.custom_filters.build(action: :warn) - @filter.keywords.build + @filter.keywords.build(resource_params.dig(:keywords_attributes, '0')) end def edit; end diff --git a/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx b/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx index 6707b246728..c485f3c0f55 100644 --- a/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx +++ b/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx @@ -41,12 +41,14 @@ const isHashtagLink = ( interface TargetParams { hashtag?: string; accountId?: string; + hashtagUrl?: URL; } export const HashtagMenuController: React.FC = () => { const intl = useIntl(); const [open, setOpen] = useState(false); - const [{ accountId, hashtag }, setTargetParams] = useState({}); + const [{ accountId, hashtag, hashtagUrl }, setTargetParams] = + useState({}); const targetRef = useRef(null); const location = useLocation(); const account = useAppSelector((state) => @@ -77,11 +79,21 @@ export const HashtagMenuController: React.FC = () => { return; } + const hashtagUrl: URL = new URL('/filters', document.location.href); + hashtagUrl.searchParams.set( + 'custom_filter[keywords_attributes][0][keyword]', + target.text, + ); + hashtagUrl.searchParams.set( + 'custom_filter[keywords_attributes][0][whole_word]', + '1', + ); + e.preventDefault(); e.stopPropagation(); targetRef.current = target; setOpen(true); - setTargetParams({ hashtag, accountId }); + setTargetParams({ hashtag, accountId, hashtagUrl }); }; document.addEventListener('click', handleClick, { capture: true }); @@ -116,11 +128,11 @@ export const HashtagMenuController: React.FC = () => { text: intl.formatMessage(messages.muteHashtag, { hashtag, }), - href: '/filters', + href: hashtagUrl?.toString(), dangerous: true, }, ], - [intl, hashtag, account], + [intl, hashtag, account, hashtagUrl], ); if (!open) {