Add timezone-aware daily digest notifications
The daily digest notification count was inconsistent with the kanban UI because the server used UTC time while the client used local time. A task due Dec 24 would appear overdue on the server (UTC Dec 25) but still show as "due today" for the user (local Dec 24). Changes: - Add timezone column to notification_preference table - Auto-capture user's timezone from X-Timezone header when fetching tasks - Use stored timezone in HandleDailyDigest for accurate overdue calculation The mobile app already sends X-Timezone on every request, so no client changes are needed. The timezone is captured on each app launch when the tasks API is called. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
@@ -237,6 +238,28 @@ func (s *NotificationService) UpdatePreferences(userID uint, req *UpdatePreferen
|
||||
return NewNotificationPreferencesResponse(prefs), nil
|
||||
}
|
||||
|
||||
// UpdateUserTimezone updates the user's timezone for background job calculations.
|
||||
// This is called automatically when the user makes API calls (e.g., fetching tasks).
|
||||
// The timezone should be an IANA timezone name (e.g., "America/Los_Angeles").
|
||||
func (s *NotificationService) UpdateUserTimezone(userID uint, timezone string) {
|
||||
// Validate timezone is a valid IANA name
|
||||
if _, err := time.LoadLocation(timezone); err != nil {
|
||||
return // Invalid timezone, skip silently
|
||||
}
|
||||
|
||||
// Get or create preferences and update timezone
|
||||
prefs, err := s.notificationRepo.GetOrCreatePreferences(userID)
|
||||
if err != nil {
|
||||
return // Skip silently on error
|
||||
}
|
||||
|
||||
// Only update if timezone changed (avoid unnecessary DB writes)
|
||||
if prefs.Timezone == nil || *prefs.Timezone != timezone {
|
||||
prefs.Timezone = &timezone
|
||||
_ = s.notificationRepo.UpdatePreferences(prefs)
|
||||
}
|
||||
}
|
||||
|
||||
// === Device Registration ===
|
||||
|
||||
// RegisterDevice registers a device for push notifications
|
||||
|
||||
@@ -996,3 +996,14 @@ func (s *TaskService) GetFrequencies() ([]responses.TaskFrequencyResponse, error
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// === Timezone ===
|
||||
|
||||
// UpdateUserTimezone updates the user's timezone for background job calculations.
|
||||
// This is called from handlers when the X-Timezone header is present.
|
||||
// Delegates to NotificationService since timezone is stored in notification preferences.
|
||||
func (s *TaskService) UpdateUserTimezone(userID uint, timezone string) {
|
||||
if s.notificationService != nil {
|
||||
s.notificationService.UpdateUserTimezone(userID, timezone)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user