in shared/src/commonMain/kotlin/org/jetbrains/kotlinconf/ConferenceService.kt [119:155]
suspend fun loadConferenceData() {
val newData = client.downloadConferenceData() ?: return
val oldData = storage.getConferenceCache().first()
storage.setConferenceCache(newData)
if (oldData != null) {
val oldSessions = oldData.sessions.associateBy { it.id }
val newSessions = newData.sessions.associateBy { it.id }
// Cancel notifications for removed sessions
val removedIds = oldSessions.keys - newSessions.keys
removedIds.forEach { sessionId ->
cancelNotifications(sessionId)
}
// Remove removed sessions from favorites
val favorites = storage.getFavorites().first().toMutableSet()
favorites.removeAll { it in removedIds }
storage.setFavorites(favorites)
// Check if any favorite sessions were rescheduled
favorites.forEach { sessionId ->
val newSession = newSessions[sessionId] ?: return@forEach
val oldSession = oldSessions[sessionId] ?: return@forEach
if (oldSession.startsAt != newSession.startsAt || oldSession.endsAt != newSession.endsAt) {
cancelNotifications(sessionId)
scheduleNotification(
start = newSession.startsAt,
end = newSession.endsAt,
sessionId = newSession.id,
title = newSession.title,
)
}
}
}
}