mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
UserProfileEvents -> UserProfileEvent
This commit is contained in:
+2
-2
@@ -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,
|
||||
|
||||
+8
-8
@@ -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)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
+5
-5
@@ -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) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
+15
-15
@@ -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<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
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<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
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<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
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<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
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<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
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<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
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<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
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
|
||||
|
||||
+9
-9
@@ -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<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
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<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
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<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
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<UserProfileEvents>()
|
||||
val eventsRecorder = EventsRecorder<UserProfileEvent>()
|
||||
setContent {
|
||||
BlockUserDialogs(
|
||||
state = aUserProfileState(
|
||||
@@ -80,6 +80,6 @@ class BlockUserDialogsTest : RobolectricTest() {
|
||||
)
|
||||
}
|
||||
clickOn(CommonStrings.action_cancel)
|
||||
eventsRecorder.assertSingle(UserProfileEvents.ClearConfirmationDialog)
|
||||
eventsRecorder.assertSingle(UserProfileEvent.ClearConfirmationDialog)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user