-
Notifications
You must be signed in to change notification settings - Fork 233
feat(nip56): hide events matching an actionable report #788
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
Open
Priyanshubhartistm
wants to merge
2
commits into
cameri:main
Choose a base branch
from
Priyanshubhartistm:feat/nip56-hide-deprioritize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| "nostream": minor | ||
| --- | ||
|
|
||
| feat: execute hide action for actionable NIP-56 reports | ||
|
|
||
| Adds `nip56.hideActionableReports` (default `false`): when true, events matching an `actionable` | ||
| report (a trusted-moderator report against a valid target) are excluded from REQ/COUNT results. A | ||
| pubkey-targeted report hides every event from that pubkey; an event-targeted report hides just that | ||
| event. Requires `nip56.enabled` to have any effect. Previously an actionable report was only ever | ||
| recorded, never acted on. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
migrations/20260926_120000_add_actionable_reports_indexes.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /** | ||
| * Supports EventRepository.applyActionableReportExclusion's NOT EXISTS | ||
| * subquery (used by findByFilters/countByFilters when | ||
| * nip56.hideActionableReports is enabled): | ||
| * | ||
| * WHERE NOT EXISTS ( | ||
| * SELECT 1 FROM reports | ||
| * WHERE actionable = true | ||
| * AND (reported_event_id = events.event_id OR reported_pubkey = events.event_pubkey) | ||
| * ) | ||
| * | ||
| * Partial on actionable = true since non-actionable reports (the vast | ||
| * majority -- most reporters are not trusted moderators) never participate | ||
| * in this check, matching the existing events_deleted_at_partial_idx | ||
| * precedent for keeping partial indexes small. | ||
| * | ||
| * CREATE INDEX CONCURRENTLY cannot run inside a transaction. | ||
| */ | ||
|
|
||
| exports.config = { transaction: false } | ||
|
|
||
| exports.up = async function (knex) { | ||
| await knex.raw(` | ||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS reports_actionable_reported_event_id_idx | ||
| ON reports (reported_event_id) | ||
| WHERE actionable = true AND reported_event_id IS NOT NULL | ||
| `) | ||
|
|
||
| await knex.raw(` | ||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS reports_actionable_reported_pubkey_idx | ||
| ON reports (reported_pubkey) | ||
| WHERE actionable = true AND reported_pubkey IS NOT NULL | ||
| `) | ||
| } | ||
|
|
||
| exports.down = async function (knex) { | ||
| await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS reports_actionable_reported_event_id_idx') | ||
| await knex.raw('DROP INDEX CONCURRENTLY IF EXISTS reports_actionable_reported_pubkey_idx') | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { EventId, Pubkey } from '../@types/base' | ||
| import { Event } from '../@types/event' | ||
| import { IReportRepository } from '../@types/repositories' | ||
|
|
||
| /** | ||
| * In-memory mirror of actionable-report targets, so EventRepository's | ||
| * NOT-EXISTS-based hiding (which only applies to fresh REQ/COUNT queries) can | ||
| * also be checked synchronously on the live-broadcast path, where events are | ||
| * matched against open subscriptions in-process without a DB round trip. | ||
| */ | ||
| const hiddenPubkeys = new Set<string>() | ||
| const hiddenEventIds = new Set<string>() | ||
|
|
||
| export const markActionableTarget = (target: { reportedPubkey: Pubkey | null; reportedEventId: EventId | null }): void => { | ||
| if (target.reportedPubkey) { | ||
| hiddenPubkeys.add(target.reportedPubkey) | ||
| } | ||
| if (target.reportedEventId) { | ||
| hiddenEventIds.add(target.reportedEventId) | ||
| } | ||
| } | ||
|
|
||
| export const isHidden = (event: Pick<Event, 'id' | 'pubkey'>): boolean => | ||
| hiddenPubkeys.has(event.pubkey) || hiddenEventIds.has(event.id) | ||
|
|
||
| /** Populates the cache from every actionable report already in the DB, at worker boot. */ | ||
| export const warmHiddenContentCache = async (reportRepository: IReportRepository): Promise<void> => { | ||
| const targets = await reportRepository.findActionableTargets() | ||
| targets.forEach(markActionableTarget) | ||
| } | ||
|
|
||
| export const resetHiddenContentCache = (): void => { | ||
| hiddenPubkeys.clear() | ||
| hiddenEventIds.clear() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.