fix(android): parse optional contentFetch timeout/retry fields for dual schedule
JSONObject.getInt threw when timeout/retryAttempts/retryDelay were omitted, but TS ContentFetchConfig marks them optional. Use optIntOrNull so null passes through and FetchWorker keeps its existing defaults. Document omitted-field behavior in README under scheduleDualNotification.
This commit is contained in:
@@ -320,6 +320,8 @@ await DailyNotification.scheduleDualNotification({
|
||||
});
|
||||
```
|
||||
|
||||
If `contentFetch` omits `timeout`, `retryAttempts`, or `retryDelay`, Android applies defaults when scheduling fetch work (currently 30000 ms, 3 attempts, 1000 ms between attempts; see `FetchWorker`).
|
||||
|
||||
### Callback Methods
|
||||
|
||||
#### `registerCallback(name, config)`
|
||||
|
||||
@@ -2394,15 +2394,22 @@ open class DailyNotificationPlugin : Plugin() {
|
||||
}
|
||||
|
||||
// Helper methods
|
||||
/**
|
||||
* Optional int from JSON: absent or JSON-null → null (aligns with TS `ContentFetchConfig` optional fields).
|
||||
* [FetchWorker] applies defaults (e.g. 30000 / 3 / 1000) when null.
|
||||
*/
|
||||
private fun JSObject.optIntOrNull(key: String): Int? =
|
||||
if (has(key) && !isNull(key)) optInt(key) else null
|
||||
|
||||
private fun parseContentFetchConfig(configJson: JSObject): ContentFetchConfig {
|
||||
val callbacksObj = configJson.getJSObject("callbacks")
|
||||
return ContentFetchConfig(
|
||||
enabled = configJson.getBoolean("enabled") ?: true,
|
||||
schedule = configJson.getString("schedule") ?: "0 9 * * *",
|
||||
url = configJson.getString("url"),
|
||||
timeout = configJson.getInt("timeout"),
|
||||
retryAttempts = configJson.getInt("retryAttempts"),
|
||||
retryDelay = configJson.getInt("retryDelay"),
|
||||
timeout = configJson.optIntOrNull("timeout"),
|
||||
retryAttempts = configJson.optIntOrNull("retryAttempts"),
|
||||
retryDelay = configJson.optIntOrNull("retryDelay"),
|
||||
callbacks = CallbackConfig(
|
||||
apiService = callbacksObj?.getString("apiService"),
|
||||
database = callbacksObj?.getString("database"),
|
||||
|
||||
Reference in New Issue
Block a user