Documentation
¶
Overview ¶
Package threads provides thread synchronization and traversal services
Index ¶
- Constants
- Variables
- func ValidateNoteURL(noteURL string) error
- type ActorRepository
- type FederationClient
- type ObjectRepository
- type Publisher
- type Service
- func (s *Service) FindThreadRoot(ctx context.Context, note *activitypub.Note) (*activitypub.Note, []*activitypub.Note, error)
- func (s *Service) GetThreadContext(ctx context.Context, query ThreadContextQuery) (*ThreadContextResult, error)
- func (s *Service) SyncMissingReplies(ctx context.Context, cmd SyncMissingRepliesCommand) (*SyncMissingRepliesResult, error)
- func (s *Service) SyncRemoteThread(ctx context.Context, cmd SyncRemoteThreadCommand) (*SyncRemoteThreadResult, error)
- type StatusRepository
- type SyncMissingRepliesCommand
- type SyncMissingRepliesResult
- type SyncRemoteThreadCommand
- type SyncRemoteThreadResult
- type ThreadContextQuery
- type ThreadContextResult
- type ThreadRepository
Constants ¶
const ( MaxThreadDepth = 10 // Maximum depth for thread traversal DefaultDepth = 3 // Default depth for sync operations // Sync status constants SyncStatusNone = "NONE" SyncStatusComplete = "COMPLETE" SyncStatusPartial = "PARTIAL" SyncStatusFailed = "FAILED" SyncStatusSyncing = "SYNCING" )
Constants for thread operations
Variables ¶
var ( // Thread traversal errors ErrThreadNotFound = errors.New("thread not found") ErrThreadRootNotFound = errors.New("thread root not found") ErrCircularReference = errors.New("circular reference detected in thread") ErrMaxDepthExceeded = errors.New("maximum thread depth exceeded") ErrInvalidThreadStructure = errors.New("invalid thread structure") // Federation errors ErrFetchRemoteNote = errors.New("failed to fetch remote note") ErrFetchRemoteReplies = errors.New("failed to fetch remote replies") ErrRemoteNoteNotFound = errors.New("remote note not found") ErrRemoteInstanceUnreachable = errors.New("remote instance unreachable") ErrRemoteAuthFailed = errors.New("remote authentication failed") ErrRemoteTimeout = errors.New("remote request timeout") // Sync errors ErrSyncInProgress = errors.New("sync already in progress for this thread") ErrSyncFailed = errors.New("thread synchronization failed") ErrPartialSync = errors.New("thread synchronization partially completed") ErrSyncMissingReplies = errors.New("failed to sync missing replies") // Storage errors ErrSaveThreadNode = errors.New("failed to save thread node") ErrSaveThreadSync = errors.New("failed to save thread sync record") ErrGetThreadContext = errors.New("failed to get thread context") ErrMarkMissingReply = errors.New("failed to mark missing reply") // Validation errors ErrInvalidNoteID = errors.New("invalid note ID") ErrInvalidNoteURL = errors.New("invalid note URL") ErrInvalidDepth = errors.New("invalid depth parameter") ErrMissingRequiredParam = errors.New("missing required parameter") // Note type errors ErrNotANote = errors.New("object is not a note") ErrInvalidNoteStructure = errors.New("note has invalid structure") )
Service-level errors for thread operations
Functions ¶
func ValidateNoteURL ¶
ValidateNoteURL validates and normalizes a note URL
Types ¶
type ActorRepository ¶
type ActorRepository interface {
GetActorByUsername(ctx context.Context, username string) (*activitypub.Actor, error)
}
ActorRepository defines the interface for actor operations
type FederationClient ¶
type FederationClient interface {
FetchObject(ctx context.Context, objectURL string, signingActor *activitypub.Actor) (any, error)
}
FederationClient defines the interface for federation operations
type ObjectRepository ¶
type ObjectRepository interface {
GetObject(ctx context.Context, objectID string) (any, error)
CreateObject(ctx context.Context, object any) error
}
ObjectRepository defines the interface for object storage operations
type Publisher ¶
type Publisher interface {
PublishToStream(ctx context.Context, stream string, event *streaming.Event) error
}
Publisher defines the interface for event publishing
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides thread synchronization and traversal operations
func NewService ¶
func NewService( threadRepo ThreadRepository, statusRepo StatusRepository, objectRepo ObjectRepository, actorRepo ActorRepository, federation FederationClient, publisher Publisher, logger *zap.Logger, domainName string, ) *Service
NewService creates a new threads service
func (*Service) FindThreadRoot ¶
func (s *Service) FindThreadRoot(ctx context.Context, note *activitypub.Note) (*activitypub.Note, []*activitypub.Note, error)
FindThreadRoot finds the root of a thread by walking up the inReplyTo chain
func (*Service) GetThreadContext ¶
func (s *Service) GetThreadContext(ctx context.Context, query ThreadContextQuery) (*ThreadContextResult, error)
GetThreadContext retrieves the complete thread context for a note
func (*Service) SyncMissingReplies ¶
func (s *Service) SyncMissingReplies(ctx context.Context, cmd SyncMissingRepliesCommand) (*SyncMissingRepliesResult, error)
SyncMissingReplies syncs replies that were detected as missing
func (*Service) SyncRemoteThread ¶
func (s *Service) SyncRemoteThread(ctx context.Context, cmd SyncRemoteThreadCommand) (*SyncRemoteThreadResult, error)
SyncRemoteThread synchronizes a remote thread by fetching it and building the tree
type StatusRepository ¶
type StatusRepository interface {
GetReplies(ctx context.Context, parentStatusID string, opts interfaces.PaginationOptions) (*interfaces.PaginatedResult[*models.Status], error)
}
StatusRepository defines minimal interface for status operations
type SyncMissingRepliesCommand ¶
SyncMissingRepliesCommand represents a command to sync missing replies
type SyncMissingRepliesResult ¶
SyncMissingRepliesResult represents the result of syncing missing replies
type SyncRemoteThreadCommand ¶
SyncRemoteThreadCommand represents a command to sync a remote thread
type SyncRemoteThreadResult ¶
type SyncRemoteThreadResult struct {
Success bool
ThreadRoot *activitypub.Note
SyncedPosts int
ErrorCount int
Errors []string
SyncStatus string
}
SyncRemoteThreadResult represents the result of a thread sync operation
type ThreadContextQuery ¶
ThreadContextQuery represents a query for thread context
type ThreadContextResult ¶
type ThreadContextResult struct {
RootNote *activitypub.Note
RequestedNote *activitypub.Note
Ancestors []*activitypub.Note
Descendants []*models.ThreadNode
ParticipantCount int
ReplyCount int
MissingCount int
LastActivity time.Time
SyncStatus string
}
ThreadContextResult represents the complete context of a thread
type ThreadRepository ¶
type ThreadRepository interface {
SaveThreadSync(ctx context.Context, sync *models.ThreadSync) error
GetThreadSync(ctx context.Context, statusID string) (*models.ThreadSync, error)
SaveThreadNode(ctx context.Context, node *models.ThreadNode) error
GetThreadNodes(ctx context.Context, rootStatusID string) ([]*models.ThreadNode, error)
GetThreadNode(ctx context.Context, rootStatusID, statusID string) (*models.ThreadNode, error)
GetThreadNodeByStatusID(ctx context.Context, statusID string) (*models.ThreadNode, error)
MarkMissingReplies(ctx context.Context, rootStatusID, parentStatusID string, replyIDs []string) error
GetMissingReplies(ctx context.Context, rootStatusID string) ([]*models.MissingReply, error)
GetThreadContext(ctx context.Context, statusID string) (*repositories.ThreadContextResult, error)
SaveMissingReply(ctx context.Context, missing *models.MissingReply) error
DeleteMissingReply(ctx context.Context, rootStatusID, replyID string) error
}
ThreadRepository defines the interface for thread storage operations