diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/details/RoomMemberDetailsPresenter.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/details/RoomMemberDetailsPresenter.kt index 9b18c88c93..85eca4fbae 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/details/RoomMemberDetailsPresenter.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/details/RoomMemberDetailsPresenter.kt @@ -17,7 +17,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import dev.zacsweers.metro.Assisted import dev.zacsweers.metro.AssistedInject -import io.element.android.features.userprofile.api.UserProfileEvents +import io.element.android.features.userprofile.api.UserProfileEvent import io.element.android.features.userprofile.api.UserProfilePresenterFactory import io.element.android.features.userprofile.api.UserProfileState import io.element.android.features.userprofile.api.UserProfileVerificationState @@ -112,12 +112,12 @@ class RoomMemberDetailsPresenter( } } - fun handleEvent(event: UserProfileEvents) { + fun handleEvent(event: UserProfileEvent) { when (event) { - UserProfileEvents.WithdrawVerification -> coroutineScope.launch { + UserProfileEvent.WithdrawVerification -> coroutineScope.launch { encryptionService.withdrawVerification(roomMemberId) } - is UserProfileEvents.CopyToClipboard -> { + is UserProfileEvent.CopyToClipboard -> { clipboardHelper.copyPlainText(event.text) snackbarDispatcher.post(SnackbarMessage(CommonStrings.common_copied_to_clipboard)) } diff --git a/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/impl/members/details/RoomMemberDetailsPresenterTest.kt b/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/impl/members/details/RoomMemberDetailsPresenterTest.kt index 34ac8d623f..53ec3b1491 100644 --- a/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/impl/members/details/RoomMemberDetailsPresenterTest.kt +++ b/features/roomdetails/impl/src/test/kotlin/io/element/android/features/roomdetails/impl/members/details/RoomMemberDetailsPresenterTest.kt @@ -11,7 +11,7 @@ package io.element.android.features.roomdetails.impl.members.details import com.google.common.truth.Truth.assertThat import io.element.android.features.roomdetails.impl.aJoinedRoom import io.element.android.features.roomdetails.impl.members.aRoomMember -import io.element.android.features.userprofile.api.UserProfileEvents +import io.element.android.features.userprofile.api.UserProfileEvent import io.element.android.features.userprofile.api.UserProfilePresenterFactory import io.element.android.features.userprofile.api.UserProfileVerificationState import io.element.android.features.userprofile.shared.aUserProfileState @@ -348,7 +348,7 @@ class RoomMemberDetailsPresenterTest { consumeItemsUntilPredicate { it.verificationState == UserProfileVerificationState.VERIFICATION_VIOLATION } - initialState.eventSink(UserProfileEvents.WithdrawVerification) + initialState.eventSink(UserProfileEvent.WithdrawVerification) withdrawVerificationResult.assertions().isCalledOnce() } } diff --git a/features/userprofile/api/src/main/kotlin/io/element/android/features/userprofile/api/UserProfileEvents.kt b/features/userprofile/api/src/main/kotlin/io/element/android/features/userprofile/api/UserProfileEvent.kt similarity index 57% rename from features/userprofile/api/src/main/kotlin/io/element/android/features/userprofile/api/UserProfileEvents.kt rename to features/userprofile/api/src/main/kotlin/io/element/android/features/userprofile/api/UserProfileEvent.kt index 55c9c40f74..24265f0d9b 100644 --- a/features/userprofile/api/src/main/kotlin/io/element/android/features/userprofile/api/UserProfileEvents.kt +++ b/features/userprofile/api/src/main/kotlin/io/element/android/features/userprofile/api/UserProfileEvent.kt @@ -8,13 +8,13 @@ package io.element.android.features.userprofile.api -sealed interface UserProfileEvents { - data object StartDM : UserProfileEvents - data object ClearStartDMState : UserProfileEvents - data class BlockUser(val needsConfirmation: Boolean = false) : UserProfileEvents - data class UnblockUser(val needsConfirmation: Boolean = false) : UserProfileEvents - data object ClearBlockUserError : UserProfileEvents - data object ClearConfirmationDialog : UserProfileEvents - data object WithdrawVerification : UserProfileEvents - data class CopyToClipboard(val text: String) : UserProfileEvents +sealed interface UserProfileEvent { + data object StartDM : UserProfileEvent + data object ClearStartDMState : UserProfileEvent + data class BlockUser(val needsConfirmation: Boolean = false) : UserProfileEvent + data class UnblockUser(val needsConfirmation: Boolean = false) : UserProfileEvent + data object ClearBlockUserError : UserProfileEvent + data object ClearConfirmationDialog : UserProfileEvent + data object WithdrawVerification : UserProfileEvent + data class CopyToClipboard(val text: String) : UserProfileEvent } diff --git a/features/userprofile/api/src/main/kotlin/io/element/android/features/userprofile/api/UserProfileState.kt b/features/userprofile/api/src/main/kotlin/io/element/android/features/userprofile/api/UserProfileState.kt index 4de0d50ca4..bdc1c5a5c7 100644 --- a/features/userprofile/api/src/main/kotlin/io/element/android/features/userprofile/api/UserProfileState.kt +++ b/features/userprofile/api/src/main/kotlin/io/element/android/features/userprofile/api/UserProfileState.kt @@ -28,7 +28,7 @@ data class UserProfileState( val canCall: Boolean, val snackbarMessage: SnackbarMessage?, val displayedStatus: DisplayedStatus?, - val eventSink: (UserProfileEvents) -> Unit + val eventSink: (UserProfileEvent) -> Unit ) { enum class ConfirmationDialog { Block, diff --git a/features/userprofile/impl/src/main/kotlin/io/element/android/features/userprofile/impl/root/UserProfilePresenter.kt b/features/userprofile/impl/src/main/kotlin/io/element/android/features/userprofile/impl/root/UserProfilePresenter.kt index 24977713c0..08251981c9 100644 --- a/features/userprofile/impl/src/main/kotlin/io/element/android/features/userprofile/impl/root/UserProfilePresenter.kt +++ b/features/userprofile/impl/src/main/kotlin/io/element/android/features/userprofile/impl/root/UserProfilePresenter.kt @@ -23,7 +23,7 @@ import dev.zacsweers.metro.AssistedFactory import dev.zacsweers.metro.AssistedInject import io.element.android.features.enterprise.api.SessionEnterpriseService import io.element.android.features.startchat.api.StartDMAction -import io.element.android.features.userprofile.api.UserProfileEvents +import io.element.android.features.userprofile.api.UserProfileEvent import io.element.android.features.userprofile.api.UserProfileState import io.element.android.features.userprofile.api.UserProfileState.ConfirmationDialog import io.element.android.features.userprofile.api.UserProfileVerificationState @@ -101,9 +101,9 @@ class UserProfilePresenter( } val userProfile by produceState(null) { value = client.getProfile(userId).getOrNull() } - fun handleEvent(event: UserProfileEvents) { + fun handleEvent(event: UserProfileEvent) { when (event) { - is UserProfileEvents.BlockUser -> { + is UserProfileEvent.BlockUser -> { if (event.needsConfirmation) { confirmationDialog = ConfirmationDialog.Block } else { @@ -111,7 +111,7 @@ class UserProfilePresenter( coroutineScope.blockUser(isBlocked) } } - is UserProfileEvents.UnblockUser -> { + is UserProfileEvent.UnblockUser -> { if (event.needsConfirmation) { confirmationDialog = ConfirmationDialog.Unblock } else { @@ -119,11 +119,11 @@ class UserProfilePresenter( coroutineScope.unblockUser(isBlocked) } } - UserProfileEvents.ClearConfirmationDialog -> confirmationDialog = null - UserProfileEvents.ClearBlockUserError -> { + UserProfileEvent.ClearConfirmationDialog -> confirmationDialog = null + UserProfileEvent.ClearBlockUserError -> { isBlocked.value = AsyncData.Success(isBlocked.value.dataOrNull().orFalse()) } - UserProfileEvents.StartDM -> { + UserProfileEvent.StartDM -> { coroutineScope.launch { startDMAction.execute( matrixUser = userProfile ?: MatrixUser(userId), @@ -132,12 +132,12 @@ class UserProfilePresenter( ) } } - UserProfileEvents.ClearStartDMState -> { + UserProfileEvent.ClearStartDMState -> { startDmActionState.value = AsyncAction.Uninitialized } // Do nothing for other event as they are handled by the RoomMemberDetailsPresenter if needed - UserProfileEvents.WithdrawVerification, - is UserProfileEvents.CopyToClipboard -> Unit + UserProfileEvent.WithdrawVerification, + is UserProfileEvent.CopyToClipboard -> Unit } } diff --git a/features/userprofile/impl/src/test/kotlin/io/element/android/features/userprofile/impl/UserProfilePresenterTest.kt b/features/userprofile/impl/src/test/kotlin/io/element/android/features/userprofile/impl/UserProfilePresenterTest.kt index bbdc698f17..57a7ae273f 100644 --- a/features/userprofile/impl/src/test/kotlin/io/element/android/features/userprofile/impl/UserProfilePresenterTest.kt +++ b/features/userprofile/impl/src/test/kotlin/io/element/android/features/userprofile/impl/UserProfilePresenterTest.kt @@ -18,7 +18,7 @@ import io.element.android.features.enterprise.test.FakeSessionEnterpriseService import io.element.android.features.invitepeople.test.FakeStartDMAction import io.element.android.features.startchat.api.ConfirmingStartDmWithMatrixUser import io.element.android.features.startchat.api.StartDMAction -import io.element.android.features.userprofile.api.UserProfileEvents +import io.element.android.features.userprofile.api.UserProfileEvent import io.element.android.features.userprofile.api.UserProfileState import io.element.android.features.userprofile.api.UserProfileVerificationState import io.element.android.features.userprofile.impl.root.UserProfilePresenter @@ -182,12 +182,12 @@ class UserProfilePresenterTest { val presenter = createUserProfilePresenter() presenter.test { val initialState = awaitFirstItem() - initialState.eventSink(UserProfileEvents.BlockUser(needsConfirmation = true)) + initialState.eventSink(UserProfileEvent.BlockUser(needsConfirmation = true)) val dialogState = awaitItem() assertThat(dialogState.displayConfirmationDialog).isEqualTo(UserProfileState.ConfirmationDialog.Block) - dialogState.eventSink(UserProfileEvents.ClearConfirmationDialog) + dialogState.eventSink(UserProfileEvent.ClearConfirmationDialog) assertThat(awaitItem().displayConfirmationDialog).isNull() } } @@ -202,12 +202,12 @@ class UserProfilePresenterTest { ) presenter.test { val initialState = awaitFirstItem() - initialState.eventSink(UserProfileEvents.BlockUser(needsConfirmation = false)) + initialState.eventSink(UserProfileEvent.BlockUser(needsConfirmation = false)) assertThat(awaitItem().isBlocked.isLoading()).isTrue() ignoredUsersFlow.emit(persistentListOf(A_USER_ID)) assertThat(awaitItem().isBlocked.dataOrNull()).isTrue() - initialState.eventSink(UserProfileEvents.UnblockUser(needsConfirmation = false)) + initialState.eventSink(UserProfileEvent.UnblockUser(needsConfirmation = false)) assertThat(awaitItem().isBlocked.isLoading()).isTrue() ignoredUsersFlow.emit(persistentListOf()) assertThat(awaitItem().isBlocked.dataOrNull()).isFalse() @@ -222,12 +222,12 @@ class UserProfilePresenterTest { val presenter = createUserProfilePresenter(client = matrixClient) presenter.test { val initialState = awaitFirstItem(count = 2) - initialState.eventSink(UserProfileEvents.BlockUser(needsConfirmation = false)) + initialState.eventSink(UserProfileEvent.BlockUser(needsConfirmation = false)) assertThat(awaitItem().isBlocked.isLoading()).isTrue() val errorState = awaitItem() assertThat(errorState.isBlocked.errorOrNull()).isEqualTo(AN_EXCEPTION) // Clear error - initialState.eventSink(UserProfileEvents.ClearBlockUserError) + initialState.eventSink(UserProfileEvent.ClearBlockUserError) assertThat(awaitItem().isBlocked).isEqualTo(AsyncData.Success(false)) } } @@ -240,12 +240,12 @@ class UserProfilePresenterTest { val presenter = createUserProfilePresenter(client = matrixClient) presenter.test { val initialState = awaitFirstItem(count = 2) - initialState.eventSink(UserProfileEvents.UnblockUser(needsConfirmation = false)) + initialState.eventSink(UserProfileEvent.UnblockUser(needsConfirmation = false)) assertThat(awaitItem().isBlocked.isLoading()).isTrue() val errorState = awaitItem() assertThat(errorState.isBlocked.errorOrNull()).isEqualTo(AN_EXCEPTION) // Clear error - initialState.eventSink(UserProfileEvents.ClearBlockUserError) + initialState.eventSink(UserProfileEvent.ClearBlockUserError) assertThat(awaitItem().isBlocked).isEqualTo(AsyncData.Success(true)) } } @@ -255,12 +255,12 @@ class UserProfilePresenterTest { val presenter = createUserProfilePresenter() presenter.test { val initialState = awaitFirstItem() - initialState.eventSink(UserProfileEvents.UnblockUser(needsConfirmation = true)) + initialState.eventSink(UserProfileEvent.UnblockUser(needsConfirmation = true)) val dialogState = awaitItem() assertThat(dialogState.displayConfirmationDialog).isEqualTo(UserProfileState.ConfirmationDialog.Unblock) - dialogState.eventSink(UserProfileEvents.ClearConfirmationDialog) + dialogState.eventSink(UserProfileEvent.ClearConfirmationDialog) assertThat(awaitItem().displayConfirmationDialog).isNull() } } @@ -279,7 +279,7 @@ class UserProfilePresenterTest { val initialState = awaitFirstItem() assertThat(initialState.startDmActionState).isInstanceOf(AsyncAction.Uninitialized::class.java) val matrixUser = MatrixUser(UserId("@alice:server.org")) - initialState.eventSink(UserProfileEvents.StartDM) + initialState.eventSink(UserProfileEvent.StartDM) awaitItem().also { state -> assertThat(state.startDmActionState).isEqualTo(startDMFailureResult) executeResult.assertions().isCalledOnce().with( @@ -287,7 +287,7 @@ class UserProfilePresenterTest { value(false), any(), ) - state.eventSink(UserProfileEvents.ClearStartDMState) + state.eventSink(UserProfileEvent.ClearStartDMState) } awaitItem().also { state -> assertThat(state.startDmActionState.isUninitialized()).isTrue() @@ -309,7 +309,7 @@ class UserProfilePresenterTest { val initialState = awaitFirstItem() assertThat(initialState.startDmActionState).isInstanceOf(AsyncAction.Uninitialized::class.java) val matrixUser = MatrixUser(UserId("@alice:server.org")) - initialState.eventSink(UserProfileEvents.StartDM) + initialState.eventSink(UserProfileEvent.StartDM) awaitItem().also { state -> assertThat(state.startDmActionState).isEqualTo(startDMSuccessResult) executeResult.assertions().isCalledOnce().with( @@ -335,7 +335,7 @@ class UserProfilePresenterTest { }.test { val initialState = awaitFirstItem() assertThat(initialState.startDmActionState).isInstanceOf(AsyncAction.Uninitialized::class.java) - initialState.eventSink(UserProfileEvents.StartDM) + initialState.eventSink(UserProfileEvent.StartDM) val confirmingState = awaitItem() assertThat(confirmingState.startDmActionState).isEqualTo(startDMConfirmationResult) executeResult.assertions().isCalledOnce().with( @@ -344,7 +344,7 @@ class UserProfilePresenterTest { any(), ) // Cancelling should not create the DM - confirmingState.eventSink(UserProfileEvents.ClearStartDMState) + confirmingState.eventSink(UserProfileEvent.ClearStartDMState) val finalState = awaitItem() assertThat(finalState.startDmActionState.isUninitialized()).isTrue() executeResult.assertions().isCalledExactly(1) @@ -365,7 +365,7 @@ class UserProfilePresenterTest { }.test { val initialState = awaitFirstItem() assertThat(initialState.startDmActionState).isInstanceOf(AsyncAction.Uninitialized::class.java) - initialState.eventSink(UserProfileEvents.StartDM) + initialState.eventSink(UserProfileEvent.StartDM) val confirmingState = awaitItem() assertThat(confirmingState.startDmActionState).isEqualTo(startDMConfirmationResult) executeResult.assertions().isCalledOnce().with( @@ -374,7 +374,7 @@ class UserProfilePresenterTest { any(), ) // Start DM again should invoke the action with createIfDmDoesNotExist = true - confirmingState.eventSink(UserProfileEvents.StartDM) + confirmingState.eventSink(UserProfileEvent.StartDM) executeResult.assertions().isCalledExactly(2).withSequence( listOf(value(matrixUser), value(false), any()), listOf(value(matrixUser), value(true), any()), diff --git a/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/UserProfileStatePreviewParam.kt b/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/UserProfileStatePreviewParam.kt index 84a95e0b14..bfb3df4ac6 100644 --- a/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/UserProfileStatePreviewParam.kt +++ b/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/UserProfileStatePreviewParam.kt @@ -10,7 +10,7 @@ package io.element.android.features.userprofile.shared import androidx.compose.ui.tooling.preview.PreviewParameterProvider import io.element.android.features.startchat.api.ConfirmingStartDmWithMatrixUser -import io.element.android.features.userprofile.api.UserProfileEvents +import io.element.android.features.userprofile.api.UserProfileEvent import io.element.android.features.userprofile.api.UserProfileState import io.element.android.features.userprofile.api.UserProfileVerificationState import io.element.android.libraries.architecture.AsyncAction @@ -50,7 +50,7 @@ fun aUserProfileState( canCall: Boolean = false, snackbarMessage: SnackbarMessage? = null, displayedStatus: DisplayedStatus? = null, - eventSink: (UserProfileEvents) -> Unit = {}, + eventSink: (UserProfileEvent) -> Unit = {}, ) = UserProfileState( userId = userId, userName = userName, diff --git a/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/UserProfileView.kt b/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/UserProfileView.kt index b9f43db36d..643db456b1 100644 --- a/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/UserProfileView.kt +++ b/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/UserProfileView.kt @@ -23,7 +23,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import io.element.android.compound.tokens.generated.CompoundIcons import io.element.android.features.startchat.api.ConfirmingStartDmWithMatrixUser -import io.element.android.features.userprofile.api.UserProfileEvents +import io.element.android.features.userprofile.api.UserProfileEvent import io.element.android.features.userprofile.api.UserProfileState import io.element.android.features.userprofile.api.UserProfileVerificationState import io.element.android.features.userprofile.shared.blockuser.BlockUserDialogs @@ -83,15 +83,15 @@ fun UserProfileView( openAvatarPreview(state.userName ?: state.userId.value, avatarUrl) }, onUserIdClick = { - state.eventSink(UserProfileEvents.CopyToClipboard(state.userId.value)) + state.eventSink(UserProfileEvent.CopyToClipboard(state.userId.value)) }, - withdrawVerificationClick = { state.eventSink(UserProfileEvents.WithdrawVerification) }, + withdrawVerificationClick = { state.eventSink(UserProfileEvent.WithdrawVerification) }, ) UserProfileMainActionsSection( isCurrentUser = state.isCurrentUser, canCall = state.canCall, onShareUser = onShareUser, - onStartDM = { state.eventSink(UserProfileEvents.StartDM) }, + onStartDM = { state.eventSink(UserProfileEvent.StartDM) }, onCall = { intent -> state.dmRoomId?.let { onStartCall(it, intent) } } ) Spacer(modifier = Modifier.height(26.dp)) @@ -109,18 +109,18 @@ fun UserProfileView( }, onSuccess = onOpenDm, errorMessage = { stringResource(R.string.screen_start_chat_error_starting_chat) }, - onRetry = { state.eventSink(UserProfileEvents.StartDM) }, - onErrorDismiss = { state.eventSink(UserProfileEvents.ClearStartDMState) }, + onRetry = { state.eventSink(UserProfileEvent.StartDM) }, + onErrorDismiss = { state.eventSink(UserProfileEvent.ClearStartDMState) }, confirmationDialog = { data -> if (data is ConfirmingStartDmWithMatrixUser) { CreateDmConfirmationBottomSheet( matrixUser = data.matrixUser, isUserIdentityUnknown = data.isUserIdentityUnknown, onSendInvite = { - state.eventSink(UserProfileEvents.StartDM) + state.eventSink(UserProfileEvent.StartDM) }, onDismiss = { - state.eventSink(UserProfileEvents.ClearStartDMState) + state.eventSink(UserProfileEvent.ClearStartDMState) }, ) } diff --git a/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/blockuser/BlockUserDialogs.kt b/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/blockuser/BlockUserDialogs.kt index 2ba17b947b..220118c5a7 100644 --- a/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/blockuser/BlockUserDialogs.kt +++ b/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/blockuser/BlockUserDialogs.kt @@ -10,7 +10,7 @@ package io.element.android.features.userprofile.shared.blockuser import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource -import io.element.android.features.userprofile.api.UserProfileEvents +import io.element.android.features.userprofile.api.UserProfileEvent import io.element.android.features.userprofile.api.UserProfileState import io.element.android.features.userprofile.shared.R import io.element.android.libraries.designsystem.components.dialogs.ConfirmationDialog @@ -23,24 +23,24 @@ fun BlockUserDialogs(state: UserProfileState) { BlockConfirmationDialog( onBlockAction = { state.eventSink( - UserProfileEvents.BlockUser( + UserProfileEvent.BlockUser( needsConfirmation = false ) ) }, - onDismiss = { state.eventSink(UserProfileEvents.ClearConfirmationDialog) } + onDismiss = { state.eventSink(UserProfileEvent.ClearConfirmationDialog) } ) } UserProfileState.ConfirmationDialog.Unblock -> { UnblockConfirmationDialog( onUnblockAction = { state.eventSink( - UserProfileEvents.UnblockUser( + UserProfileEvent.UnblockUser( needsConfirmation = false ) ) }, - onDismiss = { state.eventSink(UserProfileEvents.ClearConfirmationDialog) } + onDismiss = { state.eventSink(UserProfileEvent.ClearConfirmationDialog) } ) } } diff --git a/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/blockuser/BlockUserSection.kt b/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/blockuser/BlockUserSection.kt index 30f8c28607..e8210997b0 100644 --- a/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/blockuser/BlockUserSection.kt +++ b/features/userprofile/shared/src/main/kotlin/io/element/android/features/userprofile/shared/blockuser/BlockUserSection.kt @@ -15,7 +15,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import io.element.android.compound.tokens.generated.CompoundIcons -import io.element.android.features.userprofile.api.UserProfileEvents +import io.element.android.features.userprofile.api.UserProfileEvent import io.element.android.features.userprofile.api.UserProfileState import io.element.android.features.userprofile.shared.R import io.element.android.libraries.architecture.AsyncData @@ -50,13 +50,13 @@ fun BlockUserSection( if (isBlocked is AsyncData.Failure) { RetryDialog( content = stringResource(CommonStrings.error_unknown), - onDismiss = { state.eventSink(UserProfileEvents.ClearBlockUserError) }, + onDismiss = { state.eventSink(UserProfileEvent.ClearBlockUserError) }, onRetry = { val event = when (isBlocked.prevData) { - true -> UserProfileEvents.UnblockUser(needsConfirmation = false) - false -> UserProfileEvents.BlockUser(needsConfirmation = false) + true -> UserProfileEvent.UnblockUser(needsConfirmation = false) + false -> UserProfileEvent.BlockUser(needsConfirmation = false) // null case Should not happen - null -> UserProfileEvents.ClearBlockUserError + null -> UserProfileEvent.ClearBlockUserError } state.eventSink(event) }, @@ -68,7 +68,7 @@ fun BlockUserSection( private fun PreferenceBlockUser( isBlocked: Boolean?, isLoading: Boolean, - eventSink: (UserProfileEvents) -> Unit, + eventSink: (UserProfileEvent) -> Unit, ) { val loadingCurrentValue = @Composable { _: Boolean -> CircularProgressIndicator( @@ -82,7 +82,7 @@ private fun PreferenceBlockUser( ListItem( content = { Text(stringResource(R.string.screen_dm_details_unblock_user)) }, leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.Block())), - onClick = { if (!isLoading) eventSink(UserProfileEvents.UnblockUser(needsConfirmation = true)) }, + onClick = { if (!isLoading) eventSink(UserProfileEvent.UnblockUser(needsConfirmation = true)) }, trailingContent = if (isLoading) ListItemContent.Custom(loadingCurrentValue) else null, ) } else { @@ -90,7 +90,7 @@ private fun PreferenceBlockUser( content = { Text(stringResource(R.string.screen_dm_details_block_user)) }, leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.Block())), style = ListItemStyle.Destructive, - onClick = { if (!isLoading) eventSink(UserProfileEvents.BlockUser(needsConfirmation = true)) }, + onClick = { if (!isLoading) eventSink(UserProfileEvent.BlockUser(needsConfirmation = true)) }, trailingContent = if (isLoading) ListItemContent.Custom(loadingCurrentValue) else null, ) } diff --git a/features/userprofile/shared/src/test/kotlin/io/element/android/features/userprofile/UserProfileViewTest.kt b/features/userprofile/shared/src/test/kotlin/io/element/android/features/userprofile/UserProfileViewTest.kt index 63930affee..9c6aa66670 100644 --- a/features/userprofile/shared/src/test/kotlin/io/element/android/features/userprofile/UserProfileViewTest.kt +++ b/features/userprofile/shared/src/test/kotlin/io/element/android/features/userprofile/UserProfileViewTest.kt @@ -16,7 +16,7 @@ import androidx.compose.ui.test.ExperimentalTestApi import androidx.compose.ui.test.hasTestTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.v2.runAndroidComposeUiTest -import io.element.android.features.userprofile.api.UserProfileEvents +import io.element.android.features.userprofile.api.UserProfileEvent import io.element.android.features.userprofile.api.UserProfileState import io.element.android.features.userprofile.api.UserProfileVerificationState import io.element.android.features.userprofile.shared.R @@ -89,7 +89,7 @@ class UserProfileViewTest : RobolectricTest() { @Test fun `on Message clicked - the StartDm event is emitted`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setUserProfileView( state = aUserProfileState( dmRoomId = A_ROOM_ID, @@ -97,7 +97,7 @@ class UserProfileViewTest : RobolectricTest() { ), ) clickOn(CommonStrings.action_message) - eventsRecorder.assertSingle(UserProfileEvents.StartDM) + eventsRecorder.assertSingle(UserProfileEvent.StartDM) } @Test @@ -131,19 +131,19 @@ class UserProfileViewTest : RobolectricTest() { @Config(qualifiers = "h1024dp") @Test fun `on Block user clicked - a BlockUser event is emitted with needsConfirmation`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setUserProfileView( state = aUserProfileState( eventSink = eventsRecorder, ), ) clickOn(R.string.screen_dm_details_block_user) - eventsRecorder.assertSingle(UserProfileEvents.BlockUser(needsConfirmation = true)) + eventsRecorder.assertSingle(UserProfileEvent.BlockUser(needsConfirmation = true)) } @Test fun `on confirming block user - a BlockUser event is emitted without needsConfirmation`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setUserProfileView( state = aUserProfileState( displayConfirmationDialog = UserProfileState.ConfirmationDialog.Block, @@ -151,12 +151,12 @@ class UserProfileViewTest : RobolectricTest() { ), ) clickOn(R.string.screen_dm_details_block_alert_action) - eventsRecorder.assertSingle(UserProfileEvents.BlockUser(needsConfirmation = false)) + eventsRecorder.assertSingle(UserProfileEvent.BlockUser(needsConfirmation = false)) } @Test fun `on canceling blocking a user - a ClearConfirmationDialog event is emitted`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setUserProfileView( state = aUserProfileState( displayConfirmationDialog = UserProfileState.ConfirmationDialog.Block, @@ -164,13 +164,13 @@ class UserProfileViewTest : RobolectricTest() { ), ) clickOn(CommonStrings.action_cancel) - eventsRecorder.assertSingle(UserProfileEvents.ClearConfirmationDialog) + eventsRecorder.assertSingle(UserProfileEvent.ClearConfirmationDialog) } @Config(qualifiers = "h1024dp") @Test fun `on Unblock user clicked - an UnblockUser event is emitted with needsConfirmation`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setUserProfileView( state = aUserProfileState( isBlocked = AsyncData.Success(true), @@ -178,12 +178,12 @@ class UserProfileViewTest : RobolectricTest() { ), ) clickOn(R.string.screen_dm_details_unblock_user) - eventsRecorder.assertSingle(UserProfileEvents.UnblockUser(needsConfirmation = true)) + eventsRecorder.assertSingle(UserProfileEvent.UnblockUser(needsConfirmation = true)) } @Test fun `on confirming Unblock user - an UnblockUser event is emitted without needsConfirmation`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setUserProfileView( state = aUserProfileState( isBlocked = AsyncData.Success(true), @@ -192,12 +192,12 @@ class UserProfileViewTest : RobolectricTest() { ), ) clickOn(R.string.screen_dm_details_unblock_alert_action) - eventsRecorder.assertSingle(UserProfileEvents.UnblockUser(needsConfirmation = false)) + eventsRecorder.assertSingle(UserProfileEvent.UnblockUser(needsConfirmation = false)) } @Test fun `on canceling unblocking a user - a ClearConfirmationDialog event is emitted`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setUserProfileView( state = aUserProfileState( isBlocked = AsyncData.Success(true), @@ -206,7 +206,7 @@ class UserProfileViewTest : RobolectricTest() { ), ) clickOn(CommonStrings.action_cancel) - eventsRecorder.assertSingle(UserProfileEvents.ClearConfirmationDialog) + eventsRecorder.assertSingle(UserProfileEvent.ClearConfirmationDialog) } @Test diff --git a/features/userprofile/shared/src/test/kotlin/io/element/android/features/userprofile/shared/blockuser/BlockUserDialogsTest.kt b/features/userprofile/shared/src/test/kotlin/io/element/android/features/userprofile/shared/blockuser/BlockUserDialogsTest.kt index b0a2590e8a..575c9ff7a0 100644 --- a/features/userprofile/shared/src/test/kotlin/io/element/android/features/userprofile/shared/blockuser/BlockUserDialogsTest.kt +++ b/features/userprofile/shared/src/test/kotlin/io/element/android/features/userprofile/shared/blockuser/BlockUserDialogsTest.kt @@ -12,7 +12,7 @@ package io.element.android.features.userprofile.shared.blockuser import androidx.compose.ui.test.ExperimentalTestApi import androidx.compose.ui.test.v2.runAndroidComposeUiTest -import io.element.android.features.userprofile.api.UserProfileEvents +import io.element.android.features.userprofile.api.UserProfileEvent import io.element.android.features.userprofile.api.UserProfileState import io.element.android.features.userprofile.shared.R import io.element.android.features.userprofile.shared.aUserProfileState @@ -25,7 +25,7 @@ import org.junit.Test class BlockUserDialogsTest : RobolectricTest() { @Test fun `confirm block user emit expected Event`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setContent { BlockUserDialogs( state = aUserProfileState( @@ -35,12 +35,12 @@ class BlockUserDialogsTest : RobolectricTest() { ) } clickOn(R.string.screen_dm_details_block_alert_action) - eventsRecorder.assertSingle(UserProfileEvents.BlockUser(false)) + eventsRecorder.assertSingle(UserProfileEvent.BlockUser(false)) } @Test fun `cancel block user emit expected Event`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setContent { BlockUserDialogs( state = aUserProfileState( @@ -50,12 +50,12 @@ class BlockUserDialogsTest : RobolectricTest() { ) } clickOn(CommonStrings.action_cancel) - eventsRecorder.assertSingle(UserProfileEvents.ClearConfirmationDialog) + eventsRecorder.assertSingle(UserProfileEvent.ClearConfirmationDialog) } @Test fun `confirm unblock user emit expected Event`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setContent { BlockUserDialogs( state = aUserProfileState( @@ -65,12 +65,12 @@ class BlockUserDialogsTest : RobolectricTest() { ) } clickOn(R.string.screen_dm_details_unblock_alert_action) - eventsRecorder.assertSingle(UserProfileEvents.UnblockUser(false)) + eventsRecorder.assertSingle(UserProfileEvent.UnblockUser(false)) } @Test fun `cancel unblock user emit expected Event`() = runAndroidComposeUiTest { - val eventsRecorder = EventsRecorder() + val eventsRecorder = EventsRecorder() setContent { BlockUserDialogs( state = aUserProfileState( @@ -80,6 +80,6 @@ class BlockUserDialogsTest : RobolectricTest() { ) } clickOn(CommonStrings.action_cancel) - eventsRecorder.assertSingle(UserProfileEvents.ClearConfirmationDialog) + eventsRecorder.assertSingle(UserProfileEvent.ClearConfirmationDialog) } }