mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-07 21:37:02 +09:00
DROID-3362 Widgets | Fix | Should not trigger container creation on irrelevant keys updates (#2467)
This commit is contained in:
parent
4be24285e6
commit
ad1492120e
5 changed files with 83 additions and 6 deletions
|
@ -1350,7 +1350,18 @@ class HomeScreenViewModel(
|
|||
)
|
||||
}
|
||||
is Event.Command.Details -> {
|
||||
curr = curr.copy(details = curr.details.process(e))
|
||||
if (e is Event.Command.Details.Amend) {
|
||||
val hasTargetKeyValueChanges = Widget.Source.SOURCE_KEYS.any { key ->
|
||||
key in e.details.keys
|
||||
}
|
||||
if (hasTargetKeyValueChanges) {
|
||||
curr = curr.copy(details = curr.details.process(e))
|
||||
} else {
|
||||
Timber.d("Widget source reducer: Ignoring Amend event: no relevant keys in ${e.details.keys}")
|
||||
}
|
||||
} else {
|
||||
curr = curr.copy(details = curr.details.process(e))
|
||||
}
|
||||
}
|
||||
is Event.Command.LinkGranularChange -> {
|
||||
curr = curr.copy(
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.anytypeio.anytype.core_models.SupportedLayouts.isSupportedForWidgets
|
|||
import com.anytypeio.anytype.core_models.ext.asMap
|
||||
import com.anytypeio.anytype.core_models.widgets.BundledWidgetSourceIds
|
||||
import com.anytypeio.anytype.domain.primitives.FieldParser
|
||||
import com.anytypeio.anytype.presentation.search.ObjectSearchConstants
|
||||
import com.anytypeio.anytype.presentation.widgets.WidgetView.Name
|
||||
|
||||
sealed class Widget {
|
||||
|
@ -122,6 +123,10 @@ sealed class Widget {
|
|||
override val type: Id? = null
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val SOURCE_KEYS = ObjectSearchConstants.defaultKeys
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ import com.anytypeio.anytype.domain.base.Resultat
|
|||
import com.anytypeio.anytype.domain.bin.EmptyBin
|
||||
import com.anytypeio.anytype.domain.block.interactor.CreateBlock
|
||||
import com.anytypeio.anytype.domain.block.interactor.Move
|
||||
import com.anytypeio.anytype.domain.chats.ChatPreviewContainer
|
||||
import com.anytypeio.anytype.domain.collections.AddObjectToCollection
|
||||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.config.Gateway
|
||||
|
@ -284,6 +285,9 @@ class HomeScreenViewModelTest {
|
|||
@Mock
|
||||
lateinit var setObjectListIsFavorite: SetObjectListIsFavorite
|
||||
|
||||
@Mock
|
||||
lateinit var chacPreviewContainer: ChatPreviewContainer
|
||||
|
||||
lateinit var userPermissionProvider: UserPermissionProvider
|
||||
|
||||
private val objectPayloadDispatcher = Dispatcher.Default<Payload>()
|
||||
|
@ -2930,7 +2934,8 @@ class HomeScreenViewModelTest {
|
|||
spaceMembers = activeSpaceMemberSubscriptionContainer,
|
||||
spaceViewSubscriptionContainer = spaceViewSubscriptionContainer,
|
||||
deleteSpace = deleteSpace,
|
||||
setAsFavourite = setObjectListIsFavorite
|
||||
setAsFavourite = setObjectListIsFavorite,
|
||||
chatPreviews = chacPreviewContainer
|
||||
)
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.anytypeio.anytype.CrashReporter
|
|||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_models.StubConfig
|
||||
import com.anytypeio.anytype.core_models.StubSpaceView
|
||||
import com.anytypeio.anytype.core_models.multiplayer.SpaceUxType
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
import com.anytypeio.anytype.core_models.restrictions.SpaceStatus
|
||||
import com.anytypeio.anytype.domain.auth.interactor.CheckAuthorizationStatus
|
||||
|
@ -319,7 +320,8 @@ class SplashViewModelTest {
|
|||
targetSpaceId = space,
|
||||
spaceLocalStatus = SpaceStatus.OK,
|
||||
spaceAccountStatus = SpaceStatus.OK,
|
||||
chatId = chatId
|
||||
chatId = chatId,
|
||||
spaceUxType = SpaceUxType.CHAT
|
||||
)
|
||||
|
||||
stubCheckAuthStatus(response)
|
||||
|
@ -357,6 +359,58 @@ class SplashViewModelTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should navigate to vault even if chat is available if given space has data ux type`() = runTest {
|
||||
// GIVEN
|
||||
val deeplink = "test-deeplink"
|
||||
val status = AuthStatus.AUTHORIZED
|
||||
val response = Either.Right(status)
|
||||
|
||||
val space = defaultSpaceConfig.space
|
||||
val chatId = "chat-id"
|
||||
|
||||
val spaceView = StubSpaceView(
|
||||
targetSpaceId = space,
|
||||
spaceLocalStatus = SpaceStatus.OK,
|
||||
spaceAccountStatus = SpaceStatus.OK,
|
||||
chatId = chatId,
|
||||
spaceUxType = SpaceUxType.DATA
|
||||
)
|
||||
|
||||
stubCheckAuthStatus(response)
|
||||
stubLaunchWallet()
|
||||
stubLaunchAccount()
|
||||
stubGetLastOpenedObject()
|
||||
|
||||
getLastOpenedSpace.stub {
|
||||
onBlocking { async(Unit) } doReturn Resultat.Success(SpaceId(space))
|
||||
}
|
||||
|
||||
initViewModel()
|
||||
|
||||
// WHEN
|
||||
spaceManager.stub {
|
||||
on { observe() } doReturn flowOf(defaultSpaceConfig)
|
||||
}
|
||||
spaceViewSubscriptionContainer.stub {
|
||||
on { observe(SpaceId(defaultSpaceConfig.space)) } doReturn flowOf(spaceView)
|
||||
}
|
||||
|
||||
vm.commands.test {
|
||||
// Act
|
||||
vm.onDeepLinkLaunch(deeplink)
|
||||
|
||||
val first = awaitItem()
|
||||
assertEquals(
|
||||
expected = SplashViewModel.Command.NavigateToWidgets(
|
||||
space = space,
|
||||
deeplink = deeplink
|
||||
),
|
||||
actual = first
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun stubCheckAuthStatus(response: Either.Right<AuthStatus>) {
|
||||
checkAuthorizationStatus.stub {
|
||||
onBlocking { invoke(eq(Unit)) } doReturn response
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.anytypeio.anytype.core_models
|
||||
|
||||
import com.anytypeio.anytype.core_models.multiplayer.SpaceAccessType
|
||||
import com.anytypeio.anytype.core_models.multiplayer.SpaceUxType
|
||||
import com.anytypeio.anytype.core_models.restrictions.SpaceStatus
|
||||
import com.anytypeio.anytype.test_utils.MockDataFactory
|
||||
|
||||
|
@ -104,8 +105,8 @@ fun StubSpaceView(
|
|||
sharedSpaceLimit: Int? = null,
|
||||
spaceAccountStatus: SpaceStatus? = null,
|
||||
spaceLocalStatus: SpaceStatus? = null,
|
||||
chatId: Id? = null
|
||||
|
||||
chatId: Id? = null,
|
||||
spaceUxType: SpaceUxType = SpaceUxType.DATA,
|
||||
) = ObjectWrapper.SpaceView(
|
||||
map = mapOf(
|
||||
Relations.ID to id,
|
||||
|
@ -114,6 +115,7 @@ fun StubSpaceView(
|
|||
Relations.SPACE_ACCESS_TYPE to spaceAccessType.code.toDouble(),
|
||||
Relations.SHARED_SPACES_LIMIT to sharedSpaceLimit?.toDouble(),
|
||||
Relations.SPACE_ACCOUNT_STATUS to spaceAccountStatus?.code?.toDouble(),
|
||||
Relations.SPACE_LOCAL_STATUS to spaceLocalStatus?.code?.toDouble()
|
||||
Relations.SPACE_LOCAL_STATUS to spaceLocalStatus?.code?.toDouble(),
|
||||
Relations.SPACE_UX_TYPE to spaceUxType.code.toDouble()
|
||||
)
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue