Skip to content

Commit a2ede76

Browse files
uburoiubukonstantiniiv
authored andcommitted
DROID-4168 Chats | Chats analytics update for multi-chats (#2989)
Co-authored-by: Konstantin Ivanov <54908981+konstantiniiv@users.noreply.github.com> (cherry picked from commit a01fbe9) # Conflicts: # feature-chats/src/main/java/com/anytypeio/anytype/feature_chats/presentation/ChatViewModel.kt
1 parent f1348de commit a2ede76

File tree

6 files changed

+67
-1
lines changed

6 files changed

+67
-1
lines changed

analytics/src/main/java/com/anytypeio/anytype/analytics/base/EventsDictionary.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ object EventsDictionary {
194194
// Vault events
195195

196196
const val screenVault = "ScreenVault"
197+
const val screenChatInfo = "ScreenChatInfo"
197198

198199
// About-app screen
199200

@@ -362,6 +363,9 @@ object EventsDictionary {
362363
const val chatClickScrollToMention = "ClickScrollToMention"
363364
const val chatClickScrollToReply = "ClickScrollToReply"
364365

366+
// Notification changes
367+
const val changeMessageNotificationState = "ChangeMessageNotificationState"
368+
365369
// --- Vault menu ---
366370
const val chatScreenVaultCreateMenu = "ScreenVaultCreateMenu"
367371
const val chatClickVaultCreateMenuChat = "ClickVaultCreateMenuChat"

app/src/main/java/com/anytypeio/anytype/di/feature/widgets/CreateChatObjectDI.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.anytypeio.anytype.di.feature.widgets
22

33
import androidx.lifecycle.ViewModelProvider
4+
import com.anytypeio.anytype.analytics.base.Analytics
45
import com.anytypeio.anytype.core_utils.di.scope.PerScreen
56
import com.anytypeio.anytype.di.common.ComponentDependencies
67
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
@@ -44,6 +45,7 @@ object CreateChatObjectModule {
4445
}
4546

4647
interface CreateChatObjectDependencies : ComponentDependencies {
48+
fun analytics(): Analytics
4749
fun repo(): BlockRepository
4850
fun dispatchers(): AppCoroutineDispatchers
4951
fun settings(): UserSettingsRepository

feature-chats/src/main/java/com/anytypeio/anytype/feature_chats/presentation/ChatViewModel.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import com.anytypeio.anytype.feature_chats.tools.syncStatus
6767
import com.anytypeio.anytype.feature_chats.tools.toNotificationSetting
6868
import com.anytypeio.anytype.feature_chats.tools.toNotificationState
6969
import com.anytypeio.anytype.presentation.common.BaseViewModel
70+
import com.anytypeio.anytype.presentation.extension.sendAnalyticsChangeMessageNotificationState
7071
import com.anytypeio.anytype.presentation.confgs.ChatConfig
7172
import com.anytypeio.anytype.presentation.home.OpenObjectNavigation
7273
import com.anytypeio.anytype.presentation.home.navigation
@@ -1638,6 +1639,8 @@ class ChatViewModel @Inject constructor(
16381639
val headerView = header.value
16391640
if (headerView is HeaderView.ChatObject) {
16401641
val name = headerView.title
1642+
// Fire analytics event for opening chat info screen
1643+
analytics.sendEvent(eventName = EventsDictionary.screenChatInfo)
16411644
commands.emit(
16421645
ViewModelCommand.OpenChatInfo(
16431646
name = name,
@@ -1963,7 +1966,12 @@ class ChatViewModel @Inject constructor(
19631966
mode = mode
19641967
)
19651968
).onSuccess { payload ->
1966-
Timber.d("Notification setting changed successfully to: $setting, for chat: ${vmParams.ctx}")
1969+
Timber.d("Notification setting changed successfully to: $setting")
1970+
// Fire analytics event for chat-level notification change
1971+
analytics.sendAnalyticsChangeMessageNotificationState(
1972+
spaceUxType = _currentSpaceUxType.value,
1973+
notificationState = setting.toNotificationState()
1974+
)
19671975
}.onFailure { e ->
19681976
Timber.e(e, "Failed to change notification setting")
19691977
// Revert header to previous state on error

presentation/src/main/java/com/anytypeio/anytype/presentation/extension/AnalyticsExt.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import com.anytypeio.anytype.core_models.WidgetLayout
5858
import com.anytypeio.anytype.core_models.getSingleValue
5959
import com.anytypeio.anytype.core_models.multiplayer.InviteType
6060
import com.anytypeio.anytype.core_models.multiplayer.SpaceMemberPermissions
61+
import com.anytypeio.anytype.core_models.chats.NotificationState
6162
import com.anytypeio.anytype.core_models.multiplayer.SpaceUxType
6263
import com.anytypeio.anytype.core_models.primitives.RelationKey
6364
import com.anytypeio.anytype.core_utils.ext.Mimetype
@@ -2728,3 +2729,30 @@ fun CoroutineScope.sendAnalyticsScreenObjectType(
27282729
}
27292730
//endregion
27302731

2732+
//region Notifications
2733+
suspend fun Analytics.sendAnalyticsChangeMessageNotificationState(
2734+
spaceUxType: SpaceUxType?,
2735+
notificationState: NotificationState
2736+
) {
2737+
val uxType = when (spaceUxType) {
2738+
SpaceUxType.ONE_TO_ONE -> "OneToOne"
2739+
SpaceUxType.CHAT -> "Chat"
2740+
else -> "Data"
2741+
}
2742+
val type = when (notificationState) {
2743+
NotificationState.ALL -> "All"
2744+
NotificationState.MENTIONS -> "Mentions"
2745+
NotificationState.DISABLE -> "Nothing"
2746+
}
2747+
sendEvent(
2748+
eventName = EventsDictionary.changeMessageNotificationState,
2749+
props = Props(
2750+
mapOf(
2751+
EventsPropertiesKey.uxType to uxType,
2752+
EventsPropertiesKey.type to type
2753+
)
2754+
)
2755+
)
2756+
}
2757+
//endregion
2758+

presentation/src/main/java/com/anytypeio/anytype/presentation/spaces/SpaceSettingsViewModel.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import com.anytypeio.anytype.domain.wallpaper.SetWallpaper
6565
import com.anytypeio.anytype.domain.workspace.SpaceManager
6666
import com.anytypeio.anytype.presentation.BuildConfig
6767
import com.anytypeio.anytype.presentation.common.BaseViewModel
68+
import com.anytypeio.anytype.presentation.extension.sendAnalyticsChangeMessageNotificationState
6869
import com.anytypeio.anytype.presentation.mapper.objectIcon
6970
import com.anytypeio.anytype.presentation.multiplayer.SpaceLimitsState
7071
import com.anytypeio.anytype.presentation.multiplayer.spaceLimitsState
@@ -1019,6 +1020,14 @@ class SpaceSettingsViewModel(
10191020
onSuccess = {
10201021
_notificationState.value = newState
10211022
Timber.d("Successfully set notification state to: $newState for space: $targetSpaceId")
1023+
// Fire analytics event for space-level notification change
1024+
val spaceView = spaceViewContainer.get(vmParams.space)
1025+
if (spaceView != null) {
1026+
analytics.sendAnalyticsChangeMessageNotificationState(
1027+
spaceUxType = spaceView.spaceUxType,
1028+
notificationState = newState
1029+
)
1030+
}
10221031
},
10231032
onFailure = { error ->
10241033
Timber.e("Failed to set notification state: $error")

presentation/src/main/java/com/anytypeio/anytype/presentation/widgets/CreateChatObjectViewModel.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ package com.anytypeio.anytype.presentation.widgets
33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.ViewModelProvider
55
import androidx.lifecycle.viewModelScope
6+
import com.anytypeio.anytype.analytics.base.Analytics
7+
import com.anytypeio.anytype.analytics.base.EventsDictionary
8+
import com.anytypeio.anytype.analytics.base.EventsPropertiesKey
9+
import com.anytypeio.anytype.analytics.base.sendEvent
10+
import com.anytypeio.anytype.analytics.props.Props
611
import com.anytypeio.anytype.core_models.Block
712
import com.anytypeio.anytype.core_models.Id
813
import com.anytypeio.anytype.core_models.Name
@@ -26,6 +31,7 @@ import timber.log.Timber
2631

2732
class CreateChatObjectViewModel(
2833
private val vmParams: VmParams,
34+
private val analytics: Analytics,
2935
private val createObject: CreateObject,
3036
private val uploadFile: UploadFile,
3137
private val setObjectDetails: SetObjectDetails
@@ -139,6 +145,13 @@ class CreateChatObjectViewModel(
139145
}
140146

141147
private suspend fun finishCreation(objectId: Id) {
148+
// Fire CreateObject analytics event
149+
analytics.sendEvent(
150+
eventName = EventsDictionary.objectCreate,
151+
props = Props(
152+
mapOf(EventsPropertiesKey.objectType to "_otchatDerived")
153+
)
154+
)
142155
isLoading.value = false
143156
commands.emit(Command.ChatObjectCreated(objectId = objectId))
144157
}
@@ -171,6 +184,7 @@ class CreateChatObjectViewModel(
171184

172185
class Factory @Inject constructor(
173186
private val vmParams: VmParams,
187+
private val analytics: Analytics,
174188
private val createObject: CreateObject,
175189
private val uploadFile: UploadFile,
176190
private val setObjectDetails: SetObjectDetails
@@ -180,6 +194,7 @@ class CreateChatObjectViewModel(
180194
modelClass: Class<T>
181195
) = CreateChatObjectViewModel(
182196
vmParams = vmParams,
197+
analytics = analytics,
183198
createObject = createObject,
184199
uploadFile = uploadFile,
185200
setObjectDetails = setObjectDetails

0 commit comments

Comments
 (0)