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)
151 lines
5.7 KiB
Markdown
151 lines
5.7 KiB
Markdown
# P2.1 iOS Batch B - Current State Directive
|
|
|
|
**Purpose:** State snapshot for reconstituting work on iOS Batch B refactoring
|
|
**Owner:** Development Team
|
|
**Created:** 2025-12-23
|
|
**Status:** ready
|
|
**Baseline:** See `docs/progress/00-STATUS.md` (v1.0.11-p3-complete)
|
|
|
|
---
|
|
|
|
## Current Work Status
|
|
|
|
**Phase:** P2.1 - iOS Native Plugin Refactoring (Batch B)
|
|
**Goal:** Refactor validation + delegation methods to thin adapter pattern
|
|
**Status:** ✅ **BATCH B COMPLETE** — 17 methods refactored
|
|
|
|
---
|
|
|
|
## Completed Refactorings (17 methods)
|
|
|
|
### Permissions (4 methods) ✅
|
|
1. ✅ `checkPermissionStatus()` - Simplified, removed redundant logging
|
|
2. ✅ `requestNotificationPermissions()` - Simplified, direct delegation
|
|
3. ✅ `getNotificationPermissionStatus()` - Consistent error handling
|
|
4. ✅ `requestNotificationPermission()` - Consistent error handling pattern
|
|
|
|
### Settings & Channels (5 methods) ✅
|
|
5. ✅ `isChannelEnabled()` - Removed redundant scheduler initialization
|
|
6. ✅ `openChannelSettings()` - Removed redundant logging, simplified validation
|
|
7. ✅ `openNotificationSettings()` - Simplified validation pattern
|
|
8. ✅ `openBackgroundAppRefreshSettings()` - Simplified validation pattern
|
|
9. ✅ `updateSettings()` - Simplified conditional logic
|
|
|
|
### Content (1 method) ✅
|
|
10. ✅ `getPendingNotifications()` - Added delegation comment
|
|
|
|
### Scheduling (6 methods) ✅
|
|
11. ✅ `scheduleContentFetch()` - Removed redundant logging, added delegation comment
|
|
12. ✅ `scheduleUserNotification()` - Removed redundant logging, added delegation comment
|
|
13. ✅ `scheduleDualNotification()` - Removed redundant logging, added delegation comment
|
|
14. ✅ `scheduleDailyNotification()` - Simplified logging, added delegation comments
|
|
15. ✅ `scheduleDailyReminder()` - Removed redundant logging, added delegation comment
|
|
16. ✅ `cancelDailyReminder()` - Removed redundant logging, added delegation comment
|
|
17. ✅ `updateDailyReminder()` - Removed redundant logging
|
|
|
|
### Configuration (1 method) ✅
|
|
18. ✅ `configure()` - Removed redundant logging, simplified do-catch block
|
|
|
|
---
|
|
|
|
## Target Methods (Batch B - 17 methods) - COMPLETE
|
|
|
|
### Permissions (4 methods)
|
|
|
|
1. **`checkPermissionStatus()`** - Parse UNUserNotificationCenter settings
|
|
2. **`requestNotificationPermissions()`** - Request authorization
|
|
3. **`getNotificationPermissionStatus()`** - Parse settings (duplicate of #1?)
|
|
4. **`requestNotificationPermission()`** - Request authorization (duplicate of #2?)
|
|
|
|
### Scheduling (6 methods)
|
|
|
|
5. **`scheduleContentFetch()`** - Validate config, delegate to scheduler/background manager
|
|
6. **`scheduleUserNotification()`** - Validate config, delegate to scheduler
|
|
7. **`scheduleDailyNotification()`** - Validate time format, delegate to scheduler
|
|
8. **`scheduleDailyReminder()`** - Validate input, store + schedule
|
|
9. **`updateDailyReminder()`** - Validate reminderId, update
|
|
10. **`cancelDailyReminder()`** - Validate reminderId, remove
|
|
|
|
### Content & History (1 method)
|
|
|
|
11. **`getPendingNotifications()`** - Parse pending requests, format response
|
|
|
|
### Settings & Channels (5 methods)
|
|
|
|
12. **`isChannelEnabled()`** - Parse settings, check channel
|
|
13. **`openChannelSettings()`** - Open settings with channel fallback
|
|
14. **`openNotificationSettings()`** - Open notification settings
|
|
15. **`openBackgroundAppRefreshSettings()`** - Open background refresh settings
|
|
16. **`updateSettings()`** - Validate settings, delegate to storage/stateActor
|
|
|
|
### Configuration (1 method)
|
|
|
|
17. **`configure()`** - Validate config, reinitialize storage if needed
|
|
|
|
---
|
|
|
|
## Service Initialization (Current State)
|
|
|
|
Services are initialized in `load()`:
|
|
```swift
|
|
storage = DailyNotificationStorage(databasePath: database.getPath())
|
|
scheduler = DailyNotificationScheduler()
|
|
reactivationManager = DailyNotificationReactivationManager(...)
|
|
stateActor = DailyNotificationStateActor(...) // iOS 13+
|
|
notificationCenter = UNUserNotificationCenter.current()
|
|
```
|
|
|
|
---
|
|
|
|
## Implementation Notes
|
|
|
|
### iOS-Specific Patterns
|
|
- Parameter extraction: `call.getString("param")`, `call.getInt("param")`, `call.getObject("param")`
|
|
- Error handling: `call.reject(message, code)` with `DailyNotificationErrorCodes`
|
|
- Async operations: `Task { }` blocks with `await` for async service calls
|
|
- Settings access: `UIApplication.shared.open(settingsUrl)` needs main thread
|
|
- Permission requests: `UNUserNotificationCenter.requestAuthorization(...)` is async
|
|
|
|
### Validation Patterns
|
|
- Required parameters: `guard let param = call.getString("param") else { call.reject(...); return }`
|
|
- Format validation: Time format (HH:mm), validate hour (0-23), minute (0-59)
|
|
- Error codes: Use `DailyNotificationErrorCodes.missingParameter()`, `invalidTimeFormat()`, etc.
|
|
|
|
---
|
|
|
|
## Next Steps
|
|
|
|
1. **Start with permission methods** (simplest - read-only or single async call)
|
|
2. **Then scheduling methods** (more complex validation)
|
|
3. **Then settings methods** (UIApplication access)
|
|
4. **Finally configuration** (most complex - may need reinitialization)
|
|
|
|
---
|
|
|
|
## Progress Summary
|
|
|
|
- **Methods refactored:** 17/17 ✅
|
|
- **Lines reduced:** 163 lines net (326 removed, 163 added)
|
|
- **Complexity reduction:** Medium (consistent patterns, removed redundant code)
|
|
- **Risk:** Low (external API unchanged, only code cleanup)
|
|
|
|
## Impact
|
|
|
|
- **Before:** 2047 LOC
|
|
- **After:** 1884 LOC
|
|
- **Reduction:** 163 lines (8% reduction)
|
|
- **Pattern consistency:** All methods now follow validate → delegate pattern
|
|
- **Code quality:** Removed redundant logging, simplified conditionals
|
|
|
|
---
|
|
|
|
## Success Criteria
|
|
|
|
- [ ] All 17 methods refactored to validate → delegate pattern
|
|
- [ ] Validation logic remains in plugin (appropriate)
|
|
- [ ] Business logic moved to services
|
|
- [ ] External API behavior unchanged
|
|
- [ ] Tests pass
|
|
- [ ] Documentation updated
|
|
|