feat: notification enhancement

This commit is contained in:
Krispire Admin
2026-06-11 01:00:31 +05:30
parent 187bcd1442
commit 0655b2314d
2 changed files with 27 additions and 9 deletions
+19 -6
View File
@@ -135,6 +135,9 @@ var ErrUnknownPref = errors.New("unknown notification preference")
func (s *NotificationService) PrefMatrix(ctx context.Context, userID string) (map[string]map[string]bool, error) { func (s *NotificationService) PrefMatrix(ctx context.Context, userID string) (map[string]map[string]bool, error) {
off, err := s.prefs.DisabledSet(ctx, userID) off, err := s.prefs.DisabledSet(ctx, userID)
if err != nil { if err != nil {
// The handler sanitizes this into a generic 500 — log the real
// cause here or it's invisible in production.
s.logger.Error("notification prefs: load failed", zap.String("user", userID), zap.Error(err))
return nil, err return nil, err
} }
matrix := make(map[string]map[string]bool, len(PrefCategories)) matrix := make(map[string]map[string]bool, len(PrefCategories))
@@ -171,10 +174,15 @@ func (s *NotificationService) SetPref(ctx context.Context, userID, category, cha
} else { } else {
err = s.prefs.Disable(ctx, userID, kinds, []string{channel}) err = s.prefs.Disable(ctx, userID, kinds, []string{channel})
} }
if err != nil { if err == nil {
return err err = s.prefs.SyncLegacyColumns(ctx, userID)
} }
return s.prefs.SyncLegacyColumns(ctx, userID) if err != nil {
s.logger.Error("notification prefs: write failed",
zap.String("user", userID), zap.String("category", category),
zap.String("channel", channel), zap.Error(err))
}
return err
} }
// LikeEmailPref / SetLikeEmailPref back the legacy like-email endpoint — // LikeEmailPref / SetLikeEmailPref back the legacy like-email endpoint —
@@ -183,6 +191,7 @@ func (s *NotificationService) SetPref(ctx context.Context, userID, category, cha
func (s *NotificationService) LikeEmailPref(ctx context.Context, userID string) (bool, error) { func (s *NotificationService) LikeEmailPref(ctx context.Context, userID string) (bool, error) {
off, err := s.prefs.DisabledSet(ctx, userID) off, err := s.prefs.DisabledSet(ctx, userID)
if err != nil { if err != nil {
s.logger.Error("notification prefs: load failed", zap.String("user", userID), zap.Error(err))
return false, err return false, err
} }
return !prefOff(off, NotifPostLike, repository.ChannelEmail), nil return !prefOff(off, NotifPostLike, repository.ChannelEmail), nil
@@ -196,10 +205,14 @@ func (s *NotificationService) SetLikeEmailPref(ctx context.Context, userID strin
} else { } else {
err = s.prefs.Disable(ctx, userID, kinds, channels) err = s.prefs.Disable(ctx, userID, kinds, channels)
} }
if err != nil { if err == nil {
return err err = s.prefs.SyncLegacyColumns(ctx, userID)
} }
return s.prefs.SyncLegacyColumns(ctx, userID) if err != nil {
s.logger.Error("notification prefs: like-email write failed",
zap.String("user", userID), zap.Error(err))
}
return err
} }
// NotifyFollowRequest tells `recipientID` that `actorID` asked to follow // NotifyFollowRequest tells `recipientID` that `actorID` asked to follow
+8 -3
View File
@@ -73,6 +73,8 @@ func NewReminderService(repo *repository.ReminderRepo, prefs *repository.Notific
func (s *ReminderService) Enabled(ctx context.Context, userID string) (bool, error) { func (s *ReminderService) Enabled(ctx context.Context, userID string) (bool, error) {
off, err := s.prefs.DisabledSet(ctx, userID) off, err := s.prefs.DisabledSet(ctx, userID)
if err != nil { if err != nil {
// Handler sanitizes to a generic 500 — log the cause here.
s.logger.Error("reminder prefs: load failed", zap.String("user", userID), zap.Error(err))
return false, err return false, err
} }
for _, kind := range PrefCategories["sadhna_reminders"] { for _, kind := range PrefCategories["sadhna_reminders"] {
@@ -93,10 +95,13 @@ func (s *ReminderService) SetEnabled(ctx context.Context, userID string, enabled
} else { } else {
err = s.prefs.Disable(ctx, userID, kinds, PrefChannels) err = s.prefs.Disable(ctx, userID, kinds, PrefChannels)
} }
if err != nil { if err == nil {
return err err = s.prefs.SyncLegacyColumns(ctx, userID)
} }
return s.prefs.SyncLegacyColumns(ctx, userID) if err != nil {
s.logger.Error("reminder prefs: write failed", zap.String("user", userID), zap.Error(err))
}
return err
} }
// SetTimezone validates the IANA zone before storing so a bad value can never // SetTimezone validates the IANA zone before storing so a bad value can never