-
Notifications
You must be signed in to change notification settings - Fork 297
Add hashtag spam filter to automatically mute posts with too many hashtags #3425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ed00301 to
3ff91ad
Compare
|
smol update @jb55 - this one is tested and seems to work well. this is similar to the notedeck hashtag filter you merged damus-io/notedeck#1202 |
📝 WalkthroughWalkthroughTwo new user-configurable settings for hashtag spam filtering were added: a toggle to enable the filter and a parameter for maximum allowed hashtags per post. The new filter function integrates into the content filtering pipeline to exclude posts exceeding the threshold, and UI controls were added to the appearance settings to manage these parameters. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
🧰 Additional context used📓 Path-based instructions (1)**/*.swift📄 CodeRabbit inference engine (AGENTS.md)
Files:
🔇 Additional comments (1)
Comment |
bf73bf9 to
fc1501c
Compare
…htags Posts with more than the configured number of hashtags (default: 3) are now automatically filtered from timelines. This helps reduce hashtag spam. - Add hide_hashtag_spam and max_hashtags settings to UserSettingsStore - Add hashtag_spam_filter that counts hashtags in content text - Add toggle and slider UI in Appearance > Content filters settings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Changelog-Added: Added hashtag spam filter setting to hide posts with too many hashtags Closes: damus-io#1677 Co-Authored-By: Claude Opus 4.5 <[email protected]> Co-Authored-By: William Casarin <[email protected]> Signed-off-by: alltheseas Signed-off-by: William Casarin <[email protected]>
fc1501c to
143bc62
Compare
There was a problem hiding this 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
🤖 Fix all issues with AI Agents
In @damus/Features/Timeline/Models/ContentFilters.swift:
- Around line 57-71: The doc comment for hashtag_spam_filter is inaccurate: the
function only checks ev.referenced_hashtags (the "t" tags) against max_hashtags
and does not scan content text; update the documentation comment above func
hashtag_spam_filter(ev: NostrEvent, max_hashtags: Int) -> Bool to state that it
only enforces a tag-count limit (spam detection based solely on "t"
tags/referenced_hashtags) and remove any mention of scanning hashtags in the
event content. Ensure the comment references ev.referenced_hashtags and
max_hashtags so readers understand the check being performed.
🧹 Nitpick comments (3)
damus/Features/Settings/Models/UserSettingsStore.swift (1)
142-146: Consider adding docstrings for the new settings.Per the coding guidelines, "Ensure docstring coverage for any code added, or modified." While the existing settings in this file lack docstrings, adding them for new properties would improve maintainability and help future developers understand the purpose and expected values.
📝 Suggested docstrings
+ /// Whether to hide posts that contain too many hashtags (spam detection) @Setting(key: "hide_hashtag_spam", default_value: true) var hide_hashtag_spam: Bool + /// Maximum number of hashtags allowed in a post before it's hidden (when hide_hashtag_spam is enabled) @Setting(key: "max_hashtags", default_value: 3) var max_hashtags: Intdamus/Features/Timeline/Models/ContentFilters.swift (1)
60-71: Add docstring for new function.The
hashtag_spam_filterfunction lacks documentation. Per the coding guidelines, "Ensure docstring coverage for any code added, or modified."📝 Suggested docstring
+/// Filters posts with too many hashtags for spam detection. +/// +/// - Parameters: +/// - ev: The NostrEvent to check +/// - max_hashtags: Maximum number of hashtags allowed +/// - Returns: `true` if the post should be shown (hashtag count is within limit), `false` if it should be filtered func hashtag_spam_filter(ev: NostrEvent, max_hashtags: Int) -> Bool {damus/Features/Settings/Views/AppearanceSettingsView.swift (1)
39-45: Consider adding documentation for the binding property.While the binding implementation is correct, adding a brief docstring would improve code clarity, especially since this property bridges between different numeric types (Double ↔ Int).
📝 Suggested docstring
+ /// Binding that bridges the Double-based Slider to the Int-based max_hashtags setting var max_hashtags_binding: Binding<Double> {
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
CHANGELOG.mddamus/Features/Settings/Models/UserSettingsStore.swiftdamus/Features/Settings/Views/AppearanceSettingsView.swiftdamus/Features/Timeline/Models/ContentFilters.swift
🧰 Additional context used
📓 Path-based instructions (1)
**/*.swift
📄 CodeRabbit inference engine (AGENTS.md)
**/*.swift: Maximize usage of nostrdb facilities (Ndb, NdbNote, iterators) whenever possible for persistence and queries in the Damus iOS app
Favor Swift-first solutions that lean on nostrdb types (Ndb, NdbNote, iterators) before introducing new storage mechanisms
Ensure docstring coverage for any code added, or modified
Ensure nevernesting: favor early returns and guard clauses over deeply nested conditionals; simplify control flow by exiting early instead of wrapping logic in multiple layers of if statements
Files:
damus/Features/Timeline/Models/ContentFilters.swiftdamus/Features/Settings/Models/UserSettingsStore.swiftdamus/Features/Settings/Views/AppearanceSettingsView.swift
🔇 Additional comments (2)
damus/Features/Timeline/Models/ContentFilters.swift (1)
116-119: LGTM! Hashtag spam filter integration is correct.The integration of the hashtag spam filter into the content filtering pipeline follows the same pattern as the NSFW filter. The closure correctly captures
max_hashtagsfrom settings and passes it to the filter function.damus/Features/Settings/Views/AppearanceSettingsView.swift (1)
115-122: LGTM! Hashtag spam filter UI implementation is well-structured.The toggle and conditional slider provide a clean, intuitive interface for configuring the hashtag spam filter. The conditional reveal pattern (showing the slider only when the toggle is enabled) is good UX, and the slider range of 1-20 with step 1 is appropriate for the use case.
| /// Filter to hide posts with too many hashtags (spam detection) | ||
| /// Checks both the event's "t" tags and hashtags in content text. | ||
| /// If either exceeds the threshold, the post is filtered. | ||
| func hashtag_spam_filter(ev: NostrEvent, max_hashtags: Int) -> Bool { | ||
| // Check "t" tags count | ||
| var tag_count = 0 | ||
| for _ in ev.referenced_hashtags { | ||
| tag_count += 1 | ||
| if tag_count > max_hashtags { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| return true | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update misleading documentation comment.
The documentation comment at lines 58-59 states that the function "Checks both the event's 't' tags and hashtags in content text," but the implementation only checks ev.referenced_hashtags (the "t" tags). Content text scanning is not performed.
According to the PR description, a follow-up commit by jb55 removed the content filter, noting that "only spam in tags is relevant." The comment should be updated to reflect the actual implementation.
🔎 Proposed fix
/// Filter to hide posts with too many hashtags (spam detection)
-/// Checks both the event's "t" tags and hashtags in content text.
-/// If either exceeds the threshold, the post is filtered.
+/// Checks the event's "t" tags (referenced_hashtags).
+/// If the count exceeds the threshold, the post is filtered.
func hashtag_spam_filter(ev: NostrEvent, max_hashtags: Int) -> Bool {🤖 Prompt for AI Agents
In @damus/Features/Timeline/Models/ContentFilters.swift around lines 57 - 71,
The doc comment for hashtag_spam_filter is inaccurate: the function only checks
ev.referenced_hashtags (the "t" tags) against max_hashtags and does not scan
content text; update the documentation comment above func
hashtag_spam_filter(ev: NostrEvent, max_hashtags: Int) -> Bool to state that it
only enforces a tag-count limit (spam detection based solely on "t"
tags/referenced_hashtags) and remove any mention of scanning hashtags in the
event content. Ensure the comment references ev.referenced_hashtags and
max_hashtags so readers understand the check being performed.
|
thanks! i've cherry-picked this into my integration branch |
Posts with more than the configured number of hashtags (default: 3) are now automatically filtered from timelines. This helps reduce hashtag spam. - Add hide_hashtag_spam and max_hashtags settings to UserSettingsStore - Add hashtag_spam_filter that counts hashtags in content text - Add toggle and slider UI in Appearance > Content filters settings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Changelog-Added: Added hashtag spam filter setting to hide posts with too many hashtags Closes: #3425 Closes: #1677 Co-Authored-By: Claude Opus 4.5 <[email protected]> Co-Authored-By: William Casarin <[email protected]> Signed-off-by: alltheseas Signed-off-by: William Casarin <[email protected]>
Summary
Add a hashtag spam filter that automatically hides posts with too many hashtags from timelines. Posts with more than the configured number of hashtags (default: 3) are filtered out, helping reduce hashtag spam.
Changes:
hide_hashtag_spamsetting (default: enabled) andmax_hashtagssetting (default: 3) to UserSettingsStorehashtag_spam_filterfunction that counts hashtags in content text (works regardless of whether clients add proper["t", "tag"]entries)Checklist
Standard PR Checklist
Closes:orFixes:tags in the commit messages wherever applicable, or made sure those are not needed. See Submitting patchesTest report
Device: iPhone 16 Pro Simulator
iOS: 18.3.1
Damus: ed00301
Setup: Default settings with hashtag spam filter enabled (default)
Steps:
Results:
Other notes
Updated logic now checks both:
Some Nostr clients don't properly populate
["t", "hashtag"]tags.Closes #1677
Summary by CodeRabbit
Release Notes
New Features
✏️ Tip: You can customize this high-level summary in your review settings.