feat(ios): Extract orchestration helpers to ScheduleHelper
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)
This commit is contained in:
170
docs/progress/P2.1-IOS-BATCH-B.md
Normal file
170
docs/progress/P2.1-IOS-BATCH-B.md
Normal file
@@ -0,0 +1,170 @@
|
||||
# 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)
|
||||
|
||||
1. **`checkPermissionStatus()`**
|
||||
- Validate: None (read-only)
|
||||
- Delegate: `UNUserNotificationCenter.getNotificationSettings()` → parse and format
|
||||
- Type: validation (parse settings, format response)
|
||||
|
||||
2. **`requestNotificationPermissions()`**
|
||||
- Validate: None (request only)
|
||||
- Delegate: `UNUserNotificationCenter.requestAuthorization(...)`
|
||||
- Type: validation (handle async result)
|
||||
|
||||
3. **`getNotificationPermissionStatus()`**
|
||||
- Validate: None (read-only)
|
||||
- Delegate: `UNUserNotificationCenter.getNotificationSettings()` → parse and format
|
||||
- Type: validation (parse settings, format response)
|
||||
|
||||
4. **`requestNotificationPermission()`**
|
||||
- Validate: None (request only)
|
||||
- Delegate: `UNUserNotificationCenter.requestAuthorization(...)`
|
||||
- Type: validation (handle async result)
|
||||
|
||||
### Scheduling (5 methods)
|
||||
|
||||
5. **`scheduleContentFetch()`**
|
||||
- Validate: Config object required
|
||||
- Delegate: `DailyNotificationScheduler.scheduleFetch(...)` or `DailyNotificationBackgroundTaskManager.scheduleFetch(...)`
|
||||
- Type: validation (validate config, delegate)
|
||||
|
||||
6. **`scheduleUserNotification()`**
|
||||
- Validate: Config object required
|
||||
- Delegate: `DailyNotificationScheduler.scheduleUserNotification(...)`
|
||||
- Type: validation (validate config, delegate)
|
||||
|
||||
7. **`scheduleDailyNotification()`**
|
||||
- Validate: Time format (HH:mm), required parameters
|
||||
- Delegate: `DailyNotificationScheduler.schedule(...)`
|
||||
- Type: validation (validate time format, delegate)
|
||||
|
||||
8. **`scheduleDailyReminder()`**
|
||||
- Validate: id, title, body, time required; time format (HH:mm)
|
||||
- Delegate: `DailyNotificationStorage.storeReminder(...)` + schedule notification
|
||||
- Type: validation (validate input, delegate)
|
||||
|
||||
9. **`updateDailyReminder()`**
|
||||
- Validate: reminderId required
|
||||
- Delegate: `DailyNotificationStorage.updateReminder(...)`
|
||||
- Type: validation (validate input, delegate)
|
||||
|
||||
10. **`cancelDailyReminder()`**
|
||||
- Validate: reminderId required
|
||||
- Delegate: `DailyNotificationStorage.removeReminder(id)`
|
||||
- Type: validation (validate input, delegate)
|
||||
|
||||
### Content & History (1 method)
|
||||
|
||||
11. **`getPendingNotifications()`**
|
||||
- Validate: None (read-only)
|
||||
- Delegate: `UNUserNotificationCenter.getPendingNotificationRequests()` → parse and format
|
||||
- Type: validation (parse requests, format response)
|
||||
|
||||
### Settings & Channels (5 methods)
|
||||
|
||||
12. **`isChannelEnabled()`**
|
||||
- Validate: channelId (optional)
|
||||
- Delegate: `UNUserNotificationCenter.getNotificationSettings()` → check channel
|
||||
- Type: validation (parse settings, check channel)
|
||||
|
||||
13. **`openChannelSettings()`**
|
||||
- Validate: channelId (optional)
|
||||
- Delegate: `UIApplication.openSettingsURLString` (with channel fallback)
|
||||
- Type: validation (needs app context)
|
||||
|
||||
14. **`openNotificationSettings()`**
|
||||
- Validate: None
|
||||
- Delegate: `UIApplication.openSettingsURLString`
|
||||
- Type: validation (needs app context)
|
||||
|
||||
15. **`openBackgroundAppRefreshSettings()`**
|
||||
- Validate: None
|
||||
- Delegate: `UIApplication.openSettingsURLString`
|
||||
- Type: validation (needs app context)
|
||||
|
||||
16. **`updateSettings()`**
|
||||
- Validate: Settings object
|
||||
- Delegate: `DailyNotificationStorage.updateSettings(...)` or `DailyNotificationStateActor.saveSettings(...)`
|
||||
- Type: validation (validate input, delegate)
|
||||
|
||||
### Configuration (1 method)
|
||||
|
||||
17. **`configure()`**
|
||||
- Validate: Optional parameters (dbPath, storage, ttlSeconds, etc.)
|
||||
- Delegate: `DailyNotificationStorage.configure(...)` or reinitialize storage
|
||||
- Type: validation (validate input, delegate)
|
||||
|
||||
---
|
||||
|
||||
## Implementation Strategy
|
||||
|
||||
1. **Read current implementation** of each method
|
||||
2. **Extract validation logic** to plugin method (parameter extraction, format validation)
|
||||
3. **Identify service method** to delegate to (or create if needed)
|
||||
4. **Refactor plugin method** to: validate → delegate → map response
|
||||
5. **Test** that external API behavior is unchanged
|
||||
6. **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 created
|
||||
- `DailyNotificationStorage.updateReminder(...)` - May need to be created
|
||||
- `DailyNotificationStorage.removeReminder(id)` - May need to be created
|
||||
- `DailyNotificationScheduler.scheduleFetch(...)` - Check if exists
|
||||
- `DailyNotificationScheduler.scheduleUserNotification(...)` - Check if exists
|
||||
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
- iOS uses `CAPPluginCall` for parameter extraction (similar to Android's `PluginCall`)
|
||||
- Error handling uses `call.reject(message, code)` with `DailyNotificationErrorCodes`
|
||||
- Async operations use `Task { }` blocks with `await`
|
||||
- Settings methods need `UIApplication` access (may need activity/view controller)
|
||||
- Permission methods use `UNUserNotificationCenter` directly (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.
|
||||
|
||||
Reference in New Issue
Block a user