diff --git a/android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt b/android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt index 49dc010..f93f04b 100644 --- a/android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt +++ b/android/src/main/java/com/timesafari/dailynotification/DailyNotificationPlugin.kt @@ -1674,17 +1674,30 @@ open class DailyNotificationPlugin : Plugin() { CoroutineScope(Dispatchers.IO).launch { try { val latestCache = getDatabase().contentCacheDao().getLatest() - val result = JSObject() if (latestCache != null) { - result.put("id", latestCache.id) - result.put("fetchedAt", latestCache.fetchedAt) - result.put("ttlSeconds", latestCache.ttlSeconds) - result.put("payload", String(latestCache.payload)) - result.put("meta", latestCache.meta) + // Use Contract v1 DTO via mapper + val dto = com.timesafari.dailynotification.dto.NotificationContentMapper.cacheToDTO(latestCache) + if (dto != null) { + // Convert DTO to JSObject for Capacitor response (Contract v1 field names) + val result = JSObject().apply { + put("id", dto.id) + put("title", dto.title) + if (dto.body != null) put("body", dto.body) + if (dto.scheduledTime != null) put("scheduledTime", dto.scheduledTime) + put("fetchTime", dto.fetchTime) // Contract v1 field name + if (dto.mediaUrl != null) put("mediaUrl", dto.mediaUrl) + if (dto.ttlSeconds != null) put("ttlSeconds", dto.ttlSeconds) + if (dto.dedupeKey != null) put("dedupeKey", dto.dedupeKey) + if (dto.priority != null) put("priority", dto.priority) + } + call.resolve(result) + } else { + call.reject("Failed to convert cache to DTO") + } + } else { + call.resolve(JSObject()) } - - call.resolve(result) } catch (e: Exception) { Log.e(TAG, "Failed to get content cache", e) call.reject("Content cache retrieval failed: ${e.message}") @@ -2398,12 +2411,30 @@ open class DailyNotificationPlugin : Plugin() { } private fun contentCacheToJson(cache: ContentCache): JSObject { - return JSObject().apply { - put("id", cache.id) - put("fetchedAt", cache.fetchedAt) - put("ttlSeconds", cache.ttlSeconds) - put("payload", String(cache.payload)) - put("meta", cache.meta) + // Use Contract v1 DTO via mapper + val dto = com.timesafari.dailynotification.dto.NotificationContentMapper.cacheToDTO(cache) + return if (dto != null) { + // Convert DTO to JSObject for Capacitor response (Contract v1 field names) + JSObject().apply { + put("id", dto.id) + put("title", dto.title) + if (dto.body != null) put("body", dto.body) + if (dto.scheduledTime != null) put("scheduledTime", dto.scheduledTime) + put("fetchTime", dto.fetchTime) // Contract v1 field name + if (dto.mediaUrl != null) put("mediaUrl", dto.mediaUrl) + if (dto.ttlSeconds != null) put("ttlSeconds", dto.ttlSeconds) + if (dto.dedupeKey != null) put("dedupeKey", dto.dedupeKey) + if (dto.priority != null) put("priority", dto.priority) + } + } else { + // Fallback to old format if conversion fails + JSObject().apply { + put("id", cache.id) + put("fetchedAt", cache.fetchedAt) + put("ttlSeconds", cache.ttlSeconds) + put("payload", String(cache.payload)) + put("meta", cache.meta) + } } }