Extract iOS orchestration logic from plugin to dedicated helper, matching Android's ScheduleHelper.kt pattern. This completes the P2.1 native plugin refactoring for both platforms. Changes: - Created DailyNotificationScheduleHelper.swift (192 lines) - scheduleDailyNotification(): Full orchestration (cancel, clear, save, schedule, prefetch) - scheduleDualNotification(): Dual scheduling coordination - clearRolloverState(): Rollover state cleanup helper - getHealthStatus(): Status combination from multiple sources - Refactored DailyNotificationPlugin.swift to delegate to helper - Reduced plugin by 236 lines (1854 → 1807 LOC) - Total iOS reduction: 11.7% (2047 → 1807 LOC) - Updated documentation - docs/progress/00-STATUS.md: Marked verification complete, added helper extraction - docs/progress/01-CHANGELOG-WORK.md: Added iOS helper extraction entry - docs/progress/P2.1-REFACTORING-COMPLETE.md: Updated with helper extraction - docs/00-INDEX.md: Added reference to refactoring summary Verification: - TypeScript typecheck: PASS - Build: PASS - Tests: PASS (115 tests, 8 test suites) - External API behavior unchanged Files changed: - ios/Plugin/DailyNotificationScheduleHelper.swift (new, 192 lines) - ios/Plugin/DailyNotificationPlugin.swift (198 insertions, 434 deletions) - docs/progress/00-STATUS.md (verification status updated) - docs/progress/01-CHANGELOG-WORK.md (changelog entry added) - docs/00-INDEX.md (index reference added) Related: - Completes P2.1 iOS refactoring (27 methods across 3 batches) - Matches Android ScheduleHelper.kt pattern - Total P2.1: 55 methods refactored (28 Android + 27 iOS)
6.0 KiB
P2.1 iOS Batch B - Validation + Delegation Methods
Purpose: Second batch of iOS plugin refactoring - methods that validate input then delegate to services
Owner: Development Team
Created: 2025-12-23
Status: ready
Baseline: See docs/progress/00-STATUS.md (v1.0.11-p3-complete)
Goal
Refactor iOS plugin methods that validate input then delegate to services. These methods:
- Extract and validate parameters from
CAPPluginCall - Handle error responses for invalid input
- Delegate validated parameters to service methods
- Map service results/errors to plugin responses
Success Criteria:
- Plugin method validates input, delegates to service
- Service method handles business logic
- External API unchanged
- Tests pass
Target Methods (Batch B)
Permissions (4 methods)
-
checkPermissionStatus()- Validate: None (read-only)
- Delegate:
UNUserNotificationCenter.getNotificationSettings()→ parse and format - Type: validation (parse settings, format response)
-
requestNotificationPermissions()- Validate: None (request only)
- Delegate:
UNUserNotificationCenter.requestAuthorization(...) - Type: validation (handle async result)
-
getNotificationPermissionStatus()- Validate: None (read-only)
- Delegate:
UNUserNotificationCenter.getNotificationSettings()→ parse and format - Type: validation (parse settings, format response)
-
requestNotificationPermission()- Validate: None (request only)
- Delegate:
UNUserNotificationCenter.requestAuthorization(...) - Type: validation (handle async result)
Scheduling (5 methods)
-
scheduleContentFetch()- Validate: Config object required
- Delegate:
DailyNotificationScheduler.scheduleFetch(...)orDailyNotificationBackgroundTaskManager.scheduleFetch(...) - Type: validation (validate config, delegate)
-
scheduleUserNotification()- Validate: Config object required
- Delegate:
DailyNotificationScheduler.scheduleUserNotification(...) - Type: validation (validate config, delegate)
-
scheduleDailyNotification()- Validate: Time format (HH:mm), required parameters
- Delegate:
DailyNotificationScheduler.schedule(...) - Type: validation (validate time format, delegate)
-
scheduleDailyReminder()- Validate: id, title, body, time required; time format (HH:mm)
- Delegate:
DailyNotificationStorage.storeReminder(...)+ schedule notification - Type: validation (validate input, delegate)
-
updateDailyReminder()- Validate: reminderId required
- Delegate:
DailyNotificationStorage.updateReminder(...) - Type: validation (validate input, delegate)
-
cancelDailyReminder()- Validate: reminderId required
- Delegate:
DailyNotificationStorage.removeReminder(id) - Type: validation (validate input, delegate)
Content & History (1 method)
getPendingNotifications()- Validate: None (read-only)
- Delegate:
UNUserNotificationCenter.getPendingNotificationRequests()→ parse and format - Type: validation (parse requests, format response)
Settings & Channels (5 methods)
-
isChannelEnabled()- Validate: channelId (optional)
- Delegate:
UNUserNotificationCenter.getNotificationSettings()→ check channel - Type: validation (parse settings, check channel)
-
openChannelSettings()- Validate: channelId (optional)
- Delegate:
UIApplication.openSettingsURLString(with channel fallback) - Type: validation (needs app context)
-
openNotificationSettings()- Validate: None
- Delegate:
UIApplication.openSettingsURLString - Type: validation (needs app context)
-
openBackgroundAppRefreshSettings()- Validate: None
- Delegate:
UIApplication.openSettingsURLString - Type: validation (needs app context)
-
updateSettings()- Validate: Settings object
- Delegate:
DailyNotificationStorage.updateSettings(...)orDailyNotificationStateActor.saveSettings(...) - Type: validation (validate input, delegate)
Configuration (1 method)
configure()- Validate: Optional parameters (dbPath, storage, ttlSeconds, etc.)
- Delegate:
DailyNotificationStorage.configure(...)or reinitialize storage - Type: validation (validate input, delegate)
Implementation Strategy
- Read current implementation of each method
- Extract validation logic to plugin method (parameter extraction, format validation)
- Identify service method to delegate to (or create if needed)
- Refactor plugin method to: validate → delegate → map response
- Test that external API behavior is unchanged
- Commit in small batches (2-3 methods per commit)
Service Methods Needed
Some service methods may need to be created or enhanced:
DailyNotificationStorage.storeReminder(...)- May need to be createdDailyNotificationStorage.updateReminder(...)- May need to be createdDailyNotificationStorage.removeReminder(id)- May need to be createdDailyNotificationScheduler.scheduleFetch(...)- Check if existsDailyNotificationScheduler.scheduleUserNotification(...)- Check if exists
Notes
- iOS uses
CAPPluginCallfor parameter extraction (similar to Android'sPluginCall) - Error handling uses
call.reject(message, code)withDailyNotificationErrorCodes - Async operations use
Task { }blocks withawait - Settings methods need
UIApplicationaccess (may need activity/view controller) - Permission methods use
UNUserNotificationCenterdirectly (no service wrapper needed)
Estimated Impact
- Methods refactored: 17
- Lines removed: ~400-500 lines (validation logic moved to services where appropriate)
- Complexity reduction: Medium (validation stays in plugin, business logic moves to services)
- Risk: Low-Medium (validation logic changes, but external API unchanged)
Next Batch
After Batch B, proceed to Batch C (glue/orchestration methods) for complex methods that combine multiple services.