Skip to content

Add support for filtering on commented_by current user#4348

Open
elisescu wants to merge 1 commit intomainfrom
fix2377
Open

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

Conversation

@elisescu
Copy link
Contributor

@elisescu elisescu commented Feb 13, 2026

Should close #2377

Summary by CodeRabbit

Release Notes

  • New Features
    • Added a "commented" filter option enabling users to view posts they have commented on.
    • Extended language support with translations in Czech, English, Spanish, Portuguese, Traditional Chinese, and Simplified Chinese.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

This PR introduces a "commented" filter feature for the question feed. It adds translation entries in six language files, extends frontend filter components to include a commented-by filter option, and adds backend support in the serializer and feed service to filter posts by user comments.

Changes

Cohort / File(s) Summary
Translation Entries
front_end/messages/cs.json, front_end/messages/en.json, front_end/messages/es.json, front_end/messages/pt.json, front_end/messages/zh-TW.json, front_end/messages/zh.json
Added localized "commented" translation key across six language files with region-appropriate values (Komentováno, Commented, Comentado, Comentado, 已評論, 已評論).
Frontend Filter Components
front_end/src/app/(main)/questions/helpers/filters.ts, front_end/src/components/tournament_filters.tsx
Introduced new POST_COMMENTED_BY_FILTER filter option to participation filters, setting label to "commented" and value to current user ID, mirroring existing filter patterns.
Backend Filter Support
posts/serializers.py, posts/services/feed.py
Added commented_by optional integer field to PostFilterSerializer and implemented commented_by parameter in get_posts_feed service to filter posts by comments from specified user ID.

Sequence Diagram

sequenceDiagram
    actor User
    participant Frontend
    participant API/Serializer
    participant FeedService
    participant Database

    User->>Frontend: Select "commented" filter
    Frontend->>Frontend: Encode POST_COMMENTED_BY_FILTER in URL params
    Frontend->>API/Serializer: POST request with commented_by user_id
    API/Serializer->>API/Serializer: Validate commented_by field
    API/Serializer->>FeedService: Call get_posts_feed(commented_by=user_id)
    FeedService->>FeedService: Filter queryset by comments__author_id
    FeedService->>FeedService: Apply distinct() to avoid duplicates
    FeedService->>Database: Query posts with matching comments
    Database-->>FeedService: Return filtered results
    FeedService-->>API/Serializer: Return post list
    API/Serializer-->>Frontend: Return serialized posts
    Frontend-->>User: Display filtered questions
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A filter so keen, for comments I've seen,
Through questions that prompted my voice,
Six languages strong, the translations along,
My participation—my choice! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding support for filtering by the 'commented_by' field for the current user.
Linked Issues check ✅ Passed The PR successfully implements the requirement from issue #2377 by adding a 'commented' filter to the my participation section, enabling users to filter feed by questions they've commented on.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the 'commented_by' filter feature; no unrelated modifications or refactoring are present.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 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

🚀 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-edde2ac
🗄️ PostgreSQL NeonDB branch preview/pr-4348-fix2377
Redis Fly Redis mtc-redis-pr-4348-fix2377

Details

  • Commit: 2452bf1f800667781fefafd48add65fbcadf6a2d
  • 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.

"includeBotsTooltip": "U této otázky přispívají předpovědi robotů k předpovědi komunity. <link>Další informace o srovnávání AI</link>",
"authored": "Vytvořeno",
"upvoted": "Kladně hodnoceno",
"commented": "Komentováno",
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 | 🟠 Major

Duplicate "commented" key overwrites the earlier translation.

Line 394 introduces a second "commented" entry (the file already defines "commented": "komentovali" around Line 114). JSON will keep the last value, which can silently change other UI strings. Please use a distinct key for the filter label (e.g., searchOptionCommented) and update the UI to reference it.

🔧 Suggested key rename
-  "commented": "Komentováno",
+  "searchOptionCommented": "Komentováno",
📝 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": "Komentováno",
"searchOptionCommented": "Komentováno",
🤖 Prompt for AI Agents
In `@front_end/messages/cs.json` at 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.

"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": "Para esta pergunta, previsões de bots contribuem para a Previsão da Comunidade. <link>Saiba mais sobre Benchmarking de IA</link>",
"authored": "Criado",
"upvoted": "Curtido",
"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 | 🟠 Major

Duplicate "commented" key overwrites the earlier translation.

This file already defines "commented": "comentou" (around Line 132). Adding a second "commented" at Line 426 will override the earlier value. Please use a distinct key for the filter label (e.g., searchOptionCommented) and update the UI to reference it.

🔧 Suggested key rename
-  "commented": "Comentado",
+  "searchOptionCommented": "Comentado",
📝 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": "Comentado",
"searchOptionCommented": "Comentado",
🤖 Prompt for AI Agents
In `@front_end/messages/pt.json` at 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).

"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.

"includeBots": "包括機器人",
"includeBotsTooltip": "對於這個問題,機器人預測有助於社群預測。<link>了解更多有關 AI 基準測試的資訊</link>",
"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 398 repeats a key already defined at Line 112, 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.json` at 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.

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

1 participant