Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ class OrgRepo(
) {
private var currentOrg: Org? = null

private val ORG_CONFIG_SYNCED_KEY = PrefKeys.SYSTEM_SETTINGS + PrefKey("org-config-synced")

// In OrgRepo.kt
fun hasCompletedInitialOrgSync(): Boolean = prefs.getBoolean(ORG_CONFIG_SYNCED_KEY, false)

fun markInitialOrgSyncComplete() {
prefs.edit().putBoolean(ORG_CONFIG_SYNCED_KEY, true).commit()
}

fun resetInitialOrgSync() {
prefs.edit().putBoolean(ORG_CONFIG_SYNCED_KEY, false).commit()
}

suspend fun init() {
dao.insertOrg(defaultOrgEntity())
val currentOrgId = prefs.getString(CURRENT_ORG_ID_KEY, DEFAULT_ORG_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ class SplashScreenViewModel(
if (!orgId.isNullOrBlank()) {
Timber.tag(ORG_LINK_TAG).i("Deeplink received: orgId=$orgId, orgName=$orgName")
val configJson = orgConfigProvider.fetchOrgConfig(orgId)
if (configJson != null) {
// Non-deeplink launch: refresh current org config if we haven't yet

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually a deeplink launch.

val currentOrg = orgRepo.currentOrg()
if (currentOrg.id != OrgRepo.DEFAULT_ORG_ID && !orgRepo.hasCompletedInitialOrgSync()) {
Timber.tag(ORG_LINK_TAG).d("Fetching Remote Config for org ${currentOrg.id}")
if (configJson != null) {
orgRepo.addOrgFromRemoteConfig(currentOrg.id, currentOrg.name, configJson)
orgRepo.markInitialOrgSyncComplete()
}
Comment thread
jaycenusa marked this conversation as resolved.
} else if (configJson != null) {
Timber.tag(ORG_LINK_TAG).i("Remote Config found for org $orgId, applying full config")
orgRepo.addOrgFromRemoteConfig(orgId, orgName ?: "", configJson)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ class SplashScreenViewModelTest {
@Before
fun setUp() {
MockKAnnotations.init(this)
// Default behavior to maintain existing test expectations:
// Assume sync is already complete so the "refresh" logic doesn't trigger unexpectedly.
every { orgRepo.hasCompletedInitialOrgSync() } returns true
every { orgRepo.currentOrg() } returns
io.mockk.mockk {
every { id } returns OrgRepo.DEFAULT_ORG_ID
}
splashScreenViewModel =
SplashScreenViewModel(
orgId = orgId,
Expand Down
Loading