Analytics: Send JoinedRoom event (#4716)

This commit is contained in:
Benoit Marty 2021-12-15 15:15:38 +01:00 committed by Benoit Marty
parent 11f176e079
commit 55a6257cee
8 changed files with 51 additions and 8 deletions

View file

@ -17,9 +17,13 @@
package im.vector.app.features.analytics.extensions package im.vector.app.features.analytics.extensions
import im.vector.app.features.analytics.plan.JoinedRoom import im.vector.app.features.analytics.plan.JoinedRoom
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoom
fun Int.toAnalyticsRoomSize(): JoinedRoom.RoomSize { fun Int?.toAnalyticsRoomSize(): JoinedRoom.RoomSize {
return when (this) { return when (this) {
null,
2 -> JoinedRoom.RoomSize.Two 2 -> JoinedRoom.RoomSize.Two
in 3..10 -> JoinedRoom.RoomSize.ThreeToTen in 3..10 -> JoinedRoom.RoomSize.ThreeToTen
in 11..100 -> JoinedRoom.RoomSize.ElevenToOneHundred in 11..100 -> JoinedRoom.RoomSize.ElevenToOneHundred
@ -27,3 +31,17 @@ fun Int.toAnalyticsRoomSize(): JoinedRoom.RoomSize {
else -> JoinedRoom.RoomSize.MoreThanAThousand else -> JoinedRoom.RoomSize.MoreThanAThousand
} }
} }
fun RoomSummary?.toAnalyticsJoinedRoom(): JoinedRoom {
return JoinedRoom(
isDM = this?.isDirect.orFalse(),
roomSize = this?.joinedMembersCount?.toAnalyticsRoomSize() ?: JoinedRoom.RoomSize.Two
)
}
fun PublicRoom.toAnalyticsJoinedRoom(): JoinedRoom {
return JoinedRoom(
isDM = false,
roomSize = numJoinedMembers.toAnalyticsRoomSize()
)
}

View file

@ -37,7 +37,9 @@ import im.vector.app.core.mvrx.runCatchingToAsync
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.app.core.utils.BehaviorDataSource import im.vector.app.core.utils.BehaviorDataSource
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.DecryptionFailureTracker import im.vector.app.features.analytics.DecryptionFailureTracker
import im.vector.app.features.analytics.extensions.toAnalyticsJoinedRoom
import im.vector.app.features.call.conference.ConferenceEvent import im.vector.app.features.call.conference.ConferenceEvent
import im.vector.app.features.call.conference.JitsiActiveConferenceHolder import im.vector.app.features.call.conference.JitsiActiveConferenceHolder
import im.vector.app.features.call.conference.JitsiService import im.vector.app.features.call.conference.JitsiService
@ -112,6 +114,7 @@ class RoomDetailViewModel @AssistedInject constructor(
private val chatEffectManager: ChatEffectManager, private val chatEffectManager: ChatEffectManager,
private val directRoomHelper: DirectRoomHelper, private val directRoomHelper: DirectRoomHelper,
private val jitsiService: JitsiService, private val jitsiService: JitsiService,
private val analyticsTracker: AnalyticsTracker,
private val activeConferenceHolder: JitsiActiveConferenceHolder, private val activeConferenceHolder: JitsiActiveConferenceHolder,
private val decryptionFailureTracker: DecryptionFailureTracker, private val decryptionFailureTracker: DecryptionFailureTracker,
timelineFactory: TimelineFactory timelineFactory: TimelineFactory
@ -709,7 +712,10 @@ class RoomDetailViewModel @AssistedInject constructor(
private fun handleAcceptInvite() { private fun handleAcceptInvite() {
viewModelScope.launch { viewModelScope.launch {
tryOrNull { room.join() } tryOrNull {
room.join()
analyticsTracker.capture(room.roomSummary().toAnalyticsJoinedRoom())
}
} }
} }

View file

@ -26,6 +26,8 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.extensions.toAnalyticsJoinedRoom
import im.vector.app.features.attachments.toContentAttachmentData import im.vector.app.features.attachments.toContentAttachmentData
import im.vector.app.features.command.CommandParser import im.vector.app.features.command.CommandParser
import im.vector.app.features.command.ParsedCommand import im.vector.app.features.command.ParsedCommand
@ -68,6 +70,7 @@ class MessageComposerViewModel @AssistedInject constructor(
private val vectorPreferences: VectorPreferences, private val vectorPreferences: VectorPreferences,
private val rainbowGenerator: RainbowGenerator, private val rainbowGenerator: RainbowGenerator,
private val voiceMessageHelper: VoiceMessageHelper, private val voiceMessageHelper: VoiceMessageHelper,
private val analyticsTracker: AnalyticsTracker,
private val voicePlayerHelper: VoicePlayerHelper private val voicePlayerHelper: VoicePlayerHelper
) : VectorViewModel<MessageComposerViewState, MessageComposerAction, MessageComposerViewEvents>(initialState) { ) : VectorViewModel<MessageComposerViewState, MessageComposerAction, MessageComposerViewEvents>(initialState) {
@ -520,6 +523,7 @@ class MessageComposerViewModel @AssistedInject constructor(
return@launch return@launch
} }
session.getRoomSummary(command.roomAlias) session.getRoomSummary(command.roomAlias)
?.also { analyticsTracker.capture(it.toAnalyticsJoinedRoom()) }
?.roomId ?.roomId
?.let { ?.let {
_viewEvents.post(MessageComposerViewEvents.JoinRoomCommandSuccess(it)) _viewEvents.post(MessageComposerViewEvents.JoinRoomCommandSuccess(it))

View file

@ -32,6 +32,8 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.extensions.toAnalyticsJoinedRoom
import im.vector.app.features.displayname.getBestName import im.vector.app.features.displayname.getBestName
import im.vector.app.features.invite.AutoAcceptInvites import im.vector.app.features.invite.AutoAcceptInvites
import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.VectorPreferences
@ -56,7 +58,8 @@ class RoomListViewModel @AssistedInject constructor(
stringProvider: StringProvider, stringProvider: StringProvider,
appStateHandler: AppStateHandler, appStateHandler: AppStateHandler,
vectorPreferences: VectorPreferences, vectorPreferences: VectorPreferences,
autoAcceptInvites: AutoAcceptInvites autoAcceptInvites: AutoAcceptInvites,
private val analyticsTracker: AnalyticsTracker
) : VectorViewModel<RoomListViewState, RoomListAction, RoomListViewEvents>(initialState) { ) : VectorViewModel<RoomListViewState, RoomListAction, RoomListViewEvents>(initialState) {
@AssistedFactory @AssistedFactory
@ -223,6 +226,7 @@ class RoomListViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
room.join() room.join()
analyticsTracker.capture(action.roomSummary.toAnalyticsJoinedRoom())
// We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data. // We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data.
// Instead, we wait for the room to be joined // Instead, we wait for the room to be joined
} catch (failure: Throwable) { } catch (failure: Throwable) {

View file

@ -23,6 +23,8 @@ import androidx.core.app.RemoteInput
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.extensions.toAnalyticsJoinedRoom
import im.vector.app.features.session.coroutineScope import im.vector.app.features.session.coroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.extensions.tryOrNull
@ -41,6 +43,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
@Inject lateinit var notificationDrawerManager: NotificationDrawerManager @Inject lateinit var notificationDrawerManager: NotificationDrawerManager
@Inject lateinit var activeSessionHolder: ActiveSessionHolder @Inject lateinit var activeSessionHolder: ActiveSessionHolder
@Inject lateinit var analyticsTracker: AnalyticsTracker
override fun onReceive(context: Context?, intent: Intent?) { override fun onReceive(context: Context?, intent: Intent?) {
if (intent == null || context == null) return if (intent == null || context == null) return
@ -79,7 +82,10 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
val room = session.getRoom(roomId) val room = session.getRoom(roomId)
if (room != null) { if (room != null) {
session.coroutineScope.launch { session.coroutineScope.launch {
tryOrNull { room.join() } tryOrNull {
room.join()
analyticsTracker.capture(room.roomSummary().toAnalyticsJoinedRoom())
}
} }
} }
} }

View file

@ -160,7 +160,7 @@ class PublicRoomsFragment @Inject constructor(
override fun onPublicRoomJoin(publicRoom: PublicRoom) { override fun onPublicRoomJoin(publicRoom: PublicRoom) {
Timber.v("PublicRoomJoinClicked: $publicRoom") Timber.v("PublicRoomJoinClicked: $publicRoom")
viewModel.handle(RoomDirectoryAction.JoinRoom(publicRoom.roomId)) viewModel.handle(RoomDirectoryAction.JoinRoom(publicRoom))
} }
override fun loadMore() { override fun loadMore() {

View file

@ -17,10 +17,11 @@
package im.vector.app.features.roomdirectory package im.vector.app.features.roomdirectory
import im.vector.app.core.platform.VectorViewModelAction import im.vector.app.core.platform.VectorViewModelAction
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoom
sealed class RoomDirectoryAction : VectorViewModelAction { sealed class RoomDirectoryAction : VectorViewModelAction {
data class SetRoomDirectoryData(val roomDirectoryData: RoomDirectoryData) : RoomDirectoryAction() data class SetRoomDirectoryData(val roomDirectoryData: RoomDirectoryData) : RoomDirectoryAction()
data class FilterWith(val filter: String) : RoomDirectoryAction() data class FilterWith(val filter: String) : RoomDirectoryAction()
object LoadMore : RoomDirectoryAction() object LoadMore : RoomDirectoryAction()
data class JoinRoom(val roomId: String) : RoomDirectoryAction() data class JoinRoom(val publicRoom: PublicRoom) : RoomDirectoryAction()
} }

View file

@ -27,6 +27,8 @@ import dagger.assisted.AssistedInject
import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.extensions.toAnalyticsJoinedRoom
import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.VectorPreferences
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@ -45,6 +47,7 @@ class RoomDirectoryViewModel @AssistedInject constructor(
@Assisted initialState: PublicRoomsViewState, @Assisted initialState: PublicRoomsViewState,
vectorPreferences: VectorPreferences, vectorPreferences: VectorPreferences,
private val session: Session, private val session: Session,
private val analyticsTracker: AnalyticsTracker,
private val explicitTermFilter: ExplicitTermFilter private val explicitTermFilter: ExplicitTermFilter
) : VectorViewModel<PublicRoomsViewState, RoomDirectoryAction, RoomDirectoryViewEvents>(initialState) { ) : VectorViewModel<PublicRoomsViewState, RoomDirectoryAction, RoomDirectoryViewEvents>(initialState) {
@ -213,7 +216,7 @@ class RoomDirectoryViewModel @AssistedInject constructor(
} }
private fun joinRoom(action: RoomDirectoryAction.JoinRoom) = withState { state -> private fun joinRoom(action: RoomDirectoryAction.JoinRoom) = withState { state ->
val roomMembershipChange = state.changeMembershipStates[action.roomId] val roomMembershipChange = state.changeMembershipStates[action.publicRoom.roomId]
if (roomMembershipChange?.isInProgress().orFalse()) { if (roomMembershipChange?.isInProgress().orFalse()) {
// Request already sent, should not happen // Request already sent, should not happen
Timber.w("Try to join an already joining room. Should not happen") Timber.w("Try to join an already joining room. Should not happen")
@ -222,7 +225,8 @@ class RoomDirectoryViewModel @AssistedInject constructor(
val viaServers = listOfNotNull(state.roomDirectoryData.homeServer) val viaServers = listOfNotNull(state.roomDirectoryData.homeServer)
viewModelScope.launch { viewModelScope.launch {
try { try {
session.joinRoom(action.roomId, viaServers = viaServers) session.joinRoom(action.publicRoom.roomId, viaServers = viaServers)
analyticsTracker.capture(action.publicRoom.toAnalyticsJoinedRoom())
// We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data. // We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data.
// Instead, we wait for the room to be joined // Instead, we wait for the room to be joined
} catch (failure: Throwable) { } catch (failure: Throwable) {