Documentation
¶
Overview ¶
Package conversations provides the core Conversations Service for the Lesser project's API alignment. This service handles direct message conversations including creation, participant management, read status tracking, and real-time event emission. It supports federation for remote participants and maintains privacy by ensuring only participants can access conversation content.
Index ¶
- Constants
- Variables
- type ConversationResult
- type ConversationWithMessages
- type DeleteConversationCommand
- type FederationService
- type GetConversationQuery
- type ListConversationsQuery
- type MarkConversationReadCommand
- type MessageResult
- type Result
- type SendDirectMessageCommand
- type Service
- func (s *Service) DeleteConversation(ctx context.Context, cmd *DeleteConversationCommand) (*ConversationResult, error)
- func (s *Service) GetConversation(ctx context.Context, query *GetConversationQuery) (*ConversationWithMessages, error)
- func (s *Service) ListConversations(ctx context.Context, query *ListConversationsQuery) (*Result, error)
- func (s *Service) MarkConversationRead(ctx context.Context, cmd *MarkConversationReadCommand) (*ConversationResult, error)
- func (s *Service) SendDirectMessage(ctx context.Context, cmd *SendDirectMessageCommand) (*MessageResult, error)
Constants ¶
const ( // VisibilityDirect represents direct message visibility VisibilityDirect = "direct" // ConversationMessageEvent is emitted when a message is sent to a conversation ConversationMessageEvent = "conversation.message" // ConversationReadEvent is emitted when a conversation is marked as read ConversationReadEvent = "conversation.read" // ConversationUpdatedEvent is emitted when conversation metadata is updated ConversationUpdatedEvent = "conversation.updated" )
Variables ¶
var ( // ErrConversationValidationFailed is returned when conversation validation fails ErrConversationValidationFailed = apperrors.ValidationFailedWithField("conversation") // ErrGetSenderAccount is returned when getting sender account fails ErrGetSenderAccount = apperrors.FailedToGet("sender account", errors.New("failed to get sender account")) // ErrInvalidRecipient is returned when recipient validation fails ErrInvalidRecipient = apperrors.NewValidationError("recipient", "invalid") // ErrLookupExistingConversation is returned when looking up existing conversation fails ErrLookupExistingConversation = apperrors.FailedToQuery("existing conversation", errors.New("failed to lookup existing conversation")) // ErrCreateConversation is returned when conversation creation fails ErrCreateConversation = apperrors.FailedToCreate("conversation", errors.New("failed to create conversation")) // ErrCreateDirectMessage is returned when direct message creation fails ErrCreateDirectMessage = apperrors.FailedToCreate("direct message", errors.New("failed to create direct message")) // ErrGetConversation is returned when conversation retrieval fails ErrGetConversation = apperrors.FailedToGet("conversation", errors.New("failed to get conversation")) // ErrNotConversationParticipant is returned when user is not a participant in conversation ErrNotConversationParticipant = apperrors.AccessDeniedForResource("conversation", "participant") // ErrMarkConversationRead is returned when marking conversation as read fails ErrMarkConversationRead = apperrors.FailedToUpdate("conversation read status", errors.New("failed to mark conversation as read")) // ErrGetUserConversations is returned when getting user conversations fails ErrGetUserConversations = apperrors.FailedToList("user conversations", errors.New("failed to get user conversations")) // ErrGetConversationMessages is returned when getting conversation messages fails ErrGetConversationMessages = apperrors.FailedToList("conversation messages", errors.New("failed to get conversation messages")) // ErrRecipientsRequired is returned when recipients list is required but empty ErrRecipientsRequired = apperrors.NewValidationError("recipients", "required") // ErrContentTooLongConversation is returned when conversation content is too long ErrContentTooLongConversation = apperrors.NewValidationError("content", "too long (max 5000 characters)") // ErrInvalidInReplyToIDConversation is returned when in_reply_to_id is invalid for conversation ErrInvalidInReplyToIDConversation = apperrors.NewValidationError("in_reply_to_id", "invalid") // ErrCanOnlyReplyToDirectMessages is returned when attempting to reply to non-direct message ErrCanOnlyReplyToDirectMessages = apperrors.NewValidationError("reply_target", "can only reply to direct messages") // ErrConversationNotFound is returned when conversation is not found ErrConversationNotFound = apperrors.NewAppError(apperrors.CodeNotFound, apperrors.CategoryBusiness, "conversation not found") // ErrGetAccount is returned when account retrieval fails ErrGetAccount = apperrors.FailedToGet("account", errors.New("failed to get account")) // ErrDeleteConversation is returned when conversation deletion fails ErrDeleteConversation = apperrors.FailedToDelete("conversation", errors.New("failed to delete conversation")) )
Conversation service errors
Functions ¶
This section is empty.
Types ¶
type ConversationResult ¶
type ConversationResult struct {
Conversation *models.Conversation `json:"conversation"`
Events []*streaming.Event `json:"events"`
}
ConversationResult contains a conversation and associated events
type ConversationWithMessages ¶
type ConversationWithMessages struct {
Conversation *models.Conversation `json:"conversation"`
Messages *interfaces.PaginatedResult[*models.Status] `json:"messages"`
Events []*streaming.Event `json:"events"`
}
ConversationWithMessages contains a conversation and its message history
type DeleteConversationCommand ¶
type DeleteConversationCommand struct {
ConversationID string `json:"conversation_id" validate:"required"`
UserID string `json:"user_id" validate:"required"`
}
DeleteConversationCommand contains data needed to delete a conversation
type FederationService ¶
type FederationService interface {
QueueActivity(ctx context.Context, activity *activitypub.Activity) error
}
FederationService defines the interface for federation operations
type GetConversationQuery ¶
type GetConversationQuery struct {
ConversationID string `json:"conversation_id" validate:"required"`
ViewerID string `json:"viewer_id" validate:"required"` // Must be a participant
Pagination interfaces.PaginationOptions `json:"pagination"`
}
GetConversationQuery contains parameters for retrieving a conversation
type ListConversationsQuery ¶
type ListConversationsQuery struct {
UserID string `json:"user_id" validate:"required"`
Pagination interfaces.PaginationOptions `json:"pagination"`
OnlyUnread bool `json:"only_unread"`
}
ListConversationsQuery contains parameters for listing user conversations
type MarkConversationReadCommand ¶
type MarkConversationReadCommand struct {
ConversationID string `json:"conversation_id" validate:"required"`
UserID string `json:"user_id" validate:"required"`
}
MarkConversationReadCommand contains data needed to mark a conversation as read
type MessageResult ¶
type MessageResult struct {
Message *models.Status `json:"message"`
Conversation *models.Conversation `json:"conversation"`
Events []*streaming.Event `json:"events"`
}
MessageResult contains a direct message and associated events
type Result ¶
type Result struct {
Conversations *interfaces.PaginatedResult[*models.Conversation] `json:"conversations"`
Events []*streaming.Event `json:"events"`
}
Result contains multiple conversations with pagination
type SendDirectMessageCommand ¶
type SendDirectMessageCommand struct {
SenderID string `json:"sender_id" validate:"required"`
Recipients []string `json:"recipients" validate:"required,min=1"`
Content string `json:"content" validate:"required,max=5000"`
Sensitive bool `json:"sensitive"`
Language string `json:"language"`
MediaIDs []string `json:"media_ids"`
InReplyToID string `json:"in_reply_to_id"` // Can reply to messages in the conversation
}
SendDirectMessageCommand contains all data needed to send a direct message
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides conversation operations for direct messages
func NewService ¶
func NewService( conversationRepo interfaces.ConversationRepository, noteRepo interfaces.StatusRepository, accountRepo interfaces.AccountRepository, publisher streaming.Publisher, federation FederationService, logger *zap.Logger, domainName string, ) *Service
NewService creates a new Conversations Service with the required dependencies
func (*Service) DeleteConversation ¶
func (s *Service) DeleteConversation(ctx context.Context, cmd *DeleteConversationCommand) (*ConversationResult, error)
DeleteConversation removes a conversation or removes a user from it
func (*Service) GetConversation ¶
func (s *Service) GetConversation(ctx context.Context, query *GetConversationQuery) (*ConversationWithMessages, error)
GetConversation retrieves a conversation with its message history
func (*Service) ListConversations ¶
func (s *Service) ListConversations(ctx context.Context, query *ListConversationsQuery) (*Result, error)
ListConversations retrieves conversations for a user with pagination
func (*Service) MarkConversationRead ¶
func (s *Service) MarkConversationRead(ctx context.Context, cmd *MarkConversationReadCommand) (*ConversationResult, error)
MarkConversationRead marks a conversation as read for a specific user
func (*Service) SendDirectMessage ¶
func (s *Service) SendDirectMessage(ctx context.Context, cmd *SendDirectMessageCommand) (*MessageResult, error)
SendDirectMessage creates or updates a conversation, creates a direct message, and emits events