Documentation
¶
Index ¶
- Variables
- func CloseConnection(pool *pgxpool.Pool)
- func EnrichThreadsWithFirstMessageFromAddress(ctx context.Context, pool *pgxpool.Pool, threads []*models.Thread) error
- func EnrichThreadsWithPreviewAndAttachments(ctx context.Context, pool *pgxpool.Pool, threads []*models.Thread) error
- func GetAttachmentByID(ctx context.Context, pool *pgxpool.Pool, attachmentID string) (*models.Attachment, error)
- func GetAttachmentsForMessage(ctx context.Context, pool *pgxpool.Pool, messageID string) ([]*models.Attachment, error)
- func GetAttachmentsForMessages(ctx context.Context, pool *pgxpool.Pool, messageIDs []string) (map[string][]*models.Attachment, error)
- func GetMessageByID(ctx context.Context, pool *pgxpool.Pool, messageID string) (*models.Message, error)
- func GetMessageByMessageID(ctx context.Context, pool *pgxpool.Pool, userID, messageID string) (*models.Message, error)
- func GetMessageByUID(ctx context.Context, pool *pgxpool.Pool, userID, folderName string, ...) (*models.Message, error)
- func GetMessagesForThread(ctx context.Context, pool *pgxpool.Pool, threadID string) ([]*models.Message, error)
- func GetOrCreateUser(ctx context.Context, pool *pgxpool.Pool, email string) (string, error)
- func GetThreadByID(ctx context.Context, pool *pgxpool.Pool, threadID string) (*models.Thread, error)
- func GetThreadByStableID(ctx context.Context, pool *pgxpool.Pool, userID, stableThreadID string) (*models.Thread, error)
- func GetThreadCountForFolder(ctx context.Context, pool *pgxpool.Pool, userID, folderName string) (int, error)
- func GetThreadsForFolder(ctx context.Context, pool *pgxpool.Pool, userID, folderName string, ...) ([]*models.Thread, error)
- func GetUserSettings(ctx context.Context, pool *pgxpool.Pool, userID string) (*models.UserSettings, error)
- func NewConnection(ctx context.Context, cfg *config.Config) (*pgxpool.Pool, error)
- func SaveAttachment(ctx context.Context, pool *pgxpool.Pool, attachment *models.Attachment) error
- func SaveMessage(ctx context.Context, pool *pgxpool.Pool, message *models.Message) error
- func SaveThread(ctx context.Context, pool *pgxpool.Pool, thread *models.Thread) error
- func SaveUserSettings(ctx context.Context, pool *pgxpool.Pool, settings *models.UserSettings) error
- func SetFolderSyncInfo(ctx context.Context, pool *pgxpool.Pool, userID, folderName string, ...) error
- func UpdateThreadCount(ctx context.Context, pool *pgxpool.Pool, userID, folderName string) error
- func UserSettingsExist(ctx context.Context, pool *pgxpool.Pool, userID string) (bool, error)
- type FolderSyncInfo
- type ThreadCountUpdater
Constants ¶
This section is empty.
Variables ¶
var ErrMessageNotFound = errors.New("message not found")
ErrMessageNotFound is returned when a requested message cannot be found.
var ErrThreadNotFound = errors.New("thread not found")
ErrThreadNotFound is returned when a requested thread cannot be found.
var ErrUserSettingsNotFound = errors.New("user settings not found")
ErrUserSettingsNotFound is returned when user settings cannot be found.
Functions ¶
func CloseConnection ¶
CloseConnection closes the given database connection pool.
func EnrichThreadsWithFirstMessageFromAddress ¶
func EnrichThreadsWithFirstMessageFromAddress(ctx context.Context, pool *pgxpool.Pool, threads []*models.Thread) error
EnrichThreadsWithFirstMessageFromAddress enriches threads with the first message's from_address. This is useful for search results and other cases where threads don't have messages populated.
func EnrichThreadsWithPreviewAndAttachments ¶
func EnrichThreadsWithPreviewAndAttachments(ctx context.Context, pool *pgxpool.Pool, threads []*models.Thread) error
EnrichThreadsWithPreviewAndAttachments enriches threads with preview snippet, attachment info, message count, and last sent date. This is useful for search results and other cases where threads don't have these fields populated.
func GetAttachmentByID ¶
func GetAttachmentByID(ctx context.Context, pool *pgxpool.Pool, attachmentID string) (*models.Attachment, error)
GetAttachmentByID returns an attachment by its database ID.
func GetAttachmentsForMessage ¶
func GetAttachmentsForMessage(ctx context.Context, pool *pgxpool.Pool, messageID string) ([]*models.Attachment, error)
GetAttachmentsForMessage returns all attachments for a message.
func GetAttachmentsForMessages ¶
func GetAttachmentsForMessages(ctx context.Context, pool *pgxpool.Pool, messageIDs []string) (map[string][]*models.Attachment, error)
GetAttachmentsForMessages returns all attachments for multiple messages in a single query. Returns a map from message ID to a slice of attachments.
func GetMessageByID ¶
func GetMessageByID(ctx context.Context, pool *pgxpool.Pool, messageID string) (*models.Message, error)
GetMessageByID returns a message by its database ID.
func GetMessageByMessageID ¶
func GetMessageByMessageID(ctx context.Context, pool *pgxpool.Pool, userID, messageID string) (*models.Message, error)
GetMessageByMessageID returns a message by its Message-ID header.
func GetMessageByUID ¶
func GetMessageByUID(ctx context.Context, pool *pgxpool.Pool, userID, folderName string, imapUID int64) (*models.Message, error)
GetMessageByUID returns a message by its IMAP UID and folder.
func GetMessagesForThread ¶
func GetMessagesForThread(ctx context.Context, pool *pgxpool.Pool, threadID string) ([]*models.Message, error)
GetMessagesForThread returns all messages for a thread.
func GetOrCreateUser ¶
GetOrCreateUser returns the user's id for the given email. If no user exists with that email, it creates a new one.
func GetThreadByID ¶
func GetThreadByID(ctx context.Context, pool *pgxpool.Pool, threadID string) (*models.Thread, error)
GetThreadByID returns a thread by its database ID.
func GetThreadByStableID ¶
func GetThreadByStableID(ctx context.Context, pool *pgxpool.Pool, userID, stableThreadID string) (*models.Thread, error)
GetThreadByStableID returns a thread by its stable thread ID.
func GetThreadCountForFolder ¶
func GetThreadCountForFolder(ctx context.Context, pool *pgxpool.Pool, userID, folderName string) (int, error)
GetThreadCountForFolder returns the total count of threads for a specific folder. Uses the materialized count from folder_sync_timestamps if available, otherwise falls back to calculating it on the fly.
func GetThreadsForFolder ¶
func GetThreadsForFolder(ctx context.Context, pool *pgxpool.Pool, userID, folderName string, limit, offset int) ([]*models.Thread, error)
GetThreadsForFolder returns threads for a specific folder. It returns threads that have at least one message in the specified folder. Each thread includes message_count (number of messages), last_sent_at (most recent message date), preview_snippet, has_attachments, and first_message_from_address for efficient list view rendering.
func GetUserSettings ¶
func GetUserSettings(ctx context.Context, pool *pgxpool.Pool, userID string) (*models.UserSettings, error)
GetUserSettings returns the user settings for the given user.
func NewConnection ¶
NewConnection creates a new PostgreSQL connection pool with the given configuration.
func SaveAttachment ¶
SaveAttachment saves an attachment to the database.
func SaveMessage ¶
SaveMessage saves or updates a message in the database. If a message with the same Message-ID already exists for this user in a DIFFERENT folder, it is skipped to avoid duplicates (e.g., when you email yourself, the same message appears in both Inbox and Sent with the same Message-ID). Updates to the same folder+UID are allowed (for refreshing message data).
func SaveThread ¶
SaveThread saves or updates a thread in the database.
func SaveUserSettings ¶
SaveUserSettings saves the user settings for the given user.
func SetFolderSyncInfo ¶
func SetFolderSyncInfo(ctx context.Context, pool *pgxpool.Pool, userID, folderName string, lastSyncedUID *int64) error
SetFolderSyncInfo sets the sync information for the given folder.
func UpdateThreadCount ¶
UpdateThreadCount updates the materialized thread count for a folder. This should be called in the background after syncing.
Types ¶
type FolderSyncInfo ¶
FolderSyncInfo contains information about folder sync status.
func GetFolderSyncInfo ¶
func GetFolderSyncInfo(ctx context.Context, pool *pgxpool.Pool, userID, folderName string) (*FolderSyncInfo, error)
GetFolderSyncInfo returns the sync information for the given folder. Returns nil if we've never synced it.
type ThreadCountUpdater ¶
type ThreadCountUpdater interface {
UpdateThreadCount(ctx context.Context, userID, folderName string) error
}
ThreadCountUpdater defines an interface for updating thread counts. This allows the Service to be tested with mock implementations.
func NewThreadCountUpdater ¶
func NewThreadCountUpdater(pool *pgxpool.Pool) ThreadCountUpdater
NewThreadCountUpdater creates a ThreadCountUpdater that uses the given database pool.