feat: notification enhancement
This commit is contained in:
@@ -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) {
|
||||
off, err := s.prefs.DisabledSet(ctx, userID)
|
||||
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
|
||||
}
|
||||
matrix := make(map[string]map[string]bool, len(PrefCategories))
|
||||
@@ -171,10 +174,15 @@ func (s *NotificationService) SetPref(ctx context.Context, userID, category, cha
|
||||
} else {
|
||||
err = s.prefs.Disable(ctx, userID, kinds, []string{channel})
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
if err == nil {
|
||||
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 —
|
||||
@@ -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) {
|
||||
off, err := s.prefs.DisabledSet(ctx, userID)
|
||||
if err != nil {
|
||||
s.logger.Error("notification prefs: load failed", zap.String("user", userID), zap.Error(err))
|
||||
return false, err
|
||||
}
|
||||
return !prefOff(off, NotifPostLike, repository.ChannelEmail), nil
|
||||
@@ -196,10 +205,14 @@ func (s *NotificationService) SetLikeEmailPref(ctx context.Context, userID strin
|
||||
} else {
|
||||
err = s.prefs.Disable(ctx, userID, kinds, channels)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
if err == nil {
|
||||
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
|
||||
|
||||
@@ -73,6 +73,8 @@ func NewReminderService(repo *repository.ReminderRepo, prefs *repository.Notific
|
||||
func (s *ReminderService) Enabled(ctx context.Context, userID string) (bool, error) {
|
||||
off, err := s.prefs.DisabledSet(ctx, userID)
|
||||
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
|
||||
}
|
||||
for _, kind := range PrefCategories["sadhna_reminders"] {
|
||||
@@ -93,10 +95,13 @@ func (s *ReminderService) SetEnabled(ctx context.Context, userID string, enabled
|
||||
} else {
|
||||
err = s.prefs.Disable(ctx, userID, kinds, PrefChannels)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
if err == nil {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user