mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-1443 App | Tech | Log ignored events in debug mode + feature toggle (#108)
This commit is contained in:
parent
ee42888ea9
commit
a2e3a5e1b3
4 changed files with 58 additions and 39 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.anytypeio.anytype.di.main
|
||||
|
||||
import com.anytypeio.anytype.core_utils.tools.FeatureToggles
|
||||
import com.anytypeio.anytype.data.auth.account.AccountStatusDataChannel
|
||||
import com.anytypeio.anytype.data.auth.account.AccountStatusRemoteChannel
|
||||
import com.anytypeio.anytype.data.auth.event.EventDataChannel
|
||||
|
@ -43,8 +44,9 @@ object EventModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
fun provideEventRemoteChannel(
|
||||
proxy: EventProxy
|
||||
): EventRemoteChannel = MiddlewareEventChannel(events = proxy)
|
||||
proxy: EventProxy,
|
||||
featureToggles: FeatureToggles
|
||||
): EventRemoteChannel = MiddlewareEventChannel(events = proxy, featureToggles = featureToggles)
|
||||
|
||||
@JvmStatic
|
||||
@Provides
|
||||
|
|
|
@ -1,56 +1,26 @@
|
|||
package com.anytypeio.anytype.middleware.interactor
|
||||
|
||||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.core_utils.tools.FeatureToggles
|
||||
import com.anytypeio.anytype.data.auth.event.EventRemoteChannel
|
||||
import com.anytypeio.anytype.middleware.EventProxy
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.map
|
||||
import timber.log.Timber
|
||||
|
||||
class MiddlewareEventChannel(
|
||||
private val events: EventProxy
|
||||
private val events: EventProxy,
|
||||
private val featureToggles: FeatureToggles
|
||||
) : EventRemoteChannel {
|
||||
|
||||
private fun filter(msg: anytype.Event.Message): Boolean {
|
||||
// TODO move to class property, also we should log non filtered events
|
||||
val events = listOf(
|
||||
msg.blockAdd,
|
||||
msg.blockSetText,
|
||||
msg.blockSetChildrenIds,
|
||||
msg.blockSetBackgroundColor,
|
||||
msg.objectDetailsSet,
|
||||
msg.objectDetailsAmend,
|
||||
msg.objectDetailsUnset,
|
||||
msg.blockDelete,
|
||||
msg.blockSetLink,
|
||||
msg.blockSetFile,
|
||||
msg.blockSetFields,
|
||||
msg.blockSetBookmark,
|
||||
msg.blockSetAlign,
|
||||
msg.blockSetDiv,
|
||||
msg.blockSetRelation,
|
||||
msg.blockDataviewRelationSet,
|
||||
msg.blockDataviewRelationDelete,
|
||||
msg.blockDataviewViewDelete,
|
||||
msg.blockDataviewViewOrder,
|
||||
msg.blockDataviewViewSet,
|
||||
msg.objectRelationsAmend,
|
||||
msg.objectRelationsRemove,
|
||||
msg.blockDataviewViewUpdate,
|
||||
msg.blockDataviewTargetObjectIdSet,
|
||||
msg.blockDataviewIsCollectionSet,
|
||||
msg.blockSetWidget
|
||||
)
|
||||
return events.any { it != null }
|
||||
}
|
||||
|
||||
override fun observeEvents(
|
||||
context: String?
|
||||
): Flow<List<Event>> = events
|
||||
.flow()
|
||||
.filter { event -> context == null || event.contextId == context }
|
||||
.map { event ->
|
||||
event.messages.filter { filter(it) }.map { message -> Pair(event.contextId, message) }
|
||||
event.messages.filter { it.isAccepted() }.map { message -> Pair(event.contextId, message) }
|
||||
}
|
||||
.filter { it.isNotEmpty() }
|
||||
.map { events -> processEvents(events) }
|
||||
|
@ -58,4 +28,37 @@ class MiddlewareEventChannel(
|
|||
private fun processEvents(events: List<Pair<String, anytype.Event.Message>>): List<Event.Command> {
|
||||
return events.mapNotNull { (context, event) -> event.toCoreModels(context) }
|
||||
}
|
||||
|
||||
private fun anytype.Event.Message.isAccepted() : Boolean = when {
|
||||
blockAdd != null -> true
|
||||
blockSetText != null -> true
|
||||
blockSetChildrenIds != null -> true
|
||||
blockSetBackgroundColor != null -> true
|
||||
objectDetailsSet != null -> true
|
||||
objectDetailsAmend != null -> true
|
||||
objectDetailsUnset != null -> true
|
||||
blockDelete != null -> true
|
||||
blockSetLink != null -> true
|
||||
blockSetFile != null -> true
|
||||
blockSetFields != null -> true
|
||||
blockSetBookmark != null -> true
|
||||
blockSetAlign != null -> true
|
||||
blockSetDiv != null -> true
|
||||
blockSetRelation != null -> true
|
||||
blockDataviewRelationSet != null -> true
|
||||
blockDataviewRelationDelete != null -> true
|
||||
blockDataviewViewDelete != null -> true
|
||||
blockDataviewViewOrder != null -> true
|
||||
blockDataviewViewSet != null -> true
|
||||
objectRelationsAmend != null -> true
|
||||
objectRelationsRemove != null -> true
|
||||
blockDataviewViewUpdate != null -> true
|
||||
blockDataviewTargetObjectIdSet != null -> true
|
||||
blockDataviewIsCollectionSet != null -> true
|
||||
blockSetWidget != null -> true
|
||||
else -> false.also {
|
||||
if (featureToggles.isLogMiddlewareInteraction && threadStatus == null)
|
||||
Timber.w("Ignored event: $this")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,11 +2,13 @@ package com.anytypeio.anytype.middleware.interactor
|
|||
|
||||
import com.anytypeio.anytype.core_models.Block
|
||||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.middleware.BuildConfig
|
||||
import com.anytypeio.anytype.middleware.mappers.MWidgetLayout
|
||||
import com.anytypeio.anytype.middleware.mappers.toCoreModel
|
||||
import com.anytypeio.anytype.middleware.mappers.toCoreModels
|
||||
import com.anytypeio.anytype.middleware.mappers.toCoreModelsAlign
|
||||
import com.anytypeio.anytype.middleware.mappers.toCoreModelsBookmarkState
|
||||
import timber.log.Timber
|
||||
|
||||
fun anytype.Event.Message.toCoreModels(
|
||||
context: String
|
||||
|
@ -289,5 +291,10 @@ fun anytype.Event.Message.toCoreModels(
|
|||
isCollection = event.value_
|
||||
)
|
||||
}
|
||||
else -> null
|
||||
else -> {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Timber.w("Skipped event while mapping: $this")
|
||||
}
|
||||
null
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import com.anytypeio.anytype.core_models.Event
|
|||
import com.anytypeio.anytype.core_models.RelationFormat
|
||||
import com.anytypeio.anytype.core_models.RelationLink
|
||||
import com.anytypeio.anytype.core_models.ThemeColor
|
||||
import com.anytypeio.anytype.core_utils.tools.FeatureToggles
|
||||
import com.anytypeio.anytype.middleware.EventProxy
|
||||
import com.anytypeio.anytype.middleware.interactor.MiddlewareEventChannel
|
||||
import com.anytypeio.anytype.middleware.mappers.MRelationLink
|
||||
|
@ -24,12 +25,18 @@ class MiddlewareEventChannelTest {
|
|||
@Mock
|
||||
lateinit var proxy: EventProxy
|
||||
|
||||
@Mock
|
||||
lateinit var featureToggles: FeatureToggles
|
||||
|
||||
private lateinit var channel: MiddlewareEventChannel
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
channel = MiddlewareEventChannel(proxy)
|
||||
channel = MiddlewareEventChannel(
|
||||
events = proxy,
|
||||
featureToggles = featureToggles
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue