Documentation
¶
Index ¶
- Constants
- type Dispatcher
- type DispatcherOpts
- type EmailNotification
- type Message
- type Notification
- type Notifier
- type Service
- type UserNotificationManager
- func (m *UserNotificationManager) Create(userID int, notificationType models.NotificationType, title string, ...) (models.UserNotification, error)
- func (m *UserNotificationManager) Delete(id, userID int) error
- func (m *UserNotificationManager) DeleteAll(userID int) error
- func (m *UserNotificationManager) DeleteOldNotifications(ctx context.Context) error
- func (m *UserNotificationManager) GetAll(userID, limit, offset int) ([]models.UserNotification, error)
- func (m *UserNotificationManager) GetStats(userID int) (models.NotificationStats, error)
- func (m *UserNotificationManager) MarkAllAsRead(userID int) error
- func (m *UserNotificationManager) MarkAsRead(id, userID int) error
- func (m *UserNotificationManager) RunNotificationCleaner(ctx context.Context)
- type UserNotificationOpts
- type WSHub
Constants ¶
const (
ProviderEmail = "email"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher coordinates sending notifications through multiple channels: WS, DB, email.
func NewDispatcher ¶
func NewDispatcher(opts DispatcherOpts) *Dispatcher
NewDispatcher creates a new notification Dispatcher.
func (*Dispatcher) Send ¶
func (d *Dispatcher) Send(n Notification)
Send sends a notification through all configured channels. For each recipient: creates in-app notification (DB), broadcasts via Websocket, and sends email if Email field is provided.
func (*Dispatcher) SendWithEmails ¶
func (d *Dispatcher) SendWithEmails(n Notification, emails []EmailNotification)
SendWithEmails sends notifications where each recipient has their own email content. This is useful when email content is personalized per recipient.
type DispatcherOpts ¶
type DispatcherOpts struct {
InApp *UserNotificationManager
Outbound *Service
WSHub WSHub
Lo *logf.Logger
}
DispatcherOpts contains options for creating a new Dispatcher.
type EmailNotification ¶
EmailNotification holds email channel notification details.
type Message ¶
type Message struct {
// Email addresses of the recipients
RecipientEmails []string
// Subject of the message
Subject string
// Body of the message
Content string
// Provider to send the message through
Provider string
// Attachments to be sent with the message
Attachments []attachment.Attachment
// Type of content ("plain" or "html")
ContentType string
// Alternative plain text version of the HTML content
AltContent string
// Additional email headers
Headers map[string][]string
}
Message represents a message to be sent as a notification.
type Notification ¶
type Notification struct {
// Core notification fields
Type models.NotificationType
RecipientIDs []int
Title string
Body null.String
ConversationID null.Int
MessageID null.Int
ActorID null.Int
Meta json.RawMessage
// For Websocket broadcast
ConversationUUID string
ActorFirstName string
ActorLastName string
// Email fields (optional - if empty, no email sent)
Email *EmailNotification
}
Notification represents a notification to be sent through all channels.
type Notifier ¶
type Notifier interface {
// Sends the notification message using the specified provider
Send(message Message) error
// Returns the name of the provider
Name() string
}
Notifier defines the interface for sending notifications through various providers.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages message providers and a worker pool.
func NewService ¶
func NewService(providers map[string]Notifier, concurrency, capacity int, logger *logf.Logger) *Service
NewService initializes the Service with given concurrency, channel capacity, and logger.
func (*Service) Close ¶
func (s *Service) Close()
Close signals service to stop, closes the message channel and waits for all goroutine workers to finish.
type UserNotificationManager ¶
type UserNotificationManager struct {
// contains filtered or unexported fields
}
func NewUserNotificationManager ¶
func NewUserNotificationManager(opts UserNotificationOpts) (*UserNotificationManager, error)
NewUserNotificationManager creates and returns a new instance of UserNotificationManager.
func (*UserNotificationManager) Create ¶
func (m *UserNotificationManager) Create(userID int, notificationType models.NotificationType, title string, body null.String, conversationID, messageID, actorID null.Int, meta json.RawMessage) (models.UserNotification, error)
Create creates a new notification for a user.
func (*UserNotificationManager) Delete ¶
func (m *UserNotificationManager) Delete(id, userID int) error
Delete deletes a notification.
func (*UserNotificationManager) DeleteAll ¶
func (m *UserNotificationManager) DeleteAll(userID int) error
DeleteAll deletes all notifications for a user.
func (*UserNotificationManager) DeleteOldNotifications ¶
func (m *UserNotificationManager) DeleteOldNotifications(ctx context.Context) error
DeleteOldNotifications deletes notifications older than 30 days.
func (*UserNotificationManager) GetAll ¶
func (m *UserNotificationManager) GetAll(userID, limit, offset int) ([]models.UserNotification, error)
GetAll retrieves notifications for a user with pagination.
func (*UserNotificationManager) GetStats ¶
func (m *UserNotificationManager) GetStats(userID int) (models.NotificationStats, error)
GetStats retrieves notification statistics for a user.
func (*UserNotificationManager) MarkAllAsRead ¶
func (m *UserNotificationManager) MarkAllAsRead(userID int) error
MarkAllAsRead marks all notifications as read for a user.
func (*UserNotificationManager) MarkAsRead ¶
func (m *UserNotificationManager) MarkAsRead(id, userID int) error
MarkAsRead marks a notification as read.
func (*UserNotificationManager) RunNotificationCleaner ¶
func (m *UserNotificationManager) RunNotificationCleaner(ctx context.Context)
RunNotificationCleaner runs a background job to delete old notifications every 24 hours.
type UserNotificationOpts ¶
type WSHub ¶
type WSHub interface {
BroadcastMessage(msg wsmodels.BroadcastMessage)
}
WSHub defines the interface for the Websocket hub.