From 81512ab4ca7ff4a75c20657170a1b615865fa264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Sun, 22 Jun 2025 00:29:06 +0200 Subject: [PATCH 01/15] Add URL query params to "Mute hashtags" request to /filters --- .../mastodon/features/ui/components/hashtag_menu_controller.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..5fa647e5e3f 100644 --- a/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx +++ b/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx @@ -116,7 +116,7 @@ export const HashtagMenuController: React.FC = () => { text: intl.formatMessage(messages.muteHashtag, { hashtag, }), - href: '/filters', + href: `/filters?custom_filter[keywords_attributes][0][keyword]=${hashtag}&custom_filter[keywords_attributes][0][whole_word]=1`, dangerous: true, }, ], From 6af65171f8e38baf00615a5ba9607a222dc67651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Sun, 22 Jun 2025 01:40:27 +0200 Subject: [PATCH 02/15] Prefix hashtag text with URL-encoded hashtag character --- .../mastodon/features/ui/components/hashtag_menu_controller.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5fa647e5e3f..08e2cf344ac 100644 --- a/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx +++ b/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx @@ -116,7 +116,7 @@ export const HashtagMenuController: React.FC = () => { text: intl.formatMessage(messages.muteHashtag, { hashtag, }), - href: `/filters?custom_filter[keywords_attributes][0][keyword]=${hashtag}&custom_filter[keywords_attributes][0][whole_word]=1`, + href: `/filters?custom_filter[keywords_attributes][0][keyword]=%23${hashtag}&custom_filter[keywords_attributes][0][whole_word]=1`, dangerous: true, }, ], From 5b98c1ba42a59607bb57a370fc69a779a340f3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Sun, 22 Jun 2025 02:04:56 +0200 Subject: [PATCH 03/15] Pass pre-filled URL query params to keywords association build to be pre-filled into the creation form --- app/controllers/filters_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/filters_controller.rb b/app/controllers/filters_controller.rb index 769aea2afe5..fc612dc93f4 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(params[:keywords]) end def edit; end From 3f8b83ee59361a5268131ab449f27c5766b37c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Sun, 22 Jun 2025 02:24:29 +0200 Subject: [PATCH 04/15] Fix URL query param access --- app/controllers/filters_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/filters_controller.rb b/app/controllers/filters_controller.rb index fc612dc93f4..20363ce387e 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(params[:keywords]) + @filter.keywords.build(params.dig(:custom_filter, :keywords_attributes)) end def edit; end From f69352fe56eb514a5f77b34c999dcf5d553bd793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Tue, 24 Jun 2025 13:33:00 +0200 Subject: [PATCH 05/15] Use native escaping for hashtag URL --- .../features/ui/components/hashtag_menu_controller.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 08e2cf344ac..a928fa6945b 100644 --- a/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx +++ b/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx @@ -77,6 +77,10 @@ export const HashtagMenuController: React.FC = () => { return; } + hashtagUrl = new URL('/filters', document.location) + 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; @@ -116,7 +120,7 @@ export const HashtagMenuController: React.FC = () => { text: intl.formatMessage(messages.muteHashtag, { hashtag, }), - href: `/filters?custom_filter[keywords_attributes][0][keyword]=%23${hashtag}&custom_filter[keywords_attributes][0][whole_word]=1`, + href: hashtagUrl.toString(), dangerous: true, }, ], From c6bef7522beba97e000e82ad29236d91417921e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Tue, 24 Jun 2025 17:35:41 +0200 Subject: [PATCH 06/15] Use validated resource_params instead of plain params MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … as well as properly fill :keywords_attributes as collection rather than single model Co-authored-by: Claire See: https://github.com/mastodon/mastodon/pull/35133#discussion_r2163366096 Co-authored-by: Claire --- app/controllers/filters_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/filters_controller.rb b/app/controllers/filters_controller.rb index 20363ce387e..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(params.dig(:custom_filter, :keywords_attributes)) + @filter.keywords.build(resource_params.dig(:keywords_attributes, '0')) end def edit; end From 70e595cb79eae4882094f90967a303637763f59b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Tue, 24 Jun 2025 22:24:07 +0200 Subject: [PATCH 07/15] fix const assignment --- .../mastodon/features/ui/components/hashtag_menu_controller.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a928fa6945b..94c8d79b188 100644 --- a/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx +++ b/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx @@ -77,7 +77,7 @@ export const HashtagMenuController: React.FC = () => { return; } - hashtagUrl = new URL('/filters', document.location) + const hashtagUrl = new URL('/filters', document.location) hashtagUrl.searchParams.set('custom_filter[keywords_attributes][0][keyword]', target.text) hashtagUrl.searchParams.set('custom_filter[keywords_attributes][0][whole_word]', 1) From f70f096cae68642103e108bb337a72f4efd3ad56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 25 Jun 2025 13:25:55 +0200 Subject: [PATCH 08/15] Explicitly type variable See https://github.com/mastodon/mastodon/actions/runs/15860724453 --- .../mastodon/features/ui/components/hashtag_menu_controller.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 94c8d79b188..2069c3b5d15 100644 --- a/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx +++ b/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx @@ -77,7 +77,7 @@ export const HashtagMenuController: React.FC = () => { return; } - const hashtagUrl = new URL('/filters', document.location) + const hashtagUrl: URL = new URL('/filters', document.location) hashtagUrl.searchParams.set('custom_filter[keywords_attributes][0][keyword]', target.text) hashtagUrl.searchParams.set('custom_filter[keywords_attributes][0][whole_word]', 1) From 59abde12ee45b507cfdbd4b997d1f61817e3f9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Wed, 25 Jun 2025 13:30:21 +0200 Subject: [PATCH 09/15] Pass hashtagUrl variable to useMemo() as dependency See https://github.com/mastodon/mastodon/actions/runs/15860724453 --- .../mastodon/features/ui/components/hashtag_menu_controller.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2069c3b5d15..83e59b22ee0 100644 --- a/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx +++ b/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx @@ -124,7 +124,7 @@ export const HashtagMenuController: React.FC = () => { dangerous: true, }, ], - [intl, hashtag, account], + [intl, hashtag, account, hashtagUrl], ); if (!open) { From 35662387d2e2310d22cff3d2a6007d431469015f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= Date: Wed, 25 Jun 2025 23:00:20 +0200 Subject: [PATCH 10/15] Revert "Pass hashtagUrl variable to useMemo() as dependency" This reverts commit 59abde12ee45b507cfdbd4b997d1f61817e3f9a5. --- .../mastodon/features/ui/components/hashtag_menu_controller.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 83e59b22ee0..2069c3b5d15 100644 --- a/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx +++ b/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx @@ -124,7 +124,7 @@ export const HashtagMenuController: React.FC = () => { dangerous: true, }, ], - [intl, hashtag, account, hashtagUrl], + [intl, hashtag, account], ); if (!open) { From fc18ec8bc1fe9f5b1114d18918d98b56db9be675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 26 Jun 2025 03:49:06 +0200 Subject: [PATCH 11/15] Fix variable types --- .../features/ui/components/hashtag_menu_controller.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 2069c3b5d15..cb4dcb40ee6 100644 --- a/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx +++ b/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx @@ -77,9 +77,9 @@ export const HashtagMenuController: React.FC = () => { return; } - const hashtagUrl: URL = new URL('/filters', document.location) + 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) + hashtagUrl.searchParams.set('custom_filter[keywords_attributes][0][whole_word]', '1') e.preventDefault(); e.stopPropagation(); From 1e672ae66e13073b2793262379e08d2473893695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 26 Jun 2025 03:49:41 +0200 Subject: [PATCH 12/15] fix: :bug: Add hashtagUrl to target params so that the variable is avialable outside of useEffect() --- .../features/ui/components/hashtag_menu_controller.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 cb4dcb40ee6..7a3a1dcd133 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,13 @@ 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) => @@ -85,7 +86,7 @@ export const HashtagMenuController: React.FC = () => { e.stopPropagation(); targetRef.current = target; setOpen(true); - setTargetParams({ hashtag, accountId }); + setTargetParams({ hashtag, accountId, hashtagUrl }); }; document.addEventListener('click', handleClick, { capture: true }); From f9f7018639b92c91f2873bcfcf47f56ec8d25af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 26 Jun 2025 03:51:02 +0200 Subject: [PATCH 13/15] Linter --- .../ui/components/hashtag_menu_controller.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 7a3a1dcd133..0c552287e7e 100644 --- a/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx +++ b/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx @@ -47,7 +47,8 @@ interface TargetParams { export const HashtagMenuController: React.FC = () => { const intl = useIntl(); const [open, setOpen] = useState(false); - const [{ accountId, hashtag, hashtagUrl }, setTargetParams] = useState({}); + const [{ accountId, hashtag, hashtagUrl }, setTargetParams] = + useState({}); const targetRef = useRef(null); const location = useLocation(); const account = useAppSelector((state) => @@ -78,9 +79,15 @@ 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') + 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(); From 418e5617cc5832658d44c234899c7957beb4bd32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 26 Jun 2025 03:53:49 +0200 Subject: [PATCH 14/15] 'hashtagUrl' is possibly 'undefined' --- .../mastodon/features/ui/components/hashtag_menu_controller.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0c552287e7e..54c807cdd39 100644 --- a/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx +++ b/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx @@ -128,7 +128,7 @@ export const HashtagMenuController: React.FC = () => { text: intl.formatMessage(messages.muteHashtag, { hashtag, }), - href: hashtagUrl.toString(), + href: hashtagUrl?.toString(), dangerous: true, }, ], From aa51b2ba37f20b0d8054de7692db388caad529f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 26 Jun 2025 03:54:59 +0200 Subject: [PATCH 15/15] Pass hashtagUrl variable to useMemo() as dependency Redo 59abde1 --- .../mastodon/features/ui/components/hashtag_menu_controller.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 54c807cdd39..c485f3c0f55 100644 --- a/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx +++ b/app/javascript/mastodon/features/ui/components/hashtag_menu_controller.tsx @@ -132,7 +132,7 @@ export const HashtagMenuController: React.FC = () => { dangerous: true, }, ], - [intl, hashtag, account], + [intl, hashtag, account, hashtagUrl], ); if (!open) {