Files
gochat/internal/model/notification_preference.go
T
2026-06-04 15:44:48 +08:00

25 lines
1.2 KiB
Go

package model
import (
"encoding/json"
"time"
)
// NotificationPreference represents per-user notification settings.
// Reference: Chatwoot NotificationPreference model + P2B M8 spec
type NotificationPreference struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"not null;uniqueIndex:idx_user_account_channel_event" json:"user_id"`
AccountID *uint `gorm:"uniqueIndex:idx_user_account_channel_event" json:"account_id,omitempty"`
Channel string `gorm:"size:100;not null;uniqueIndex:idx_user_account_channel_event" json:"channel"` // email/push/browser
EventType string `gorm:"size:100;not null;uniqueIndex:idx_user_account_channel_event" json:"event_type"` // conversation_created/assigned_conversation_new_message/...
Enabled bool `gorm:"default:true" json:"enabled"`
Preferences json.RawMessage `gorm:"type:jsonb" json:"preferences"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
}
func (NotificationPreference) TableName() string { return "notification_preferences" }