Skip to content

Commit

Permalink
Analytics: Send JoinedRoom event - room preview (#4716)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Jan 19, 2022
1 parent 55a6257 commit a8c29f5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ data class RoomPreviewData(
val roomAlias: String? = null,
val roomType: String? = null,
val topic: String? = null,
val numJoinedMembers: Int? = null,
val worldReadable: Boolean = false,
val avatarUrl: String? = null,
val homeServers: List<String> = emptyList(),
Expand Down Expand Up @@ -69,6 +70,7 @@ class RoomPreviewActivity : VectorBaseActivity<ActivitySimpleBinding>(), Toolbar
roomName = publicRoom.name,
roomAlias = publicRoom.getPrimaryAlias(),
topic = publicRoom.topic,
numJoinedMembers = publicRoom.numJoinedMembers,
worldReadable = publicRoom.worldReadable,
avatarUrl = publicRoom.avatarUrl,
homeServers = listOfNotNull(roomDirectoryData.homeServer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.EmptyViewEvents
import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.analytics.extensions.toAnalyticsRoomSize
import im.vector.app.features.analytics.plan.JoinedRoom
import im.vector.app.features.roomdirectory.JoinState
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.launchIn
Expand All @@ -44,9 +47,11 @@ import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
import org.matrix.android.sdk.flow.flow
import timber.log.Timber

class RoomPreviewViewModel @AssistedInject constructor(@Assisted private val initialState: RoomPreviewViewState,
private val session: Session) :
VectorViewModel<RoomPreviewViewState, RoomPreviewAction, EmptyViewEvents>(initialState) {
class RoomPreviewViewModel @AssistedInject constructor(
@Assisted private val initialState: RoomPreviewViewState,
private val analyticsTracker: AnalyticsTracker,
private val session: Session
) : VectorViewModel<RoomPreviewViewState, RoomPreviewAction, EmptyViewEvents>(initialState) {

@AssistedFactory
interface Factory : MavericksAssistedViewModelFactory<RoomPreviewViewModel, RoomPreviewViewState> {
Expand Down Expand Up @@ -243,6 +248,11 @@ class RoomPreviewViewModel @AssistedInject constructor(@Assisted private val ini
viewModelScope.launch {
try {
session.joinRoom(state.roomId, viaServers = state.homeServers)
analyticsTracker.capture(JoinedRoom(
// Always false in this case (?)
isDM = false,
roomSize = state.numJoinMembers.toAnalyticsRoomSize()
))
// 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
} catch (failure: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ data class RoomPreviewViewState(

val roomName: String? = null,
val roomTopic: String? = null,
val numJoinMembers: Int? = null,
val avatarUrl: String? = null,

val shouldPeekFromServer: Boolean = false,
Expand All @@ -56,6 +57,7 @@ data class RoomPreviewViewState(
homeServers = args.homeServers,
roomName = args.roomName,
roomTopic = args.topic,
numJoinMembers = args.numJoinedMembers,
avatarUrl = args.avatarUrl,
shouldPeekFromServer = args.peekFromServer,
fromEmailInvite = args.fromEmailInvite,
Expand All @@ -64,6 +66,6 @@ data class RoomPreviewViewState(

fun matrixItem(): MatrixItem {
return if (roomType == RoomType.SPACE) MatrixItem.SpaceItem(roomId, roomName ?: roomAlias, avatarUrl)
else MatrixItem.RoomItem(roomId, roomName ?: roomAlias, avatarUrl)
else MatrixItem.RoomItem(roomId, roomName ?: roomAlias, avatarUrl)
}
}

0 comments on commit a8c29f5

Please sign in to comment.