notes

package
v1.6.29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2026 License: AGPL-3.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package notes provides community note scoring algorithms and visibility calculations for content annotation.

Index

Constants

View Source
const (
	// Reputation requirements
	MinReputationToCreateNotes = 100.0
	MinReputationToVote        = 10.0

	// Visibility thresholds
	VisibilityThreshold = 0.5  // Minimum score to be visible
	ProminentThreshold  = 0.75 // Score for prominent display
	DisputeThreshold    = 0.3  // Below this, mark as disputed
	FederationThreshold = 0.7  // Minimum score to federate

	// Federation requirements
	FederationMinRep = 500.0 // Minimum reputation to accept federated notes

	// Rate limits (notes per day based on reputation)
	BaseNoteLimit = 1
	MaxNoteLimit  = 10

	// Content limits
	MaxNoteLength   = 500
	MinNoteLength   = 10
	MaxSources      = 5
	MaxReasonLength = 200

	// TTL
	NoteTTLDays = 90
)

Constants for thresholds and limits

Variables

This section is empty.

Functions

func CalculateNoteLimit

func CalculateNoteLimit(reputation float64) int

CalculateNoteLimit determines how many notes a user can create per day

func CalculateNoteScore

func CalculateNoteScore(note *CommunityNote, votes []Vote) float64

CalculateNoteScore computes visibility score based on multiple factors

func CalculateStats

func CalculateStats(notes []CommunityNote) map[string]any

CalculateStats generates statistics for a set of notes

func CalculateVoteWeight

func CalculateVoteWeight(voterRep float64, voteType VoteType) float64

CalculateVoteWeight determines the weight of a vote based on voter reputation

func GenerateNoteID

func GenerateNoteID() string

GenerateNoteID generates a unique ID for a note using enhanced ULID generation

Types

type Analysis

type Analysis struct {
	Sentiment   float64  `json:"sentiment"`
	Objectivity float64  `json:"objectivity"`
	HasPII      bool     `json:"has_pii"`
	Language    string   `json:"language"`
	Keywords    []string `json:"keywords"`
}

Analysis represents AI analysis results

type CommunityNote

type CommunityNote struct {
	// Identity
	ID         string `json:"id" dynamodbav:"ID"`
	ObjectID   string `json:"object_id" dynamodbav:"ObjectID"`
	ObjectType string `json:"object_type" dynamodbav:"ObjectType"`

	// Author
	AuthorID  string  `json:"author_id" dynamodbav:"AuthorID"`
	AuthorRep float64 `json:"author_reputation" dynamodbav:"AuthorRep"`

	// Content
	Content  string   `json:"content" dynamodbav:"Content"`
	Language string   `json:"language" dynamodbav:"Language"`
	Sources  []Source `json:"sources" dynamodbav:"Sources"`

	// Scoring
	HelpfulVotes     int              `json:"helpful_votes" dynamodbav:"HelpfulVotes"`
	NotHelpfulVotes  int              `json:"not_helpful_votes" dynamodbav:"NotHelpfulVotes"`
	Score            float64          `json:"score" dynamodbav:"Score"`
	VisibilityStatus VisibilityStatus `json:"visibility_status" dynamodbav:"VisibilityStatus"`

	// AI Analysis
	Sentiment     float64 `json:"sentiment" dynamodbav:"Sentiment"`
	Objectivity   float64 `json:"objectivity" dynamodbav:"Objectivity"`
	SourceQuality float64 `json:"source_quality" dynamodbav:"SourceQuality"`

	// Federation
	Federated   bool       `json:"federated" dynamodbav:"Federated"`
	FederatedAt *time.Time `json:"federated_at,omitempty" dynamodbav:"FederatedAt,omitempty"`

	// Metadata
	CreatedAt time.Time `json:"created_at" dynamodbav:"CreatedAt"`
	UpdatedAt time.Time `json:"updated_at" dynamodbav:"UpdatedAt"`
	TTL       int64     `json:"-" dynamodbav:"TTL,omitempty"`
}

CommunityNote represents a fact-checking note on any ActivityPub object

func RankNotesByTrust

func RankNotesByTrust(notes []CommunityNote, _ string, trustScores map[string]float64) []CommunityNote

RankNotesByTrust adjusts note ordering based on viewer's trust relationships

type CreateNoteRequest

type CreateNoteRequest struct {
	ObjectID   string   `json:"object_id" validate:"required"`
	ObjectType string   `json:"object_type" validate:"required"`
	Content    string   `json:"content" validate:"required,min=10,max=500"`
	Language   string   `json:"language" validate:"required,len=2"`
	Sources    []Source `json:"sources" validate:"max=5"`
}

CreateNoteRequest represents a request to create a community note

type NotesResponse

type NotesResponse struct {
	Notes []CommunityNote `json:"notes"`
	Stats map[string]any  `json:"stats"`
}

NotesResponse represents a response containing community notes

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides methods for managing community notes

func NewService

func NewService(storage core.RepositoryStorage, logger *zap.Logger) *Service

NewService creates a new notes service

func (*Service) CheckNoteRateLimit

func (s *Service) CheckNoteRateLimit(ctx context.Context, userID string, limit int) (bool, int)

CheckNoteRateLimit checks if a user can create more notes.

func (*Service) CheckRateLimit

func (s *Service) CheckRateLimit(ctx context.Context, userID string, reputation float64) (bool, int)

CheckRateLimit checks if a user can create more notes

func (*Service) CreateNote

func (s *Service) CreateNote(ctx context.Context, note *CommunityNote) error

CreateNote creates a new community note

func (*Service) GetNote

func (s *Service) GetNote(ctx context.Context, noteID string) (*CommunityNote, error)

GetNote retrieves a note by ID

func (*Service) GetNotesByAuthor

func (s *Service) GetNotesByAuthor(ctx context.Context, authorID string, limit int32) ([]CommunityNote, error)

GetNotesByAuthor retrieves notes created by a specific author

func (*Service) GetUserVotes

func (s *Service) GetUserVotes(ctx context.Context, userID string, noteIDs []string) (map[string]Vote, error)

GetUserVotes retrieves a user's votes on specific notes

func (*Service) GetVisibleNotes

func (s *Service) GetVisibleNotes(ctx context.Context, objectID string) ([]CommunityNote, error)

GetVisibleNotes retrieves visible notes for an object

func (*Service) GetVotesForNote

func (s *Service) GetVotesForNote(ctx context.Context, noteID string) ([]Vote, error)

GetVotesForNote retrieves all votes for a note

func (*Service) RecalculateNoteScore

func (s *Service) RecalculateNoteScore(ctx context.Context, noteID string) error

RecalculateNoteScore recalculates a note's score based on current votes

func (*Service) StoreNote

func (s *Service) StoreNote(ctx context.Context, note *CommunityNote) error

StoreNote stores a community note

func (*Service) StoreVote

func (s *Service) StoreVote(ctx context.Context, vote *Vote) error

StoreVote stores a vote on a note

func (*Service) UpdateNoteScore

func (s *Service) UpdateNoteScore(ctx context.Context, noteID string, score float64, status VisibilityStatus) error

UpdateNoteScore updates a note's score and visibility status

func (*Service) VoteOnNote

func (s *Service) VoteOnNote(ctx context.Context, vote *Vote) error

VoteOnNote records a vote on a note

type Source

type Source struct {
	URL         string  `json:"url" dynamodbav:"URL"`
	Title       string  `json:"title" dynamodbav:"Title"`
	Domain      string  `json:"domain" dynamodbav:"Domain"`
	Reliability float64 `json:"reliability" dynamodbav:"Reliability"`
}

Source represents a reference supporting the note

type VisibilityStatus

type VisibilityStatus string

VisibilityStatus represents the visibility state of a note

const (
	// VisibilityPending represents pending visibility status
	VisibilityPending VisibilityStatus = "pending"
	// VisibilityVisible represents visible visibility status
	VisibilityVisible VisibilityStatus = "visible"
	// VisibilityHidden represents hidden visibility status
	VisibilityHidden VisibilityStatus = "hidden"
	// VisibilityDisputed represents disputed visibility status
	VisibilityDisputed VisibilityStatus = "disputed"
)

func DetermineVisibilityStatus

func DetermineVisibilityStatus(score float64) VisibilityStatus

DetermineVisibilityStatus determines if a note should be visible based on score

type Vote

type Vote struct {
	NoteID    string    `json:"note_id" dynamodbav:"NoteID"`
	VoterID   string    `json:"voter_id" dynamodbav:"VoterID"`
	VoterRep  float64   `json:"voter_reputation" dynamodbav:"VoterRep"`
	VoteType  VoteType  `json:"vote_type" dynamodbav:"VoteType"`
	Reason    string    `json:"reason,omitempty" dynamodbav:"Reason,omitempty"`
	Weight    float64   `json:"weight" dynamodbav:"Weight"`
	CreatedAt time.Time `json:"created_at" dynamodbav:"CreatedAt"`
}

Vote represents a user's vote on a note

type VoteRequest

type VoteRequest struct {
	VoteType VoteType `json:"vote_type" validate:"required,oneof=helpful not_helpful neutral"`
	Reason   string   `json:"reason" validate:"max=200"`
}

VoteRequest represents a request to vote on a community note

type VoteType

type VoteType string

VoteType represents the type of vote on a community note

const (
	// VoteHelpful represents a helpful vote
	VoteHelpful VoteType = "helpful"
	// VoteNotHelpful represents a not helpful vote
	VoteNotHelpful VoteType = "not_helpful"
	// VoteNeutral represents a neutral vote
	VoteNeutral VoteType = "neutral"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL