mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-655 Relations | Refactoring | Implement fallback logic for default object type ID when updating Android app (#2726)
This commit is contained in:
parent
ef784d4f31
commit
e10d35e6b8
5 changed files with 62 additions and 13 deletions
|
@ -21,4 +21,7 @@ object ObjectTypeIds {
|
|||
const val DASHBOARD = "ot-dashboard"
|
||||
const val BOOKMARK = "ot-bookmark"
|
||||
const val RELATION_OPTION = "ot-relationOption"
|
||||
|
||||
const val MARKETPLACE_OBJECT_TYPE_PREFIX = "_ot"
|
||||
const val DEFAULT_OBJECT_TYPE_PREFIX = "ot-"
|
||||
}
|
|
@ -16,7 +16,7 @@ class SetDefaultEditorType(
|
|||
@property [type] object type
|
||||
@see ObjectTypeConst for possible values.
|
||||
**/
|
||||
class Params(
|
||||
data class Params(
|
||||
val type: Id,
|
||||
val name: String
|
||||
)
|
||||
|
|
|
@ -698,7 +698,7 @@ class Middleware(
|
|||
val (image, emoji) = when (val icon = command.icon) {
|
||||
is Command.SetTextIcon.Icon.Emoji -> "" to icon.unicode
|
||||
is Command.SetTextIcon.Icon.Image -> icon.hash to ""
|
||||
Command.SetTextIcon.Icon.None -> "" to ""
|
||||
is Command.SetTextIcon.Icon.None -> "" to ""
|
||||
}
|
||||
val request = Rpc.BlockText.SetIcon.Request(
|
||||
contextId = command.context,
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.anytypeio.anytype.analytics.props.Props
|
|||
import com.anytypeio.anytype.analytics.props.UserProperty
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
import com.anytypeio.anytype.core_models.ObjectTypeIds.MARKETPLACE_OBJECT_TYPE_PREFIX
|
||||
import com.anytypeio.anytype.core_models.ObjectTypeIds.NOTE
|
||||
import com.anytypeio.anytype.core_models.ObjectTypeIds.PAGE
|
||||
import com.anytypeio.anytype.domain.auth.interactor.CheckAuthorizationStatus
|
||||
|
@ -63,8 +64,11 @@ class SplashViewModel(
|
|||
},
|
||||
onSuccess = { result ->
|
||||
Timber.d("getDefaultPageType: ${result.type}")
|
||||
if (result.type == null) {
|
||||
val defaultObjectType = result.type
|
||||
if (defaultObjectType == null) {
|
||||
commands.emit(Command.CheckFirstInstall)
|
||||
} else if (defaultObjectType.contains(MARKETPLACE_OBJECT_TYPE_PREFIX)) {
|
||||
fallbackToNoteAsDefaultObjectType()
|
||||
} else {
|
||||
checkAuthorizationStatus()
|
||||
}
|
||||
|
@ -80,6 +84,24 @@ class SplashViewModel(
|
|||
} else {
|
||||
DEFAULT_TYPE_UPDATE
|
||||
}
|
||||
proceedWithUpdatingDefaultObjectType(
|
||||
typeId = typeId,
|
||||
typeName = typeName
|
||||
)
|
||||
}
|
||||
|
||||
private fun fallbackToNoteAsDefaultObjectType() {
|
||||
val (typeId, typeName) = DEFAULT_TYPE_FIRST_INSTALL
|
||||
proceedWithUpdatingDefaultObjectType(
|
||||
typeId = typeId,
|
||||
typeName = typeName
|
||||
)
|
||||
}
|
||||
|
||||
private fun proceedWithUpdatingDefaultObjectType(
|
||||
typeId: String,
|
||||
typeName: String
|
||||
) {
|
||||
appActionManager.setup(
|
||||
AppActionManager.Action.CreateNew(
|
||||
type = typeId,
|
||||
|
@ -114,7 +136,6 @@ class SplashViewModel(
|
|||
}
|
||||
|
||||
private fun proceedWithLaunchingWallet() {
|
||||
val startTime = System.currentTimeMillis()
|
||||
viewModelScope.launch {
|
||||
launchWallet(BaseUseCase.None).either(
|
||||
fnL = { retryLaunchingWallet() },
|
||||
|
@ -246,7 +267,6 @@ class SplashViewModel(
|
|||
|
||||
companion object {
|
||||
const val ERROR_MESSAGE = "An error occurred while starting account..."
|
||||
//ToDo better to take the name from middleware (see GetLastOpenedObject use case)
|
||||
val DEFAULT_TYPE_FIRST_INSTALL = Pair(NOTE, "Note")
|
||||
val DEFAULT_TYPE_UPDATE = Pair(PAGE, "Page")
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.anytypeio.anytype.presentation.splash
|
|||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_models.ObjectTypeIds
|
||||
import com.anytypeio.anytype.domain.`object`.ObjectTypesProvider
|
||||
import com.anytypeio.anytype.domain.auth.interactor.CheckAuthorizationStatus
|
||||
import com.anytypeio.anytype.domain.auth.interactor.GetLastOpenedObject
|
||||
import com.anytypeio.anytype.domain.auth.interactor.LaunchAccount
|
||||
|
@ -12,7 +11,6 @@ import com.anytypeio.anytype.domain.auth.model.AuthStatus
|
|||
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import com.anytypeio.anytype.domain.config.UserSettingsRepository
|
||||
import com.anytypeio.anytype.domain.launch.GetDefaultEditorType
|
||||
import com.anytypeio.anytype.domain.launch.SetDefaultEditorType
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
|
@ -20,8 +18,10 @@ import com.anytypeio.anytype.domain.page.CreatePage
|
|||
import com.anytypeio.anytype.domain.search.ObjectTypesSubscriptionManager
|
||||
import com.anytypeio.anytype.domain.search.RelationsSubscriptionManager
|
||||
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
|
||||
import com.anytypeio.anytype.test_utils.MockDataFactory
|
||||
import com.anytypeio.anytype.test_utils.ValueClassAnswer
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
import org.junit.Rule
|
||||
|
@ -35,6 +35,7 @@ import org.mockito.kotlin.eq
|
|||
import org.mockito.kotlin.stub
|
||||
import org.mockito.kotlin.times
|
||||
import org.mockito.kotlin.verify
|
||||
import org.mockito.kotlin.verifyNoInteractions
|
||||
import org.mockito.kotlin.verifyNoMoreInteractions
|
||||
|
||||
class SplashViewModelTest {
|
||||
|
@ -63,12 +64,6 @@ class SplashViewModelTest {
|
|||
@Mock
|
||||
lateinit var auth: AuthRepository
|
||||
|
||||
@Mock
|
||||
lateinit var objectTypesProvider: ObjectTypesProvider
|
||||
|
||||
@Mock
|
||||
lateinit var userSettingsRepo: UserSettingsRepository
|
||||
|
||||
private lateinit var getLastOpenedObject: GetLastOpenedObject
|
||||
|
||||
@Mock
|
||||
|
@ -235,6 +230,37 @@ class SplashViewModelTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should fallback to default object type if default object type contains deprecated prefix id`() = runTest {
|
||||
stubCheckAuthStatus(Either.Right(AuthStatus.AUTHORIZED))
|
||||
stubLaunchWallet()
|
||||
stubLaunchAccount()
|
||||
stubGetLastOpenedObject()
|
||||
stubGetDefaultObjectType(type = ObjectTypeIds.MARKETPLACE_OBJECT_TYPE_PREFIX + MockDataFactory.randomUuid())
|
||||
|
||||
initViewModel()
|
||||
|
||||
verify(setDefaultEditorType, times(1)).invoke(
|
||||
SetDefaultEditorType.Params(
|
||||
SplashViewModel.DEFAULT_TYPE_FIRST_INSTALL.first,
|
||||
SplashViewModel.DEFAULT_TYPE_FIRST_INSTALL.second
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should not fallback to default object type if default object type does not contain deprecated prefix id`() = runTest {
|
||||
stubCheckAuthStatus(Either.Right(AuthStatus.AUTHORIZED))
|
||||
stubLaunchWallet()
|
||||
stubLaunchAccount()
|
||||
stubGetLastOpenedObject()
|
||||
stubGetDefaultObjectType(type = ObjectTypeIds.DEFAULT_OBJECT_TYPE_PREFIX + MockDataFactory.randomUuid())
|
||||
|
||||
initViewModel()
|
||||
|
||||
verifyNoInteractions(setDefaultEditorType)
|
||||
}
|
||||
|
||||
//Todo can't mock Amplitude
|
||||
// @Test
|
||||
// fun `should emit appropriate navigation command if account is launched`() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue