fix NS profile sync

This commit is contained in:
Milos Kozak 2021-10-24 00:20:07 +02:00
parent 9935ff90a1
commit 3b30f73209
2 changed files with 5 additions and 5 deletions

View file

@ -458,11 +458,11 @@ class LocalProfilePlugin @Inject constructor(
?: return Result.failure(workDataOf("Error" to "missing input data")) ?: return Result.failure(workDataOf("Error" to "missing input data"))
if (sp.getBoolean(R.string.key_ns_receive_profile_store, true) || config.NSCLIENT) { if (sp.getBoolean(R.string.key_ns_receive_profile_store, true) || config.NSCLIENT) {
val store = ProfileStore(injector, profileJson, dateUtil) val store = ProfileStore(injector, profileJson, dateUtil)
val startDate = store.getStartDate() val createdAt = store.getCreatedAt()
val lastLocalChange = sp.getLong(R.string.key_local_profile_last_change, 0) val lastLocalChange = sp.getLong(R.string.key_local_profile_last_change, 0)
aapsLogger.debug(LTag.PROFILE, "Received profileStore: StartDate: $startDate Local last modification: $lastLocalChange") aapsLogger.debug(LTag.PROFILE, "Received profileStore: createdAt: $createdAt Local last modification: $lastLocalChange")
@Suppress("LiftReturnOrAssignment") @Suppress("LiftReturnOrAssignment")
if (startDate > lastLocalChange || startDate % 1000 == 0L) {// whole second means edited in NS if (createdAt > lastLocalChange || createdAt % 1000 == 0L) {// whole second means edited in NS
localProfilePlugin.loadFromStore(store) localProfilePlugin.loadFromStore(store)
aapsLogger.debug(LTag.PROFILE, "Received profileStore: $profileJson") aapsLogger.debug(LTag.PROFILE, "Received profileStore: $profileJson")
return Result.success(workDataOf("Data" to profileJson.toString().substring(0..min(5000, profileJson.length())))) return Result.success(workDataOf("Data" to profileJson.toString().substring(0..min(5000, profileJson.length()))))

View file

@ -31,8 +31,8 @@ class ProfileStore(val injector: HasAndroidInjector, val data: JSONObject, val d
return null return null
} }
fun getStartDate(): Long { fun getCreatedAt(): Long {
val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0 val iso = JsonHelper.safeGetString(data, "created_at") ?: return 0
return try { return try {
dateUtil.fromISODateString(iso) dateUtil.fromISODateString(iso)
} catch (e: Exception) { } catch (e: Exception) {