fix: race condition on changelog fetch
This commit is contained in:
parent
cbcacbe3af
commit
fb31742863
|
|
@ -10,6 +10,7 @@ import chat.stoat.core.model.schemas.NotificationSettings
|
||||||
import chat.stoat.core.model.schemas.OrderingSettings
|
import chat.stoat.core.model.schemas.OrderingSettings
|
||||||
import chat.stoat.core.model.schemas.ReleaseNotesSettings
|
import chat.stoat.core.model.schemas.ReleaseNotesSettings
|
||||||
import chat.stoat.core.model.schemas._NotificationSettingsToParse
|
import chat.stoat.core.model.schemas._NotificationSettingsToParse
|
||||||
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
import kotlinx.serialization.json.JsonPrimitive
|
import kotlinx.serialization.json.JsonPrimitive
|
||||||
import kotlinx.serialization.json.jsonPrimitive
|
import kotlinx.serialization.json.jsonPrimitive
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
|
|
@ -24,6 +25,10 @@ import logcat.logcat
|
||||||
*/
|
*/
|
||||||
|
|
||||||
object SyncedSettings {
|
object SyncedSettings {
|
||||||
|
private val _fetchCompleted = CompletableDeferred<Unit>()
|
||||||
|
|
||||||
|
suspend fun awaitFetched() = _fetchCompleted.await()
|
||||||
|
|
||||||
private val _ordering = mutableStateOf(OrderingSettings())
|
private val _ordering = mutableStateOf(OrderingSettings())
|
||||||
private val _android = mutableStateOf(
|
private val _android = mutableStateOf(
|
||||||
AndroidSpecificSettings(
|
AndroidSpecificSettings(
|
||||||
|
|
@ -93,6 +98,8 @@ object SyncedSettings {
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
} finally {
|
||||||
|
_fetchCompleted.complete(Unit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -276,6 +276,7 @@ class ChatRouterViewModel(
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SyncedSettings.awaitFetched()
|
||||||
val lastSeenChangelog = SyncedSettings.releaseNotes.lastSeenId
|
val lastSeenChangelog = SyncedSettings.releaseNotes.lastSeenId
|
||||||
if (lastSeenChangelog == null || lastSeenChangelog != latestChangelog.id) {
|
if (lastSeenChangelog == null || lastSeenChangelog != latestChangelog.id) {
|
||||||
showChangelogScreenForId = latestChangelog.id
|
showChangelogScreenForId = latestChangelog.id
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue