Skip to content

Add support for filtering on commented_by current user#4348

Open
elisescu wants to merge 2 commits intomainfrom
fix2377
Open

Add support for filtering on commented_by current user#4348
elisescu wants to merge 2 commits intomainfrom
fix2377

Conversation

@elisescu
Copy link
Contributor

@elisescu elisescu commented Feb 13, 2026

Should close #2377

Summary by CodeRabbit

  • New Features
    • Added a new "commented" filter option. Users can now filter posts to display only those they have commented on, extending the existing participation filter selections.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

This PR adds a new "commented" filter to the feed filter menu, enabling users to filter posts by questions they've commented on. The feature is implemented across frontend filter configuration, backend serializer field declaration, and feed service filtering logic.

Changes

Cohort / File(s) Summary
Frontend Filter Configuration
front_end/src/app/(main)/questions/helpers/filters.ts, front_end/src/components/tournament_filters.tsx
Introduces POST_COMMENTED_BY_FILTER as a new participation filter option with label "commented" and active state derived from URL parameters, extending existing filter sections for both question helpers and tournament components.
Backend Filter Support
posts/serializers.py, posts/services/feed.py
Adds commented_by optional integer field to PostFilterSerializer and implements filtering logic in get_posts_feed that queries posts containing comments by the specified user ID using distinct filtering on comments__author_id.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A filter for comments, now hopping through,
Questions you've talked on, all just for you,
From frontend to backend, the path stays so clear,
One simple addition brings participation near! 🌱

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main feature: adding support for filtering the feed by posts the current user has commented on.
Linked Issues check ✅ Passed The code changes implement the requirement from issue #2377 to add a 'my participation' > 'commented' filter option across all necessary components.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the commented_by filter feature; no extraneous modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix2377

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 13, 2026

🚀 Preview Environment

Your preview environment is ready!

Resource Details
🌐 Preview URL https://metaculus-pr-4348-fix2377-preview.mtcl.cc
📦 Docker Image ghcr.io/metaculus/metaculus:fix2377-f1758c4
🗄️ PostgreSQL NeonDB branch preview/pr-4348-fix2377
Redis Fly Redis mtc-redis-pr-4348-fix2377

Details

  • Commit: f1758c4a431edd4280ed481a27f25759e708c612
  • Branch: fix2377
  • Fly App: metaculus-pr-4348-fix2377

ℹ️ Preview Environment Info

Isolation:

  • PostgreSQL and Redis are fully isolated from production
  • Each PR gets its own database branch and Redis instance
  • Changes pushed to this PR will trigger a new deployment

Limitations:

  • Background workers and cron jobs are not deployed in preview environments
  • If you need to test background jobs, use Heroku staging environments

Cleanup:

  • This preview will be automatically destroyed when the PR is closed

@elisescu
Copy link
Contributor Author

@coderabbitai review again

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

@elisescu, I'll review the changes in this PR.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🤖 Fix all issues with AI agents
In `@front_end/messages/cs.json`:
- Line 394: The JSON contains a duplicate "commented" key that overwrites the
earlier translation ("komentovali"); rename the new entry to a unique key such
as "searchOptionCommented" (or another clear name) and update any UI code that
references the filter label to use "searchOptionCommented" instead of
"commented"; also verify the original "commented" key (value "komentovali")
remains unchanged and update any tests or components that expected the previous
overwritten value to use the new distinct key.

In `@front_end/messages/en.json`:
- Line 549: The JSON contains a duplicate "commented" key which overrides the
earlier entry; change this duplicate key to a distinct name such as
"commentedFilter" and update any code/UI references that read the filter label
to use "commentedFilter" (search for usages of the "commented" key that relate
to filter labels and replace them to avoid key collision); ensure the original
"commented" key remains unchanged so casing/values elsewhere are preserved.

In `@front_end/messages/es.json`:
- Line 401: Duplicate JSON key "commented" is defined twice causing the filter
label to overwrite the activity-feed value; change the filter occurrence (the
capitalized label currently using the second "commented" key) to a distinct key
name following convention, e.g., "searchOptionCommented", update the value to
the capitalized label and mirror the same key rename across all locale files
(en.json, es.json, cs.json, pt.json, zh-TW.json, zh.json) so the activity-feed
"commented" key remains the lowercase activity string and the new
"searchOptionCommented" key is used for the filter label.

In `@front_end/messages/pt.json`:
- Line 426: The duplicate JSON key "commented" overwrites the earlier
translation; replace the second occurrence with a distinct key (e.g.,
"searchOptionCommented") and update any UI code that uses the filter label to
reference "searchOptionCommented" instead of "commented"; ensure you keep the
original "commented": "comentou" entry intact, add "searchOptionCommented":
"Comentado" (or appropriate translation) where the filter label is needed, and
search for usages of the "commented" key in components to update references to
the new key (e.g., in filter components or i18n lookup calls).

In `@front_end/messages/zh-TW.json`:
- Line 454: The JSON file contains a duplicate key "commented" (second
occurrence at the reviewed diff) that will override the earlier translation;
rename this duplicate key to a distinct identifier such as "commentedFilter" and
update all places that reference this translation key (e.g., UI components or
i18n lookups that currently use "commented") to use the new key name; ensure the
new key's value remains "已評論" (or an appropriate filter label) and run the i18n
build/validation to confirm no other duplicate keys remain.

In `@front_end/messages/zh.json`:
- Line 398: The translation file contains a duplicate key "commented" which
overrides the earlier entry; rename the filter label key to a distinct name (for
example "commentedFilter") in the JSON and update all code references that read
the translation (e.g., any usages of the "commented" key in UI components, i18n
lookup calls, or filter label renderers) to use the new key "commentedFilter" so
both translations coexist without conflict.
🧹 Nitpick comments (1)
posts/services/feed.py (1)

51-51: Nit: PEP 484 discourages implicit Optional.

Static analysis (RUF013) flags commented_by: int = None — the modern annotation is int | None = None. This is a pre-existing pattern across all parameters in this function, so no need to fix it in this PR alone.

"includeBotsInAggregatesExplanation": "When enabled, bot forecasts will be included in aggregate calculations for this question and will affect scoring. Otherwise, they will affect neither.",
"authored": "Authored",
"upvoted": "Upvoted",
"commented": "Commented",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Avoid duplicate “commented” key collisions.
Line 549 redefines an existing key already present at Line 214. In most JSON loaders, the later value overrides the earlier one, so existing UI strings may change casing unexpectedly. Please use a distinct key for the filter label (e.g., commentedFilter) and update references accordingly.

🔧 Suggested fix
-  "commented": "Commented",
+  "commentedFilter": "Commented",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"commented": "Commented",
"commentedFilter": "Commented",
🤖 Prompt for AI Agents
In `@front_end/messages/en.json` at line 549, The JSON contains a duplicate
"commented" key which overrides the earlier entry; change this duplicate key to
a distinct name such as "commentedFilter" and update any code/UI references that
read the filter label to use "commentedFilter" (search for usages of the
"commented" key that relate to filter labels and replace them to avoid key
collision); ensure the original "commented" key remains unchanged so
casing/values elsewhere are preserved.

"includeBotsTooltip": "Para esta pregunta, los pronósticos de los bots contribuyen a la predicción de la comunidad. <link>Obtenga más información sobre la evaluación comparativa de IA</link>",
"authored": "Autoría",
"upvoted": "Votado positivamente",
"commented": "Comentado",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

fd -e json . front_end/messages/ | head -20

Repository: Metaculus/metaculus

Length of output: 260


🏁 Script executed:

grep -n '"commented"' front_end/messages/es.json

Repository: Metaculus/metaculus

Length of output: 126


🏁 Script executed:

sed -n '110,120p' front_end/messages/es.json

Repository: Metaculus/metaculus

Length of output: 574


🏁 Script executed:

sed -n '398,405p' front_end/messages/es.json

Repository: Metaculus/metaculus

Length of output: 454


🏁 Script executed:

grep -E '"search.*?": "' front_end/messages/es.json | head -10

Repository: Metaculus/metaculus

Length of output: 472


🏁 Script executed:

sed -n '395,410p' front_end/messages/es.json

Repository: Metaculus/metaculus

Length of output: 927


🏁 Script executed:

grep -n '"authored"\|"upvoted"\|"moderating"' front_end/messages/es.json

Repository: Metaculus/metaculus

Length of output: 165


🏁 Script executed:

sed -n '110,125p' front_end/messages/es.json | cat -n

Repository: Metaculus/metaculus

Length of output: 915


🏁 Script executed:

# Check if "commented" key is used elsewhere in the codebase
rg '"commented"' front_end/ --type json --type js --type ts -c

Repository: Metaculus/metaculus

Length of output: 397


🏁 Script executed:

# Verify the exact structure - is this really a JSON object with duplicate keys?
head -5 front_end/messages/es.json && echo "..." && tail -5 front_end/messages/es.json

Repository: Metaculus/metaculus

Length of output: 414


🏁 Script executed:

# Check how "commented" is used in the codebase
rg -B2 -A2 '"commented"' front_end/src/components/tournament_filters.tsx

Repository: Metaculus/metaculus

Length of output: 240


🏁 Script executed:

rg -B2 -A2 '"commented"' front_end/src/components/comment_feed/comment.tsx

Repository: Metaculus/metaculus

Length of output: 254


🏁 Script executed:

rg -B2 -A2 '"commented"' front_end/src/app/\(main\)/questions/helpers/filters.ts

Repository: Metaculus/metaculus

Length of output: 230


🏁 Script executed:

# Check the structure of line 401-402 context more clearly with broader range
sed -n '395,415p' front_end/messages/es.json | nl -v 395

Repository: Metaculus/metaculus

Length of output: 105


🏁 Script executed:

sed -n '395,415p' front_end/messages/es.json

Repository: Metaculus/metaculus

Length of output: 1275


🏁 Script executed:

# Check all locale files for duplicate "commented" key
for f in front_end/messages/*.json; do
  count=$(grep -c '"commented"' "$f")
  echo "$(basename $f): $count occurrences"
  grep -n '"commented"' "$f"
  echo
done

Repository: Metaculus/metaculus

Length of output: 600


Duplicate JSON key "commented" breaks existing translations across all locale files.

Both line 114 and line 401 define the same key "commented", causing the second occurrence to override the first at parse time. This affects all seven locale files identically:

  • en.json: lines 214 and 549
  • es.json: lines 114 and 401
  • cs.json: lines 114 and 394
  • pt.json: lines 132 and 426
  • zh-TW.json: lines 150 and 454
  • zh.json: lines 112 and 398

Line 114's lowercase values ("comentado", "commented", etc.) are used for activity feed display (e.g., "replied", "commented" actions). Line 401's capitalized values are filter labels. The second occurrence silently overwrites the first, breaking activity notifications.

Use a distinct key for the filter option, following the naming convention: "searchOptionCommented".

🤖 Prompt for AI Agents
In `@front_end/messages/es.json` at line 401, Duplicate JSON key "commented" is
defined twice causing the filter label to overwrite the activity-feed value;
change the filter occurrence (the capitalized label currently using the second
"commented" key) to a distinct key name following convention, e.g.,
"searchOptionCommented", update the value to the capitalized label and mirror
the same key rename across all locale files (en.json, es.json, cs.json, pt.json,
zh-TW.json, zh.json) so the activity-feed "commented" key remains the lowercase
activity string and the new "searchOptionCommented" key is used for the filter
label.

"includeBotsTooltip": "對於此問題,機器人預測構成社區預測的一部分。<link>瞭解更多關於 AI 基準測試</link>",
"authored": "著作",
"upvoted": "點贊",
"commented": "已評論",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Duplicate “commented” key overrides existing translation.
Line 454 repeats a key already defined at Line 150, which will override the earlier value in most JSON parsers. Please use a distinct key for the filter label (e.g., commentedFilter) and update references accordingly.

🔧 Suggested fix
-  "commented": "已評論",
+  "commentedFilter": "已評論",
🤖 Prompt for AI Agents
In `@front_end/messages/zh-TW.json` at line 454, The JSON file contains a
duplicate key "commented" (second occurrence at the reviewed diff) that will
override the earlier translation; rename this duplicate key to a distinct
identifier such as "commentedFilter" and update all places that reference this
translation key (e.g., UI components or i18n lookups that currently use
"commented") to use the new key name; ensure the new key's value remains "已評論"
(or an appropriate filter label) and run the i18n build/validation to confirm no
other duplicate keys remain.

)

if commented_by:
qs = qs.filter(comments__author_id=commented_by).distinct()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have a distinct at the bottom:

return qs.distinct("id", order_type).only("pk")

However, I suspect this could be pretty slow for users with a lot of comments. Could you compare performance against an Exists-based approach, especially for cases with many comments?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@posts/services/feed.py`:
- Line 51: The parameter annotation commented_by: int = None creates an implicit
Optional and should be made explicit to satisfy RUF013; update the function
signature (where commented_by is defined) to use typing.Optional[int] (or
Union[int, None]) and add the corresponding import from typing (Optional) at the
top of posts/services/feed.py so the annotation is explicit.

show_on_homepage: bool = None,
following: bool = None,
upvoted_by: int = None,
commented_by: int = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix implicit Optional annotation flagged by Ruff (RUF013).

🛠 Proposed fix
-    commented_by: int = None,
+    commented_by: int | None = None,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
commented_by: int = None,
commented_by: int | None = None,
🧰 Tools
🪛 Ruff (0.15.1)

[warning] 51-51: PEP 484 prohibits implicit Optional

Convert to T | None

(RUF013)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@posts/services/feed.py` at line 51, The parameter annotation commented_by:
int = None creates an implicit Optional and should be made explicit to satisfy
RUF013; update the function signature (where commented_by is defined) to use
typing.Optional[int] (or Union[int, None]) and add the corresponding import from
typing (Optional) at the top of posts/services/feed.py so the annotation is
explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filter feed by questions you've commented

3 participants