Merge branch 'develop' into feature/fga/role_and_permissions_rework
This commit is contained in:
commit
83a4457d6e
185 changed files with 1900 additions and 1125 deletions
|
|
@ -93,6 +93,7 @@ dependencies {
|
|||
testImplementation(projects.libraries.featureflag.test)
|
||||
testImplementation(projects.libraries.preferences.test)
|
||||
testImplementation(projects.libraries.matrix.test)
|
||||
testImplementation(projects.libraries.matrixuiTest)
|
||||
testImplementation(projects.libraries.push.test)
|
||||
testImplementation(projects.services.analytics.test)
|
||||
testImplementation(projects.services.appnavstate.test)
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ class CallScreenPresenter(
|
|||
userAgent = userAgent,
|
||||
isCallActive = isWidgetLoaded,
|
||||
isInWidgetMode = isInWidgetMode,
|
||||
eventSink = { handleEvents(it) },
|
||||
eventSink = ::handleEvents,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import io.element.android.libraries.matrix.test.A_SESSION_ID
|
|||
import io.element.android.libraries.matrix.test.A_USER_ID_2
|
||||
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||
import io.element.android.libraries.matrix.test.FakeMatrixClientProvider
|
||||
import io.element.android.libraries.push.test.notifications.FakeImageLoaderHolder
|
||||
import io.element.android.libraries.matrix.ui.test.media.FakeImageLoaderHolder
|
||||
import io.element.android.libraries.push.test.notifications.push.FakeNotificationBitmapLoader
|
||||
import io.element.android.tests.testutils.lambda.lambdaRecorder
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ import io.element.android.libraries.matrix.test.FakeMatrixClientProvider
|
|||
import io.element.android.libraries.matrix.test.room.FakeBaseRoom
|
||||
import io.element.android.libraries.matrix.test.room.FakeJoinedRoom
|
||||
import io.element.android.libraries.matrix.test.room.aRoomInfo
|
||||
import io.element.android.libraries.matrix.ui.test.media.FakeImageLoaderHolder
|
||||
import io.element.android.libraries.push.api.notifications.ForegroundServiceType
|
||||
import io.element.android.libraries.push.api.notifications.NotificationIdProvider
|
||||
import io.element.android.libraries.push.test.notifications.FakeImageLoaderHolder
|
||||
import io.element.android.libraries.push.test.notifications.FakeOnMissedCallNotificationHandler
|
||||
import io.element.android.libraries.push.test.notifications.push.FakeNotificationBitmapLoader
|
||||
import io.element.android.services.appnavstate.test.FakeAppForegroundStateService
|
||||
|
|
@ -415,6 +415,7 @@ class DefaultActiveCallManagerTest {
|
|||
|
||||
verify { notificationManagerCompat.cancel(any()) }
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun `IncomingCall - ignore expired ring lifetime`() = runTest {
|
||||
|
|
|
|||
|
|
@ -24,11 +24,12 @@ class FakeEnterpriseService(
|
|||
private val defaultHomeserverListResult: () -> List<String> = { emptyList() },
|
||||
private val isAllowedToConnectToHomeserverResult: (String) -> Boolean = { lambdaError() },
|
||||
initialSemanticColors: SemanticColorsLightDark = SemanticColorsLightDark.default,
|
||||
initialBrandColor: Color? = null,
|
||||
private val overrideBrandColorResult: (SessionId?, String?) -> Unit = { _, _ -> lambdaError() },
|
||||
private val firebasePushGatewayResult: () -> String? = { lambdaError() },
|
||||
private val unifiedPushDefaultPushGatewayResult: () -> String? = { lambdaError() },
|
||||
) : EnterpriseService {
|
||||
private val brandColorState = MutableStateFlow<Color?>(null)
|
||||
private val brandColorState = MutableStateFlow(initialBrandColor)
|
||||
private val semanticColorsState = MutableStateFlow(initialSemanticColors)
|
||||
|
||||
override suspend fun isEnterpriseUser(sessionId: SessionId): Boolean = simulateLongTask {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ dependencies {
|
|||
implementation(projects.libraries.designsystem)
|
||||
implementation(projects.libraries.matrix.api)
|
||||
implementation(projects.libraries.roomselect.api)
|
||||
implementation(projects.libraries.uiStrings)
|
||||
|
||||
testCommonDependencies(libs, true)
|
||||
testImplementation(projects.libraries.matrix.test)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import io.element.android.libraries.matrix.api.timeline.TimelineProvider
|
|||
import io.element.android.libraries.matrix.api.timeline.getActiveTimeline
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
@AssistedInject
|
||||
class ForwardMessagesPresenter(
|
||||
|
|
@ -54,7 +55,7 @@ class ForwardMessagesPresenter(
|
|||
|
||||
return ForwardMessagesState(
|
||||
forwardAction = forwardingActionState.value,
|
||||
eventSink = { handleEvents(it) }
|
||||
eventSink = ::handleEvents,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +64,11 @@ class ForwardMessagesPresenter(
|
|||
roomIds: List<RoomId>,
|
||||
) = launch {
|
||||
suspend {
|
||||
timelineProvider.getActiveTimeline().forwardEvent(eventId, roomIds).getOrThrow()
|
||||
timelineProvider.getActiveTimeline().forwardEvent(eventId, roomIds)
|
||||
.onFailure {
|
||||
Timber.e(it, "Error while forwarding event")
|
||||
}
|
||||
.getOrThrow()
|
||||
roomIds
|
||||
}.runCatchingUpdatingState(forwardingActionState)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,13 @@
|
|||
package io.element.android.features.forward.impl
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import io.element.android.libraries.designsystem.components.async.AsyncActionView
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
|
||||
@Composable
|
||||
fun ForwardMessagesView(
|
||||
|
|
@ -24,6 +26,9 @@ fun ForwardMessagesView(
|
|||
onSuccess = {
|
||||
onForwardSuccess(it)
|
||||
},
|
||||
errorMessage = {
|
||||
stringResource(id = CommonStrings.error_unknown)
|
||||
},
|
||||
onErrorDismiss = {
|
||||
state.eventSink(ForwardMessagesEvents.ClearError)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ import androidx.compose.runtime.remember
|
|||
import dev.zacsweers.metro.Inject
|
||||
import io.element.android.features.logout.api.direct.DirectLogoutEvents
|
||||
import io.element.android.features.logout.api.direct.DirectLogoutState
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
import io.element.android.libraries.core.coroutine.mapState
|
||||
import io.element.android.libraries.matrix.api.encryption.EncryptionService
|
||||
import io.element.android.libraries.matrix.api.encryption.RecoveryState
|
||||
|
||||
|
|
@ -27,8 +29,33 @@ class ChooseSelfVerificationModePresenter(
|
|||
@Composable
|
||||
override fun present(): ChooseSelfVerificationModeState {
|
||||
val hasDevicesToVerifyAgainst by encryptionService.hasDevicesToVerifyAgainst.collectAsState()
|
||||
val recoveryState by encryptionService.recoveryStateStateFlow.collectAsState()
|
||||
val canEnterRecoveryKey by remember { derivedStateOf { recoveryState == RecoveryState.INCOMPLETE } }
|
||||
val canEnterRecoveryKey by encryptionService.recoveryStateStateFlow
|
||||
.mapState { recoveryState ->
|
||||
when (recoveryState) {
|
||||
RecoveryState.WAITING_FOR_SYNC,
|
||||
RecoveryState.UNKNOWN -> AsyncData.Loading()
|
||||
RecoveryState.INCOMPLETE -> AsyncData.Success(true)
|
||||
RecoveryState.ENABLED,
|
||||
RecoveryState.DISABLED -> AsyncData.Success(false)
|
||||
}
|
||||
}
|
||||
.collectAsState()
|
||||
val buttonsState by remember {
|
||||
derivedStateOf {
|
||||
val canUseAnotherDevice = hasDevicesToVerifyAgainst.dataOrNull()
|
||||
val canEnterRecoveryKey = canEnterRecoveryKey.dataOrNull()
|
||||
if (canUseAnotherDevice == null || canEnterRecoveryKey == null) {
|
||||
AsyncData.Loading()
|
||||
} else {
|
||||
AsyncData.Success(
|
||||
ChooseSelfVerificationModeState.ButtonsState(
|
||||
canUseAnotherDevice = canUseAnotherDevice,
|
||||
canEnterRecoveryKey = canEnterRecoveryKey,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val directLogoutState = directLogoutPresenter.present()
|
||||
|
||||
|
|
@ -39,8 +66,7 @@ class ChooseSelfVerificationModePresenter(
|
|||
}
|
||||
|
||||
return ChooseSelfVerificationModeState(
|
||||
canUseAnotherDevice = hasDevicesToVerifyAgainst,
|
||||
canEnterRecoveryKey = canEnterRecoveryKey,
|
||||
buttonsState = buttonsState,
|
||||
directLogoutState = directLogoutState,
|
||||
eventSink = ::eventHandler,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,10 +8,15 @@
|
|||
package io.element.android.features.ftue.impl.sessionverification.choosemode
|
||||
|
||||
import io.element.android.features.logout.api.direct.DirectLogoutState
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
|
||||
data class ChooseSelfVerificationModeState(
|
||||
val canUseAnotherDevice: Boolean,
|
||||
val canEnterRecoveryKey: Boolean,
|
||||
val buttonsState: AsyncData<ButtonsState>,
|
||||
val directLogoutState: DirectLogoutState,
|
||||
val eventSink: (ChooseSelfVerificationModeEvent) -> Unit,
|
||||
)
|
||||
) {
|
||||
data class ButtonsState(
|
||||
val canUseAnotherDevice: Boolean,
|
||||
val canEnterRecoveryKey: Boolean,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,23 +9,49 @@ package io.element.android.features.ftue.impl.sessionverification.choosemode
|
|||
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import io.element.android.features.logout.api.direct.aDirectLogoutState
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
|
||||
class ChooseSelfVerificationModeStateProvider :
|
||||
PreviewParameterProvider<ChooseSelfVerificationModeState> {
|
||||
override val values = sequenceOf(
|
||||
aChooseSelfVerificationModeState(canUseAnotherDevice = false, canEnterRecoveryKey = true),
|
||||
aChooseSelfVerificationModeState(canUseAnotherDevice = false, canEnterRecoveryKey = false),
|
||||
aChooseSelfVerificationModeState(canUseAnotherDevice = true, canEnterRecoveryKey = true),
|
||||
aChooseSelfVerificationModeState(canUseAnotherDevice = true, canEnterRecoveryKey = false),
|
||||
aChooseSelfVerificationModeState(
|
||||
buttonsState = AsyncData.Success(
|
||||
aButtonsState(canUseAnotherDevice = false, canEnterRecoveryKey = true),
|
||||
),
|
||||
),
|
||||
aChooseSelfVerificationModeState(
|
||||
buttonsState = AsyncData.Success(
|
||||
aButtonsState(canUseAnotherDevice = false, canEnterRecoveryKey = false),
|
||||
),
|
||||
),
|
||||
aChooseSelfVerificationModeState(
|
||||
buttonsState = AsyncData.Success(
|
||||
aButtonsState(canUseAnotherDevice = true, canEnterRecoveryKey = true),
|
||||
),
|
||||
),
|
||||
aChooseSelfVerificationModeState(
|
||||
buttonsState = AsyncData.Success(
|
||||
aButtonsState(canUseAnotherDevice = true, canEnterRecoveryKey = false),
|
||||
),
|
||||
),
|
||||
aChooseSelfVerificationModeState(
|
||||
buttonsState = AsyncData.Loading(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fun aChooseSelfVerificationModeState(
|
||||
canUseAnotherDevice: Boolean = true,
|
||||
canEnterRecoveryKey: Boolean = true,
|
||||
buttonsState: AsyncData<ChooseSelfVerificationModeState.ButtonsState> = AsyncData.Success(aButtonsState()),
|
||||
) = ChooseSelfVerificationModeState(
|
||||
canUseAnotherDevice = canUseAnotherDevice,
|
||||
canEnterRecoveryKey = canEnterRecoveryKey,
|
||||
buttonsState = buttonsState,
|
||||
directLogoutState = aDirectLogoutState(),
|
||||
eventSink = {},
|
||||
)
|
||||
|
||||
fun aButtonsState(
|
||||
canUseAnotherDevice: Boolean = true,
|
||||
canEnterRecoveryKey: Boolean = true,
|
||||
) = ChooseSelfVerificationModeState.ButtonsState(
|
||||
canUseAnotherDevice = canUseAnotherDevice,
|
||||
canEnterRecoveryKey = canEnterRecoveryKey,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import androidx.compose.ui.unit.dp
|
|||
import io.element.android.compound.theme.ElementTheme
|
||||
import io.element.android.compound.tokens.generated.CompoundIcons
|
||||
import io.element.android.features.ftue.impl.R
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
import io.element.android.libraries.designsystem.atomic.molecules.ButtonColumnMolecule
|
||||
import io.element.android.libraries.designsystem.atomic.molecules.IconTitleSubtitleMolecule
|
||||
import io.element.android.libraries.designsystem.atomic.pages.HeaderFooterPage
|
||||
|
|
@ -50,7 +51,6 @@ fun ChooseSelfVerificationModeView(
|
|||
BackHandler {
|
||||
activity?.finish()
|
||||
}
|
||||
|
||||
HeaderFooterPage(
|
||||
modifier = modifier,
|
||||
topBar = {
|
||||
|
|
@ -73,29 +73,12 @@ fun ChooseSelfVerificationModeView(
|
|||
)
|
||||
},
|
||||
footer = {
|
||||
ButtonColumnMolecule(
|
||||
modifier = Modifier.padding(bottom = 16.dp)
|
||||
) {
|
||||
if (state.canUseAnotherDevice) {
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
text = stringResource(R.string.screen_identity_use_another_device),
|
||||
onClick = onUseAnotherDevice,
|
||||
)
|
||||
}
|
||||
if (state.canEnterRecoveryKey) {
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
text = stringResource(R.string.screen_session_verification_enter_recovery_key),
|
||||
onClick = onUseRecoveryKey,
|
||||
)
|
||||
}
|
||||
OutlinedButton(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
text = stringResource(R.string.screen_identity_confirmation_cannot_confirm),
|
||||
onClick = onResetKey,
|
||||
)
|
||||
}
|
||||
ChooseSelfVerificationModeButtons(
|
||||
state = state,
|
||||
onUseAnotherDevice = onUseAnotherDevice,
|
||||
onUseRecoveryKey = onUseRecoveryKey,
|
||||
onResetKey = onResetKey,
|
||||
)
|
||||
}
|
||||
) {
|
||||
Row(
|
||||
|
|
@ -113,6 +96,53 @@ fun ChooseSelfVerificationModeView(
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ChooseSelfVerificationModeButtons(
|
||||
state: ChooseSelfVerificationModeState,
|
||||
onUseAnotherDevice: () -> Unit,
|
||||
onUseRecoveryKey: () -> Unit,
|
||||
onResetKey: () -> Unit,
|
||||
) {
|
||||
ButtonColumnMolecule(
|
||||
modifier = Modifier.padding(bottom = 16.dp)
|
||||
) {
|
||||
when (state.buttonsState) {
|
||||
AsyncData.Uninitialized,
|
||||
is AsyncData.Failure,
|
||||
is AsyncData.Loading -> {
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
enabled = false,
|
||||
showProgress = true,
|
||||
text = stringResource(CommonStrings.common_loading),
|
||||
onClick = {},
|
||||
)
|
||||
}
|
||||
is AsyncData.Success -> {
|
||||
if (state.buttonsState.data.canUseAnotherDevice) {
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
text = stringResource(R.string.screen_identity_use_another_device),
|
||||
onClick = onUseAnotherDevice,
|
||||
)
|
||||
}
|
||||
if (state.buttonsState.data.canEnterRecoveryKey) {
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
text = stringResource(R.string.screen_session_verification_enter_recovery_key),
|
||||
onClick = onUseRecoveryKey,
|
||||
)
|
||||
}
|
||||
OutlinedButton(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
text = stringResource(R.string.screen_identity_confirmation_cannot_confirm),
|
||||
onClick = onResetKey,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PreviewsDayNight
|
||||
@Composable
|
||||
internal fun ChooseSelfVerificationModeViewPreview(
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.google.common.truth.Truth.assertThat
|
|||
import io.element.android.features.logout.api.direct.DirectLogoutEvents
|
||||
import io.element.android.features.logout.api.direct.DirectLogoutState
|
||||
import io.element.android.features.logout.api.direct.aDirectLogoutState
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
import io.element.android.libraries.matrix.api.encryption.RecoveryState
|
||||
import io.element.android.libraries.matrix.test.encryption.FakeEncryptionService
|
||||
|
|
@ -22,23 +23,92 @@ import org.junit.Test
|
|||
|
||||
class ChooseSessionVerificationModePresenterTest {
|
||||
@Test
|
||||
fun `initial state - is relayed from EncryptionService`() = runTest {
|
||||
val encryptionService = FakeEncryptionService().apply {
|
||||
// Has device to verify against
|
||||
emitHasDevicesToVerifyAgainst(false)
|
||||
// Can enter recovery key
|
||||
emitRecoveryState(RecoveryState.INCOMPLETE)
|
||||
}
|
||||
val presenter = createPresenter(encryptionService = encryptionService)
|
||||
fun `present - initial state`() = runTest {
|
||||
val presenter = createPresenter()
|
||||
presenter.test {
|
||||
awaitItem().run {
|
||||
assertThat(canUseAnotherDevice).isFalse()
|
||||
assertThat(canEnterRecoveryKey).isTrue()
|
||||
assertThat(buttonsState.isLoading()).isTrue()
|
||||
assertThat(directLogoutState.logoutAction.isUninitialized()).isTrue()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - state is relayed from EncryptionService, order 1`() = runTest {
|
||||
val encryptionService = FakeEncryptionService()
|
||||
val presenter = createPresenter(encryptionService = encryptionService)
|
||||
presenter.test {
|
||||
assertThat(awaitItem().buttonsState.isLoading()).isTrue()
|
||||
// Has device to verify against
|
||||
encryptionService.emitHasDevicesToVerifyAgainst(AsyncData.Success(false))
|
||||
// Can enter recovery key
|
||||
encryptionService.emitRecoveryState(RecoveryState.DISABLED)
|
||||
assertThat(awaitItem().buttonsState.dataOrNull()).isEqualTo(
|
||||
ChooseSelfVerificationModeState.ButtonsState(
|
||||
canUseAnotherDevice = false,
|
||||
canEnterRecoveryKey = false,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - state is relayed from EncryptionService, order 2`() = runTest {
|
||||
val encryptionService = FakeEncryptionService()
|
||||
val presenter = createPresenter(encryptionService = encryptionService)
|
||||
presenter.test {
|
||||
assertThat(awaitItem().buttonsState.isLoading()).isTrue()
|
||||
// Can enter recovery key
|
||||
encryptionService.emitRecoveryState(RecoveryState.DISABLED)
|
||||
// Has device to verify against
|
||||
encryptionService.emitHasDevicesToVerifyAgainst(AsyncData.Success(false))
|
||||
assertThat(awaitItem().buttonsState.dataOrNull()).isEqualTo(
|
||||
ChooseSelfVerificationModeState.ButtonsState(
|
||||
canUseAnotherDevice = false,
|
||||
canEnterRecoveryKey = false,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - can use another device`() = runTest {
|
||||
val encryptionService = FakeEncryptionService()
|
||||
val presenter = createPresenter(encryptionService = encryptionService)
|
||||
presenter.test {
|
||||
assertThat(awaitItem().buttonsState.isLoading()).isTrue()
|
||||
// Can enter recovery key
|
||||
encryptionService.emitRecoveryState(RecoveryState.DISABLED)
|
||||
// Has device to verify against
|
||||
encryptionService.emitHasDevicesToVerifyAgainst(AsyncData.Success(true))
|
||||
assertThat(awaitItem().buttonsState.dataOrNull()).isEqualTo(
|
||||
ChooseSelfVerificationModeState.ButtonsState(
|
||||
canUseAnotherDevice = true,
|
||||
canEnterRecoveryKey = false,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - can enter recovery key`() = runTest {
|
||||
val encryptionService = FakeEncryptionService()
|
||||
val presenter = createPresenter(encryptionService = encryptionService)
|
||||
presenter.test {
|
||||
assertThat(awaitItem().buttonsState.isLoading()).isTrue()
|
||||
// Can enter recovery key
|
||||
encryptionService.emitRecoveryState(RecoveryState.INCOMPLETE)
|
||||
// Has device to verify against
|
||||
encryptionService.emitHasDevicesToVerifyAgainst(AsyncData.Success(false))
|
||||
assertThat(awaitItem().buttonsState.dataOrNull()).isEqualTo(
|
||||
ChooseSelfVerificationModeState.ButtonsState(
|
||||
canUseAnotherDevice = false,
|
||||
canEnterRecoveryKey = true,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sing out action triggers a direct logout`() = runTest {
|
||||
val logoutEventRecorder = lambdaRecorder<DirectLogoutEvents, Unit> {}
|
||||
|
|
@ -49,8 +119,8 @@ class ChooseSessionVerificationModePresenterTest {
|
|||
presenter.test {
|
||||
val initial = awaitItem()
|
||||
initial.eventSink(ChooseSelfVerificationModeEvent.SignOut)
|
||||
|
||||
logoutEventRecorder.assertions().isCalledOnce().with(value(DirectLogoutEvents.Logout(ignoreSdkError = false)))
|
||||
logoutEventRecorder.assertions().isCalledOnce()
|
||||
.with(value(DirectLogoutEvents.Logout(ignoreSdkError = false)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import androidx.compose.ui.test.junit4.AndroidComposeTestRule
|
|||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import io.element.android.features.ftue.impl.R
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
import io.element.android.tests.testutils.EnsureNeverCalled
|
||||
import io.element.android.tests.testutils.clickOn
|
||||
|
|
@ -43,7 +44,7 @@ class ChooseSessionVerificationModeViewTest {
|
|||
fun `clicking on use another device calls the callback`() {
|
||||
ensureCalledOnce { callback ->
|
||||
rule.setChooseSelfVerificationModeView(
|
||||
aChooseSelfVerificationModeState(canUseAnotherDevice = true),
|
||||
aChooseSelfVerificationModeState(AsyncData.Success(aButtonsState(canUseAnotherDevice = true))),
|
||||
onUseAnotherDevice = callback,
|
||||
)
|
||||
rule.clickOn(R.string.screen_identity_use_another_device)
|
||||
|
|
@ -55,7 +56,7 @@ class ChooseSessionVerificationModeViewTest {
|
|||
fun `clicking on enter recovery key calls the callback`() {
|
||||
ensureCalledOnce { callback ->
|
||||
rule.setChooseSelfVerificationModeView(
|
||||
aChooseSelfVerificationModeState(canEnterRecoveryKey = true),
|
||||
aChooseSelfVerificationModeState(AsyncData.Success(aButtonsState(canEnterRecoveryKey = true))),
|
||||
onEnterRecoveryKey = callback,
|
||||
)
|
||||
rule.clickOn(R.string.screen_session_verification_enter_recovery_key)
|
||||
|
|
|
|||
|
|
@ -13,5 +13,4 @@ data class AccountProvider(
|
|||
val subtitle: String? = null,
|
||||
val isPublic: Boolean = false,
|
||||
val isMatrixOrg: Boolean = false,
|
||||
val isValid: Boolean = false,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ open class AccountProviderProvider : PreviewParameterProvider<AccountProvider> {
|
|||
get() = sequenceOf(
|
||||
anAccountProvider(),
|
||||
anAccountProvider().copy(subtitle = null),
|
||||
anAccountProvider().copy(subtitle = null, title = "invalid", isValid = false),
|
||||
anAccountProvider().copy(subtitle = null, title = "invalid"),
|
||||
anAccountProvider().copy(subtitle = null, title = "Other", isPublic = false, isMatrixOrg = false),
|
||||
// Add other state here
|
||||
)
|
||||
|
|
@ -26,11 +26,9 @@ fun anAccountProvider(
|
|||
subtitle: String? = "Matrix.org is an open network for secure, decentralized communication.",
|
||||
isPublic: Boolean = true,
|
||||
isMatrixOrg: Boolean = true,
|
||||
isValid: Boolean = true,
|
||||
) = AccountProvider(
|
||||
url = url,
|
||||
subtitle = subtitle,
|
||||
isPublic = isPublic,
|
||||
isMatrixOrg = isMatrixOrg,
|
||||
isValid = isValid,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,4 @@ package io.element.android.features.login.impl.resolver
|
|||
data class HomeserverData(
|
||||
// The computed homeserver url, for which a wellknown file has been retrieved, or just a valid Url
|
||||
val homeserverUrl: String,
|
||||
// True if a wellknown file has been found and is valid. If false, it means that the [homeserverUrl] is valid
|
||||
val isWellknownValid: Boolean,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,19 +8,16 @@
|
|||
package io.element.android.features.login.impl.resolver
|
||||
|
||||
import dev.zacsweers.metro.Inject
|
||||
import io.element.android.libraries.core.bool.orFalse
|
||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.libraries.core.coroutine.parallelMap
|
||||
import io.element.android.libraries.core.data.tryOrNull
|
||||
import io.element.android.libraries.core.uri.ensureProtocol
|
||||
import io.element.android.libraries.core.uri.isValidUrl
|
||||
import io.element.android.libraries.wellknown.api.WellKnown
|
||||
import io.element.android.libraries.wellknown.api.WellknownRetriever
|
||||
import io.element.android.libraries.matrix.api.auth.HomeServerLoginCompatibilityChecker
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import timber.log.Timber
|
||||
import java.util.Collections
|
||||
|
||||
/**
|
||||
|
|
@ -29,7 +26,7 @@ import java.util.Collections
|
|||
@Inject
|
||||
class HomeserverResolver(
|
||||
private val dispatchers: CoroutineDispatchers,
|
||||
private val wellknownRetriever: WellknownRetriever,
|
||||
private val homeServerLoginCompatibilityChecker: HomeServerLoginCompatibilityChecker,
|
||||
) {
|
||||
fun resolve(userInput: String): Flow<List<HomeserverData>> = flow {
|
||||
val flowContext = currentCoroutineContext()
|
||||
|
|
@ -41,20 +38,14 @@ class HomeserverResolver(
|
|||
// Run all the requests in parallel
|
||||
withContext(dispatchers.io) {
|
||||
list.parallelMap { url ->
|
||||
val wellKnown = tryOrNull {
|
||||
withTimeout(5000) {
|
||||
wellknownRetriever.getWellKnown(url)
|
||||
}
|
||||
}
|
||||
val isValid = wellKnown?.dataOrNull()?.isValid().orFalse()
|
||||
val isValid = homeServerLoginCompatibilityChecker.check(url)
|
||||
.onFailure { Timber.w(it, "Failed to check compatibility with homeserver $url") }
|
||||
.getOrNull()
|
||||
?: return@parallelMap
|
||||
|
||||
// Emit the list as soon as possible
|
||||
if (isValid) {
|
||||
// Emit the list as soon as possible
|
||||
currentList.add(
|
||||
HomeserverData(
|
||||
homeserverUrl = url,
|
||||
isWellknownValid = true,
|
||||
)
|
||||
)
|
||||
currentList.add(HomeserverData(homeserverUrl = url))
|
||||
withContext(flowContext) {
|
||||
emit(currentList.toList())
|
||||
}
|
||||
|
|
@ -63,14 +54,7 @@ class HomeserverResolver(
|
|||
}
|
||||
// If list is empty, and the user has entered an URL, do not block the user.
|
||||
if (currentList.isEmpty() && trimmedUserInput.isValidUrl()) {
|
||||
emit(
|
||||
listOf(
|
||||
HomeserverData(
|
||||
homeserverUrl = trimmedUserInput,
|
||||
isWellknownValid = false,
|
||||
)
|
||||
)
|
||||
)
|
||||
emit(listOf(HomeserverData(homeserverUrl = trimmedUserInput)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +72,3 @@ class HomeserverResolver(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun WellKnown.isValid(): Boolean {
|
||||
return homeServer?.baseURL?.isNotBlank().orFalse()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ class ChangeAccountProviderPresenter(
|
|||
subtitle = null,
|
||||
isPublic = url == AuthenticationConfig.MATRIX_ORG_URL,
|
||||
isMatrixOrg = url == AuthenticationConfig.MATRIX_ORG_URL,
|
||||
isValid = true,
|
||||
)
|
||||
}
|
||||
.toImmutableList()
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ class ChooseAccountProviderPresenter(
|
|||
subtitle = null,
|
||||
isPublic = url == AuthenticationConfig.MATRIX_ORG_URL,
|
||||
isMatrixOrg = url == AuthenticationConfig.MATRIX_ORG_URL,
|
||||
isValid = true,
|
||||
)
|
||||
}
|
||||
.toImmutableList()
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class OnBoardingPresenter(
|
|||
}
|
||||
val isAddingAccount by produceState(initialValue = false) {
|
||||
// We are adding an account if there is at least one session already stored
|
||||
value = sessionStore.getAllSessions().isNotEmpty()
|
||||
value = sessionStore.numberOfSessions() > 0
|
||||
}
|
||||
|
||||
val loginMode by loginHelper.collectLoginMode()
|
||||
|
|
|
|||
|
|
@ -57,14 +57,14 @@ class SearchAccountProviderPresenter(
|
|||
userInput = userInput,
|
||||
userInputResult = data.value,
|
||||
changeServerState = changeServerState,
|
||||
eventSink = ::handleEvents
|
||||
eventSink = ::handleEvents,
|
||||
)
|
||||
}
|
||||
|
||||
private fun CoroutineScope.onUserInput(userInput: String, data: MutableState<AsyncData<List<HomeserverData>>>) = launch {
|
||||
data.value = AsyncData.Uninitialized
|
||||
// Debounce
|
||||
delay(300)
|
||||
delay(500)
|
||||
data.value = AsyncData.Loading()
|
||||
homeserverResolver.resolve(userInput).collect {
|
||||
data.value = AsyncData.Success(it)
|
||||
|
|
|
|||
|
|
@ -34,18 +34,14 @@ fun aSearchAccountProviderState(
|
|||
|
||||
fun aHomeserverDataList(): List<HomeserverData> {
|
||||
return listOf(
|
||||
aHomeserverData(isWellknownValid = true),
|
||||
aHomeserverData(homeserverUrl = "https://no.sliding.sync", isWellknownValid = true),
|
||||
aHomeserverData(homeserverUrl = "https://invalid", isWellknownValid = false),
|
||||
aHomeserverData(homeserverUrl = AuthenticationConfig.MATRIX_ORG_URL),
|
||||
aHomeserverData(homeserverUrl = "https://no.sliding.sync"),
|
||||
aHomeserverData(homeserverUrl = "https://invalid"),
|
||||
)
|
||||
}
|
||||
|
||||
fun aHomeserverData(
|
||||
homeserverUrl: String = AuthenticationConfig.MATRIX_ORG_URL,
|
||||
isWellknownValid: Boolean = true,
|
||||
): HomeserverData {
|
||||
return HomeserverData(
|
||||
homeserverUrl = homeserverUrl,
|
||||
isWellknownValid = isWellknownValid,
|
||||
)
|
||||
return HomeserverData(homeserverUrl = homeserverUrl,)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,7 +192,6 @@ private fun HomeserverData.toAccountProvider(): AccountProvider {
|
|||
// There is no need to know for other servers right now
|
||||
isPublic = isMatrixOrg,
|
||||
isMatrixOrg = isMatrixOrg,
|
||||
isValid = isWellknownValid,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ class AccountProviderDataSourceTest {
|
|||
subtitle = null,
|
||||
isPublic = true,
|
||||
isMatrixOrg = true,
|
||||
isValid = false,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -55,7 +54,6 @@ class AccountProviderDataSourceTest {
|
|||
subtitle = null,
|
||||
isPublic = true,
|
||||
isMatrixOrg = true,
|
||||
isValid = false,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -77,7 +75,6 @@ class AccountProviderDataSourceTest {
|
|||
subtitle = null,
|
||||
isPublic = true,
|
||||
isMatrixOrg = true,
|
||||
isValid = false,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -98,7 +95,6 @@ class AccountProviderDataSourceTest {
|
|||
subtitle = null,
|
||||
isPublic = false,
|
||||
isMatrixOrg = false,
|
||||
isValid = false,
|
||||
)
|
||||
)
|
||||
sut.reset()
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ class ChangeAccountProviderPresenterTest {
|
|||
subtitle = null,
|
||||
isPublic = true,
|
||||
isMatrixOrg = true,
|
||||
isValid = true,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -76,7 +75,6 @@ class ChangeAccountProviderPresenterTest {
|
|||
subtitle = null,
|
||||
isPublic = true,
|
||||
isMatrixOrg = true,
|
||||
isValid = true,
|
||||
),
|
||||
AccountProvider(
|
||||
url = "https://element.io",
|
||||
|
|
@ -84,7 +82,6 @@ class ChangeAccountProviderPresenterTest {
|
|||
subtitle = null,
|
||||
isPublic = false,
|
||||
isMatrixOrg = false,
|
||||
isValid = true,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -114,7 +111,6 @@ class ChangeAccountProviderPresenterTest {
|
|||
subtitle = null,
|
||||
isPublic = true,
|
||||
isMatrixOrg = true,
|
||||
isValid = true,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -37,14 +37,12 @@ class ChooseAccountProviderPresenterTest {
|
|||
subtitle = null,
|
||||
isPublic = false,
|
||||
isMatrixOrg = false,
|
||||
isValid = true,
|
||||
)
|
||||
val accountProvider2 = AccountProvider(
|
||||
url = ACCOUNT_PROVIDER_FROM_CONFIG_2.ensureProtocol(),
|
||||
subtitle = null,
|
||||
isPublic = false,
|
||||
isMatrixOrg = false,
|
||||
isValid = true,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,12 +13,8 @@ import app.cash.turbine.test
|
|||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.features.login.impl.changeserver.aChangeServerState
|
||||
import io.element.android.features.login.impl.resolver.HomeserverResolver
|
||||
import io.element.android.features.wellknown.test.FakeWellknownRetriever
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
import io.element.android.libraries.matrix.test.A_HOMESERVER_URL
|
||||
import io.element.android.libraries.wellknown.api.WellKnown
|
||||
import io.element.android.libraries.wellknown.api.WellKnownBaseConfig
|
||||
import io.element.android.libraries.wellknown.api.WellknownRetrieverResult
|
||||
import io.element.android.libraries.matrix.test.auth.FakeHomeServerLoginCompatibilityChecker
|
||||
import io.element.android.tests.testutils.WarmUpRule
|
||||
import io.element.android.tests.testutils.lambda.lambdaRecorder
|
||||
import io.element.android.tests.testutils.lambda.value
|
||||
|
|
@ -33,9 +29,9 @@ class SearchAccountProviderPresenterTest {
|
|||
|
||||
@Test
|
||||
fun `present - initial state`() = runTest {
|
||||
val fakeWellknownRetriever = FakeWellknownRetriever()
|
||||
val fakeLoginCompatibilityChecker = FakeHomeServerLoginCompatibilityChecker(checkResult = { Result.success(true) })
|
||||
val presenter = SearchAccountProviderPresenter(
|
||||
homeserverResolver = HomeserverResolver(testCoroutineDispatchers(), fakeWellknownRetriever),
|
||||
homeserverResolver = HomeserverResolver(testCoroutineDispatchers(), fakeLoginCompatibilityChecker),
|
||||
changeServerPresenter = { aChangeServerState() }
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
|
|
@ -47,9 +43,35 @@ class SearchAccountProviderPresenterTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - error while checking login compatibility`() = runTest {
|
||||
val fakeLoginCompatibilityChecker = FakeHomeServerLoginCompatibilityChecker(checkResult = { Result.failure(IllegalStateException("Oops")) })
|
||||
val presenter = SearchAccountProviderPresenter(
|
||||
homeserverResolver = HomeserverResolver(testCoroutineDispatchers(), fakeLoginCompatibilityChecker),
|
||||
changeServerPresenter = { aChangeServerState() }
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
val initialState = awaitItem()
|
||||
initialState.eventSink.invoke(SearchAccountProviderEvents.UserInput("https://test.org"))
|
||||
val withInputState = awaitItem()
|
||||
assertThat(withInputState.userInput).isEqualTo("https://test.org")
|
||||
assertThat(initialState.userInputResult).isEqualTo(AsyncData.Uninitialized)
|
||||
assertThat(awaitItem().userInputResult).isInstanceOf(AsyncData.Loading::class.java)
|
||||
assertThat(awaitItem().userInputResult).isEqualTo(
|
||||
AsyncData.Success(
|
||||
listOf(
|
||||
aHomeserverData(homeserverUrl = "https://test.org")
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - enter text no result`() = runTest {
|
||||
val fakeWellknownRetriever = FakeWellknownRetriever()
|
||||
val fakeWellknownRetriever = FakeHomeServerLoginCompatibilityChecker(checkResult = { Result.success(false) })
|
||||
val presenter = SearchAccountProviderPresenter(
|
||||
homeserverResolver = HomeserverResolver(testCoroutineDispatchers(), fakeWellknownRetriever),
|
||||
changeServerPresenter = { aChangeServerState() }
|
||||
|
|
@ -67,48 +89,20 @@ class SearchAccountProviderPresenterTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - enter valid url no wellknown`() = runTest {
|
||||
val fakeWellknownRetriever = FakeWellknownRetriever()
|
||||
val presenter = SearchAccountProviderPresenter(
|
||||
homeserverResolver = HomeserverResolver(testCoroutineDispatchers(), fakeWellknownRetriever),
|
||||
changeServerPresenter = { aChangeServerState() }
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
val initialState = awaitItem()
|
||||
initialState.eventSink.invoke(SearchAccountProviderEvents.UserInput("https://test.org"))
|
||||
val withInputState = awaitItem()
|
||||
assertThat(withInputState.userInput).isEqualTo("https://test.org")
|
||||
assertThat(initialState.userInputResult).isEqualTo(AsyncData.Uninitialized)
|
||||
assertThat(awaitItem().userInputResult).isInstanceOf(AsyncData.Loading::class.java)
|
||||
assertThat(awaitItem().userInputResult).isEqualTo(
|
||||
AsyncData.Success(
|
||||
listOf(
|
||||
aHomeserverData(homeserverUrl = "https://test.org", isWellknownValid = false)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - enter text one result with wellknown`() = runTest {
|
||||
val getWellKnownResult = lambdaRecorder<String, WellknownRetrieverResult<WellKnown>> {
|
||||
val checkResult = lambdaRecorder<String, Result<Boolean>> {
|
||||
when (it) {
|
||||
"https://test.org" -> WellknownRetrieverResult.NotFound
|
||||
"https://test.com" -> WellknownRetrieverResult.NotFound
|
||||
"https://test.io" -> WellknownRetrieverResult.Success(aWellKnown())
|
||||
"https://test" -> WellknownRetrieverResult.NotFound
|
||||
"https://test.org" -> Result.success(false)
|
||||
"https://test.com" -> Result.success(false)
|
||||
"https://test.io" -> Result.success(true)
|
||||
"https://test" -> Result.success(false)
|
||||
else -> error("should not happen")
|
||||
}
|
||||
}
|
||||
val fakeWellknownRetriever = FakeWellknownRetriever(
|
||||
getWellKnownResult = getWellKnownResult,
|
||||
)
|
||||
val fakeLoginCompatibilityChecker = FakeHomeServerLoginCompatibilityChecker(checkResult = checkResult)
|
||||
val presenter = SearchAccountProviderPresenter(
|
||||
homeserverResolver = HomeserverResolver(testCoroutineDispatchers(), fakeWellknownRetriever),
|
||||
homeserverResolver = HomeserverResolver(testCoroutineDispatchers(), fakeLoginCompatibilityChecker),
|
||||
changeServerPresenter = { aChangeServerState() }
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
|
|
@ -127,7 +121,7 @@ class SearchAccountProviderPresenterTest {
|
|||
)
|
||||
)
|
||||
)
|
||||
getWellKnownResult.assertions().isCalledExactly(4)
|
||||
checkResult.assertions().isCalledExactly(4)
|
||||
.withSequence(
|
||||
listOf(value("https://test.org")),
|
||||
listOf(value("https://test.com")),
|
||||
|
|
@ -139,20 +133,18 @@ class SearchAccountProviderPresenterTest {
|
|||
|
||||
@Test
|
||||
fun `present - enter text two results with wellknown`() = runTest {
|
||||
val getWellKnownResult = lambdaRecorder<String, WellknownRetrieverResult<WellKnown>> {
|
||||
val checkResult = lambdaRecorder<String, Result<Boolean>> {
|
||||
when (it) {
|
||||
"https://test.org" -> WellknownRetrieverResult.Success(aWellKnown())
|
||||
"https://test.com" -> WellknownRetrieverResult.NotFound
|
||||
"https://test.io" -> WellknownRetrieverResult.Success(aWellKnown())
|
||||
"https://test" -> WellknownRetrieverResult.NotFound
|
||||
"https://test.org" -> Result.success(true)
|
||||
"https://test.com" -> Result.success(false)
|
||||
"https://test.io" -> Result.success(true)
|
||||
"https://test" -> Result.success(false)
|
||||
else -> error("should not happen")
|
||||
}
|
||||
}
|
||||
val fakeWellknownRetriever = FakeWellknownRetriever(
|
||||
getWellKnownResult = getWellKnownResult,
|
||||
)
|
||||
val fakeLoginCompatibilityChecker = FakeHomeServerLoginCompatibilityChecker(checkResult = checkResult)
|
||||
val presenter = SearchAccountProviderPresenter(
|
||||
homeserverResolver = HomeserverResolver(testCoroutineDispatchers(), fakeWellknownRetriever),
|
||||
homeserverResolver = HomeserverResolver(testCoroutineDispatchers(), fakeLoginCompatibilityChecker),
|
||||
changeServerPresenter = { aChangeServerState() }
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
|
|
@ -179,7 +171,7 @@ class SearchAccountProviderPresenterTest {
|
|||
)
|
||||
)
|
||||
)
|
||||
getWellKnownResult.assertions().isCalledExactly(4)
|
||||
checkResult.assertions().isCalledExactly(4)
|
||||
.withSequence(
|
||||
listOf(value("https://test.org")),
|
||||
listOf(value("https://test.com")),
|
||||
|
|
@ -188,15 +180,4 @@ class SearchAccountProviderPresenterTest {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun aWellKnown(): WellKnown {
|
||||
return WellKnown(
|
||||
homeServer = WellKnownBaseConfig(
|
||||
baseURL = A_HOMESERVER_URL
|
||||
),
|
||||
identityServer = WellKnownBaseConfig(
|
||||
baseURL = A_HOMESERVER_URL
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ interface MessagesEntryPoint : FeatureEntryPoint {
|
|||
fun navigateToRoomDetails()
|
||||
fun navigateToRoomMemberDetails(userId: UserId)
|
||||
fun handlePermalinkClick(data: PermalinkData, pushToBackstack: Boolean)
|
||||
fun forwardEvent(eventId: EventId)
|
||||
fun forwardEvent(eventId: EventId, fromPinnedEvents: Boolean)
|
||||
fun navigateToRoom(roomId: RoomId)
|
||||
}
|
||||
|
||||
|
|
@ -47,8 +47,8 @@ interface MessagesEntryPoint : FeatureEntryPoint {
|
|||
params: Params,
|
||||
callback: Callback,
|
||||
): Node
|
||||
}
|
||||
|
||||
interface MessagesEntryPointNode {
|
||||
suspend fun attachThread(threadId: ThreadId, focusedEventId: EventId?)
|
||||
interface NodeProxy {
|
||||
suspend fun attachThread(threadId: ThreadId, focusedEventId: EventId?)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.messages.api.pinned
|
||||
|
||||
import io.element.android.libraries.matrix.api.timeline.TimelineProvider
|
||||
|
||||
interface PinnedEventsTimelineProvider : TimelineProvider
|
||||
|
|
@ -32,10 +32,9 @@ import io.element.android.features.location.api.LocationService
|
|||
import io.element.android.features.location.api.SendLocationEntryPoint
|
||||
import io.element.android.features.location.api.ShowLocationEntryPoint
|
||||
import io.element.android.features.messages.api.MessagesEntryPoint
|
||||
import io.element.android.features.messages.api.MessagesEntryPointNode
|
||||
import io.element.android.features.messages.impl.attachments.Attachment
|
||||
import io.element.android.features.messages.impl.attachments.preview.AttachmentsPreviewNode
|
||||
import io.element.android.features.messages.impl.pinned.PinnedEventsTimelineProvider
|
||||
import io.element.android.features.messages.impl.pinned.DefaultPinnedEventsTimelineProvider
|
||||
import io.element.android.features.messages.impl.pinned.list.PinnedMessagesListNode
|
||||
import io.element.android.features.messages.impl.report.ReportMessageNode
|
||||
import io.element.android.features.messages.impl.threads.ThreadedMessagesNode
|
||||
|
|
@ -115,7 +114,7 @@ class MessagesFlowNode(
|
|||
private val roomNamesCache: RoomNamesCache,
|
||||
private val mentionSpanUpdater: MentionSpanUpdater,
|
||||
private val mentionSpanTheme: MentionSpanTheme,
|
||||
private val pinnedEventsTimelineProvider: PinnedEventsTimelineProvider,
|
||||
private val pinnedEventsTimelineProvider: DefaultPinnedEventsTimelineProvider,
|
||||
private val timelineController: TimelineController,
|
||||
private val knockRequestsListEntryPoint: KnockRequestsListEntryPoint,
|
||||
private val dateFormatter: DateFormatter,
|
||||
|
|
@ -130,8 +129,7 @@ class MessagesFlowNode(
|
|||
),
|
||||
buildContext = buildContext,
|
||||
plugins = plugins,
|
||||
),
|
||||
MessagesEntryPointNode {
|
||||
), MessagesEntryPoint.NodeProxy {
|
||||
sealed interface NavTarget : Parcelable {
|
||||
@Parcelize
|
||||
data class Messages(val focusedEventId: EventId?) : NavTarget
|
||||
|
|
@ -315,9 +313,9 @@ class MessagesFlowNode(
|
|||
this@MessagesFlowNode.viewInTimeline(eventId)
|
||||
}
|
||||
|
||||
override fun forwardEvent(eventId: EventId) {
|
||||
override fun forwardEvent(eventId: EventId, fromPinnedEvents: Boolean) {
|
||||
// Need to go to the parent because of the overlay
|
||||
callback.forwardEvent(eventId)
|
||||
callback.forwardEvent(eventId, fromPinnedEvents)
|
||||
}
|
||||
}
|
||||
mediaViewerEntryPoint.createNode(
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ class DefaultActionListPresenter(
|
|||
|
||||
return ActionListState(
|
||||
target = target.value,
|
||||
eventSink = { handleEvents(it) }
|
||||
eventSink = ::handleEvents,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ class DefaultMediaOptimizationSelectorPresenter(
|
|||
selectedVideoPreset = selectedVideoOptimizationPreset.dataOrNull(),
|
||||
displayMediaSelectorViews = displayMediaSelectorViews,
|
||||
displayVideoPresetSelectorDialog = displayVideoPresetSelectorDialog,
|
||||
eventSink = { handleEvent(it) },
|
||||
eventSink = ::handleEvent,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -382,7 +382,7 @@ class MessageComposerPresenter(
|
|||
suggestions = suggestions.toImmutableList(),
|
||||
resolveMentionDisplay = resolveMentionDisplay,
|
||||
resolveAtRoomMentionDisplay = resolveAtRoomMentionDisplay,
|
||||
eventSink = { handleEvents(it) },
|
||||
eventSink = ::handleEvents,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@
|
|||
|
||||
package io.element.android.features.messages.impl.pinned
|
||||
|
||||
import dev.zacsweers.metro.Inject
|
||||
import dev.zacsweers.metro.ContributesBinding
|
||||
import dev.zacsweers.metro.SingleIn
|
||||
import io.element.android.features.messages.api.pinned.PinnedEventsTimelineProvider
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.libraries.core.coroutine.mapState
|
||||
|
|
@ -17,7 +18,6 @@ import io.element.android.libraries.matrix.api.room.CreateTimelineParams
|
|||
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
||||
import io.element.android.libraries.matrix.api.sync.SyncService
|
||||
import io.element.android.libraries.matrix.api.timeline.Timeline
|
||||
import io.element.android.libraries.matrix.api.timeline.TimelineProvider
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
|
@ -29,12 +29,12 @@ import kotlinx.coroutines.flow.onEach
|
|||
import kotlinx.coroutines.withContext
|
||||
|
||||
@SingleIn(RoomScope::class)
|
||||
@Inject
|
||||
class PinnedEventsTimelineProvider(
|
||||
@ContributesBinding(RoomScope::class)
|
||||
class DefaultPinnedEventsTimelineProvider(
|
||||
private val room: JoinedRoom,
|
||||
private val syncService: SyncService,
|
||||
private val dispatchers: CoroutineDispatchers,
|
||||
) : TimelineProvider {
|
||||
) : PinnedEventsTimelineProvider {
|
||||
private val _timelineStateFlow: MutableStateFlow<AsyncData<Timeline>> =
|
||||
MutableStateFlow(AsyncData.Uninitialized)
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ import androidx.compose.runtime.rememberUpdatedState
|
|||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import dev.zacsweers.metro.Inject
|
||||
import io.element.android.features.messages.impl.pinned.PinnedEventsTimelineProvider
|
||||
import io.element.android.features.messages.impl.pinned.DefaultPinnedEventsTimelineProvider
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
import io.element.android.libraries.matrix.api.room.BaseRoom
|
||||
|
|
@ -35,7 +35,7 @@ import kotlinx.coroutines.flow.onEach
|
|||
class PinnedMessagesBannerPresenter(
|
||||
private val room: BaseRoom,
|
||||
private val itemFactory: PinnedMessagesBannerItemFactory,
|
||||
private val pinnedEventsTimelineProvider: PinnedEventsTimelineProvider,
|
||||
private val pinnedEventsTimelineProvider: DefaultPinnedEventsTimelineProvider,
|
||||
) : Presenter<PinnedMessagesBannerState> {
|
||||
private val pinnedItems = mutableStateOf<AsyncData<ImmutableList<PinnedMessagesBannerItem>>>(AsyncData.Uninitialized)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import io.element.android.features.messages.impl.UserEventPermissions
|
|||
import io.element.android.features.messages.impl.actionlist.ActionListState
|
||||
import io.element.android.features.messages.impl.actionlist.model.TimelineItemAction
|
||||
import io.element.android.features.messages.impl.link.LinkState
|
||||
import io.element.android.features.messages.impl.pinned.PinnedEventsTimelineProvider
|
||||
import io.element.android.features.messages.impl.pinned.DefaultPinnedEventsTimelineProvider
|
||||
import io.element.android.features.messages.impl.timeline.TimelineRoomInfo
|
||||
import io.element.android.features.messages.impl.timeline.factories.TimelineItemsFactory
|
||||
import io.element.android.features.messages.impl.timeline.factories.TimelineItemsFactoryConfig
|
||||
|
|
@ -66,7 +66,7 @@ class PinnedMessagesListPresenter(
|
|||
@Assisted private val navigator: PinnedMessagesListNavigator,
|
||||
private val room: JoinedRoom,
|
||||
timelineItemsFactoryCreator: TimelineItemsFactory.Creator,
|
||||
private val timelineProvider: PinnedEventsTimelineProvider,
|
||||
private val timelineProvider: DefaultPinnedEventsTimelineProvider,
|
||||
private val timelineProtectionPresenter: Presenter<TimelineProtectionState>,
|
||||
private val linkPresenter: Presenter<LinkState>,
|
||||
private val snackbarDispatcher: SnackbarDispatcher,
|
||||
|
|
|
|||
|
|
@ -289,7 +289,7 @@ class TimelinePresenter(
|
|||
messageShield = messageShield.value,
|
||||
resolveVerifiedUserSendFailureState = resolveVerifiedUserSendFailureState,
|
||||
displayThreadSummaries = displayThreadSummaries,
|
||||
eventSink = { handleEvents(it) }
|
||||
eventSink = ::handleEvents,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class CustomReactionPresenter(
|
|||
target = target.value,
|
||||
selectedEmoji = selectedEmoji,
|
||||
recentEmojis = recentEmojis,
|
||||
eventSink = { handleEvents(it) }
|
||||
eventSink = ::handleEvents,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class ReactionSummaryPresenter(
|
|||
}
|
||||
return ReactionSummaryState(
|
||||
target = targetWithAvatars.value,
|
||||
eventSink = { handleEvents(it) }
|
||||
eventSink = ::handleEvents,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class ReadReceiptBottomSheetPresenter : Presenter<ReadReceiptBottomSheetState> {
|
|||
|
||||
return ReadReceiptBottomSheetState(
|
||||
selectedEvent = selectedEvent,
|
||||
eventSink = { handleEvent(it) },
|
||||
eventSink = ::handleEvent,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class TimelineProtectionPresenter(
|
|||
|
||||
return TimelineProtectionState(
|
||||
protectionState = protectionState,
|
||||
eventSink = { event -> handleEvent(event) }
|
||||
eventSink = ::handleEvent,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class DefaultMessagesEntryPointTest {
|
|||
override fun navigateToRoomDetails() = lambdaError()
|
||||
override fun navigateToRoomMemberDetails(userId: UserId) = lambdaError()
|
||||
override fun handlePermalinkClick(data: PermalinkData, pushToBackstack: Boolean) = lambdaError()
|
||||
override fun forwardEvent(eventId: EventId) = lambdaError()
|
||||
override fun forwardEvent(eventId: EventId, fromPinnedEvents: Boolean) = lambdaError()
|
||||
override fun navigateToRoom(roomId: RoomId) = lambdaError()
|
||||
}
|
||||
val initialTarget = MessagesEntryPoint.InitialTarget.Messages(focusedEventId = AN_EVENT_ID)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
package io.element.android.features.messages.impl.pinned.banner
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.features.messages.impl.pinned.PinnedEventsTimelineProvider
|
||||
import io.element.android.features.messages.impl.pinned.DefaultPinnedEventsTimelineProvider
|
||||
import io.element.android.libraries.eventformatter.test.FakePinnedMessagesBannerFormatter
|
||||
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
||||
import io.element.android.libraries.matrix.api.sync.SyncService
|
||||
|
|
@ -195,7 +195,7 @@ class PinnedMessagesBannerPresenterTest {
|
|||
internal fun TestScope.createPinnedEventsTimelineProvider(
|
||||
room: JoinedRoom = FakeJoinedRoom(),
|
||||
syncService: SyncService = FakeSyncService(),
|
||||
) = PinnedEventsTimelineProvider(
|
||||
) = DefaultPinnedEventsTimelineProvider(
|
||||
room = room,
|
||||
syncService = syncService,
|
||||
dispatchers = testCoroutineDispatchers(),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import io.element.android.features.messages.impl.actionlist.anActionListState
|
|||
import io.element.android.features.messages.impl.actionlist.model.TimelineItemAction
|
||||
import io.element.android.features.messages.impl.fixtures.aTimelineItemsFactoryCreator
|
||||
import io.element.android.features.messages.impl.link.aLinkState
|
||||
import io.element.android.features.messages.impl.pinned.PinnedEventsTimelineProvider
|
||||
import io.element.android.features.messages.impl.pinned.DefaultPinnedEventsTimelineProvider
|
||||
import io.element.android.features.messages.impl.timeline.model.TimelineItem
|
||||
import io.element.android.features.messages.impl.timeline.protection.aTimelineProtectionState
|
||||
import io.element.android.libraries.designsystem.utils.snackbar.SnackbarDispatcher
|
||||
|
|
@ -300,7 +300,7 @@ class PinnedMessagesListPresenterTest {
|
|||
analyticsService: AnalyticsService = FakeAnalyticsService(),
|
||||
featureFlagService: FakeFeatureFlagService = FakeFeatureFlagService(),
|
||||
): PinnedMessagesListPresenter {
|
||||
val timelineProvider = PinnedEventsTimelineProvider(
|
||||
val timelineProvider = DefaultPinnedEventsTimelineProvider(
|
||||
room = room,
|
||||
syncService = syncService,
|
||||
dispatchers = testCoroutineDispatchers(),
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ class EditUserProfilePresenter(
|
|||
saveButtonEnabled = canSave && saveAction.value !is AsyncAction.Loading,
|
||||
saveAction = saveAction.value,
|
||||
cameraPermissionState = cameraPermissionState,
|
||||
eventSink = { handleEvents(it) },
|
||||
eventSink = ::handleEvents,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ class DefaultBugReporter(
|
|||
}
|
||||
}
|
||||
val sessionData = sessionStore.getLatestSession()
|
||||
val numberOfAccounts = sessionStore.getAllSessions().size
|
||||
val numberOfAccounts = sessionStore.numberOfSessions()
|
||||
val deviceId = sessionData?.deviceId ?: "undefined"
|
||||
val userId = sessionData?.userId?.let { UserId(it) }
|
||||
// build the multi part request
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ class ChangeRoomPermissionsPresenter(
|
|||
hasChanges = hasChanges,
|
||||
saveAction = saveAction,
|
||||
confirmExitAction = confirmExitAction,
|
||||
eventSink = { handleEvent(it) }
|
||||
eventSink = ::handleEvent,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ class RolesAndPermissionsPresenter(
|
|||
canDemoteSelf = canDemoteSelf.value,
|
||||
changeOwnRoleAction = changeOwnRoleAction.value,
|
||||
resetPermissionsAction = resetPermissionsAction.value,
|
||||
eventSink = { handleEvent(it) },
|
||||
eventSink = ::handleEvent,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ interface RoomDetailsEntryPoint : FeatureEntryPoint {
|
|||
fun navigateToGlobalNotificationSettings()
|
||||
fun navigateToRoom(roomId: RoomId, serverNames: List<String>)
|
||||
fun handlePermalinkClick(data: PermalinkData, pushToBackstack: Boolean)
|
||||
fun startForwardEventFlow(eventId: EventId)
|
||||
fun startForwardEventFlow(eventId: EventId, fromPinnedEvents: Boolean)
|
||||
}
|
||||
|
||||
fun createNode(
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ class RoomDetailsFlowNode(
|
|||
// Cannot happen
|
||||
}
|
||||
|
||||
override fun forwardEvent(eventId: EventId) {
|
||||
override fun forwardEvent(eventId: EventId, fromPinnedEvents: Boolean) {
|
||||
// Cannot happen
|
||||
}
|
||||
}
|
||||
|
|
@ -334,8 +334,8 @@ class RoomDetailsFlowNode(
|
|||
callback.handlePermalinkClick(permalinkData, pushToBackstack = false)
|
||||
}
|
||||
|
||||
override fun forward(eventId: EventId) {
|
||||
callback.startForwardEventFlow(eventId)
|
||||
override fun forward(eventId: EventId, fromPinnedEvents: Boolean) {
|
||||
callback.startForwardEventFlow(eventId, fromPinnedEvents)
|
||||
}
|
||||
}
|
||||
mediaGalleryEntryPoint.createNode(
|
||||
|
|
@ -361,8 +361,8 @@ class RoomDetailsFlowNode(
|
|||
callback.handlePermalinkClick(data, pushToBackstack)
|
||||
}
|
||||
|
||||
override fun forwardEvent(eventId: EventId) {
|
||||
callback.startForwardEventFlow(eventId)
|
||||
override fun forwardEvent(eventId: EventId, fromPinnedEvents: Boolean) {
|
||||
callback.startForwardEventFlow(eventId, fromPinnedEvents)
|
||||
}
|
||||
|
||||
override fun navigateToRoom(roomId: RoomId) {
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ class RoomMemberListPresenter(
|
|||
isSearchActive = isSearchActive,
|
||||
canInvite = canInvite,
|
||||
moderationState = roomModerationState,
|
||||
eventSink = { handleEvents(it) },
|
||||
eventSink = ::handleEvents,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class RoomNotificationSettingsPresenter(
|
|||
setNotificationSettingAction = setNotificationSettingAction.value,
|
||||
restoreDefaultAction = restoreDefaultAction.value,
|
||||
displayMentionsOnlyDisclaimer = shouldDisplayMentionsOnlyDisclaimer,
|
||||
eventSink = { handleEvents(it) },
|
||||
eventSink = ::handleEvents,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ class DefaultRoomDetailsEntryPointTest {
|
|||
override fun navigateToGlobalNotificationSettings() = lambdaError()
|
||||
override fun navigateToRoom(roomId: RoomId, serverNames: List<String>) = lambdaError()
|
||||
override fun handlePermalinkClick(data: PermalinkData, pushToBackstack: Boolean) = lambdaError()
|
||||
override fun startForwardEventFlow(eventId: EventId) = lambdaError()
|
||||
override fun startForwardEventFlow(eventId: EventId, fromPinnedEvents: Boolean) = lambdaError()
|
||||
}
|
||||
val params = RoomDetailsEntryPoint.Params(
|
||||
initialElement = RoomDetailsEntryPoint.InitialTarget.RoomDetails,
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ class RoomMemberModerationPresenter(
|
|||
kickUserAsyncAction = kickUserAsyncAction.value,
|
||||
banUserAsyncAction = banUserAsyncAction.value,
|
||||
unbanUserAsyncAction = unbanUserAsyncAction.value,
|
||||
eventSink = { handleEvent(it) },
|
||||
eventSink = ::handleEvent,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class SharePresenter(
|
|||
|
||||
return ShareState(
|
||||
shareAction = shareActionState.value,
|
||||
eventSink = { handleEvents(it) }
|
||||
eventSink = ::handleEvents,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,9 +58,11 @@ class SignedOutPresenterTest {
|
|||
val initialState = awaitItem()
|
||||
assertThat(initialState.signedOutSession).isEqualTo(aSessionData)
|
||||
assertThat(sessionStore.getAllSessions()).isNotEmpty()
|
||||
assertThat(sessionStore.numberOfSessions()).isEqualTo(1)
|
||||
initialState.eventSink(SignedOutEvents.SignInAgain)
|
||||
assertThat(awaitItem().signedOutSession).isNull()
|
||||
assertThat(sessionStore.getAllSessions()).isEmpty()
|
||||
assertThat(sessionStore.numberOfSessions()).isEqualTo(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ interface SpaceEntryPoint : FeatureEntryPoint {
|
|||
|
||||
interface Callback : Plugin {
|
||||
fun navigateToRoom(roomId: RoomId, viaParameters: List<String>)
|
||||
fun navigateToRoomDetails()
|
||||
fun navigateToRoomMemberList()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import com.bumble.appyx.core.modality.BuildContext
|
|||
import com.bumble.appyx.core.node.Node
|
||||
import com.bumble.appyx.core.plugin.Plugin
|
||||
import com.bumble.appyx.navmodel.backstack.BackStack
|
||||
import com.bumble.appyx.navmodel.backstack.operation.pop
|
||||
import com.bumble.appyx.navmodel.backstack.operation.push
|
||||
import dev.zacsweers.metro.Assisted
|
||||
import dev.zacsweers.metro.AssistedInject
|
||||
|
|
@ -26,14 +27,15 @@ import io.element.android.features.space.api.SpaceEntryPoint
|
|||
import io.element.android.features.space.impl.di.SpaceFlowGraph
|
||||
import io.element.android.features.space.impl.leave.LeaveSpaceNode
|
||||
import io.element.android.features.space.impl.root.SpaceNode
|
||||
import io.element.android.features.space.impl.settings.SpaceSettingsNode
|
||||
import io.element.android.libraries.architecture.BackstackView
|
||||
import io.element.android.libraries.architecture.BaseFlowNode
|
||||
import io.element.android.libraries.architecture.callback
|
||||
import io.element.android.libraries.architecture.createNode
|
||||
import io.element.android.libraries.architecture.inputs
|
||||
import io.element.android.libraries.di.DependencyInjectionGraphOwner
|
||||
import io.element.android.libraries.di.RoomScope
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
||||
import io.element.android.libraries.matrix.api.spaces.SpaceService
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
|
|
@ -42,6 +44,7 @@ import kotlinx.parcelize.Parcelize
|
|||
class SpaceFlowNode(
|
||||
@Assisted val buildContext: BuildContext,
|
||||
@Assisted plugins: List<Plugin>,
|
||||
room: JoinedRoom,
|
||||
spaceService: SpaceService,
|
||||
graphFactory: SpaceFlowGraph.Factory,
|
||||
) : BaseFlowNode<SpaceFlowNode.NavTarget>(
|
||||
|
|
@ -52,15 +55,17 @@ class SpaceFlowNode(
|
|||
buildContext = buildContext,
|
||||
plugins = plugins,
|
||||
), DependencyInjectionGraphOwner {
|
||||
private val inputs: SpaceEntryPoint.Inputs = inputs()
|
||||
private val callback: SpaceEntryPoint.Callback = callback()
|
||||
private val spaceRoomList = spaceService.spaceRoomList(inputs.roomId)
|
||||
private val spaceRoomList = spaceService.spaceRoomList(room.roomId)
|
||||
override val graph = graphFactory.create(spaceRoomList)
|
||||
|
||||
sealed interface NavTarget : Parcelable {
|
||||
@Parcelize
|
||||
data object Root : NavTarget
|
||||
|
||||
@Parcelize
|
||||
data object Settings : NavTarget
|
||||
|
||||
@Parcelize
|
||||
data object Leave : NavTarget
|
||||
}
|
||||
|
|
@ -77,7 +82,16 @@ class SpaceFlowNode(
|
|||
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {
|
||||
return when (navTarget) {
|
||||
NavTarget.Leave -> {
|
||||
createNode<LeaveSpaceNode>(buildContext, listOf(inputs))
|
||||
val callback = object : LeaveSpaceNode.Callback {
|
||||
override fun closeLeaveSpaceFlow() {
|
||||
backstack.pop()
|
||||
}
|
||||
|
||||
override fun navigateToRolesAndPermissions() {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
createNode<LeaveSpaceNode>(buildContext, listOf(callback))
|
||||
}
|
||||
NavTarget.Root -> {
|
||||
val callback = object : SpaceNode.Callback {
|
||||
|
|
@ -85,8 +99,8 @@ class SpaceFlowNode(
|
|||
callback.navigateToRoom(roomId, viaParameters)
|
||||
}
|
||||
|
||||
override fun navigateToRoomDetails() {
|
||||
callback.navigateToRoomDetails()
|
||||
override fun navigateToSpaceSettings() {
|
||||
backstack.push(NavTarget.Settings)
|
||||
}
|
||||
|
||||
override fun navigateToRoomMemberList() {
|
||||
|
|
@ -97,7 +111,35 @@ class SpaceFlowNode(
|
|||
backstack.push(NavTarget.Leave)
|
||||
}
|
||||
}
|
||||
createNode<SpaceNode>(buildContext, listOf(inputs, callback))
|
||||
createNode<SpaceNode>(buildContext, listOf(callback))
|
||||
}
|
||||
NavTarget.Settings -> {
|
||||
val callback = object : SpaceSettingsNode.Callback {
|
||||
override fun closeSettings() {
|
||||
backstack.pop()
|
||||
}
|
||||
|
||||
override fun navigateToSpaceInfo() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
override fun navigateToSpaceMembers() {
|
||||
callback.navigateToRoomMemberList()
|
||||
}
|
||||
|
||||
override fun navigateToRolesAndPermissions() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
override fun navigateToSecurityAndPrivacy() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
override fun startLeaveSpaceFlow() {
|
||||
backstack.push(NavTarget.Leave)
|
||||
}
|
||||
}
|
||||
createNode<SpaceSettingsNode>(buildContext, listOf(callback))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ import com.bumble.appyx.core.plugin.Plugin
|
|||
import dev.zacsweers.metro.Assisted
|
||||
import dev.zacsweers.metro.AssistedInject
|
||||
import io.element.android.annotations.ContributesNode
|
||||
import io.element.android.features.space.api.SpaceEntryPoint
|
||||
import io.element.android.features.space.impl.di.SpaceFlowScope
|
||||
import io.element.android.libraries.architecture.inputs
|
||||
import io.element.android.libraries.architecture.callback
|
||||
import io.element.android.libraries.matrix.api.MatrixClient
|
||||
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
||||
|
||||
@ContributesNode(SpaceFlowScope::class)
|
||||
@AssistedInject
|
||||
|
|
@ -27,12 +27,19 @@ class LeaveSpaceNode(
|
|||
@Assisted buildContext: BuildContext,
|
||||
@Assisted plugins: List<Plugin>,
|
||||
matrixClient: MatrixClient,
|
||||
room: JoinedRoom,
|
||||
presenterFactory: LeaveSpacePresenter.Factory,
|
||||
) : Node(buildContext, plugins = plugins) {
|
||||
private val inputs: SpaceEntryPoint.Inputs = inputs()
|
||||
private val leaveSpaceHandle = matrixClient.spaceService.getLeaveSpaceHandle(inputs.roomId)
|
||||
interface Callback : Plugin {
|
||||
fun closeLeaveSpaceFlow()
|
||||
fun navigateToRolesAndPermissions()
|
||||
}
|
||||
|
||||
private val leaveSpaceHandle = matrixClient.spaceService.getLeaveSpaceHandle(room.roomId)
|
||||
private val presenter: LeaveSpacePresenter = presenterFactory.create(leaveSpaceHandle)
|
||||
|
||||
private val callback: Callback = callback()
|
||||
|
||||
override fun onBuilt() {
|
||||
super.onBuilt()
|
||||
lifecycle.subscribe(
|
||||
|
|
@ -47,7 +54,8 @@ class LeaveSpaceNode(
|
|||
val state = presenter.present()
|
||||
LeaveSpaceView(
|
||||
state = state,
|
||||
onCancel = ::navigateUp,
|
||||
onCancel = callback::closeLeaveSpaceFlow,
|
||||
onRolesAndPermissionsClick = callback::navigateToRolesAndPermissions,
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ import io.element.android.libraries.ui.strings.CommonStrings
|
|||
fun LeaveSpaceView(
|
||||
state: LeaveSpaceState,
|
||||
onCancel: () -> Unit,
|
||||
onRolesAndPermissionsClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
Scaffold(
|
||||
|
|
@ -130,6 +131,9 @@ fun LeaveSpaceView(
|
|||
state.eventSink(LeaveSpaceEvents.LeaveSpace)
|
||||
},
|
||||
onCancel = onCancel,
|
||||
// TODO enable when navigation is ready
|
||||
showRolesAndPermissionsButton = false, // state.isLastAdmin,
|
||||
onRolesAndPermissionsClick = onRolesAndPermissionsClick,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -210,6 +214,8 @@ private fun LeaveSpaceButtons(
|
|||
showLeaveButton: Boolean,
|
||||
selectedRoomsCount: Int,
|
||||
onLeaveSpace: () -> Unit,
|
||||
showRolesAndPermissionsButton: Boolean,
|
||||
onRolesAndPermissionsClick: () -> Unit,
|
||||
onCancel: () -> Unit,
|
||||
) {
|
||||
ButtonColumnMolecule(
|
||||
|
|
@ -229,8 +235,14 @@ private fun LeaveSpaceButtons(
|
|||
destructive = true,
|
||||
)
|
||||
}
|
||||
// TODO For least admin space, add a button to open the settings.
|
||||
// See https://www.figma.com/design/kcnHxunG1LDWXsJhaNuiHz/ER-145--Spaces-on-Element-X?node-id=4622-59600
|
||||
if (showRolesAndPermissionsButton) {
|
||||
Button(
|
||||
text = stringResource(CommonStrings.action_go_to_roles_and_permissions),
|
||||
onClick = onRolesAndPermissionsClick,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
leadingIcon = IconSource.Vector(CompoundIcons.Settings()),
|
||||
)
|
||||
}
|
||||
TextButton(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
text = stringResource(CommonStrings.action_cancel),
|
||||
|
|
@ -345,5 +357,6 @@ internal fun LeaveSpaceViewPreview(
|
|||
LeaveSpaceView(
|
||||
state = state,
|
||||
onCancel = {},
|
||||
onRolesAndPermissionsClick = {},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class SpaceNode(
|
|||
) : Node(buildContext, plugins = plugins) {
|
||||
interface Callback : Plugin {
|
||||
fun navigateToRoom(roomId: RoomId, viaParameters: List<String>)
|
||||
fun navigateToRoomDetails()
|
||||
fun navigateToSpaceSettings()
|
||||
fun navigateToRoomMemberList()
|
||||
fun startLeaveSpaceFlow()
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ class SpaceNode(
|
|||
callback.navigateToRoom(spaceRoom.roomId, spaceRoom.via)
|
||||
},
|
||||
onDetailsClick = {
|
||||
callback.navigateToRoomDetails()
|
||||
callback.navigateToSpaceSettings()
|
||||
},
|
||||
onShareSpace = {
|
||||
onShareRoom(context)
|
||||
|
|
|
|||
|
|
@ -328,7 +328,7 @@ private fun SpaceViewTopBar(
|
|||
},
|
||||
text = {
|
||||
Text(
|
||||
text = stringResource(id = CommonStrings.action_leave),
|
||||
text = stringResource(id = CommonStrings.action_leave_space),
|
||||
color = ElementTheme.colors.textCriticalPrimary,
|
||||
)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.space.impl.settings
|
||||
|
||||
sealed interface SpaceSettingsEvents
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.space.impl.settings
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.bumble.appyx.core.modality.BuildContext
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import com.bumble.appyx.core.plugin.Plugin
|
||||
import dev.zacsweers.metro.Assisted
|
||||
import dev.zacsweers.metro.AssistedInject
|
||||
import io.element.android.annotations.ContributesNode
|
||||
import io.element.android.features.space.impl.di.SpaceFlowScope
|
||||
import io.element.android.libraries.architecture.appyx.launchMolecule
|
||||
import io.element.android.libraries.architecture.callback
|
||||
|
||||
@ContributesNode(SpaceFlowScope::class)
|
||||
@AssistedInject
|
||||
class SpaceSettingsNode(
|
||||
@Assisted buildContext: BuildContext,
|
||||
@Assisted plugins: List<Plugin>,
|
||||
private val presenter: SpaceSettingsPresenter,
|
||||
) : Node(buildContext, plugins = plugins) {
|
||||
interface Callback : Plugin {
|
||||
fun closeSettings()
|
||||
|
||||
fun navigateToSpaceInfo()
|
||||
fun navigateToSpaceMembers()
|
||||
fun navigateToRolesAndPermissions()
|
||||
fun navigateToSecurityAndPrivacy()
|
||||
fun startLeaveSpaceFlow()
|
||||
}
|
||||
|
||||
private val callback: Callback = callback()
|
||||
private val stateFlow = launchMolecule { presenter.present() }
|
||||
|
||||
@Composable
|
||||
override fun View(modifier: Modifier) {
|
||||
val state by stateFlow.collectAsState()
|
||||
SpaceSettingsView(
|
||||
state = state,
|
||||
modifier = modifier,
|
||||
onSpaceInfoClick = callback::navigateToSpaceInfo,
|
||||
onBackClick = callback::closeSettings,
|
||||
onMembersClick = callback::navigateToSpaceMembers,
|
||||
onRolesAndPermissionsClick = callback::navigateToRolesAndPermissions,
|
||||
onSecurityAndPrivacyClick = callback::navigateToSecurityAndPrivacy,
|
||||
onLeaveSpaceClick = callback::startLeaveSpaceFlow,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.space.impl.settings
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import dev.zacsweers.metro.Inject
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
||||
import io.element.android.libraries.matrix.ui.room.isOwnUserAdmin
|
||||
|
||||
@Inject
|
||||
class SpaceSettingsPresenter(
|
||||
private val room: JoinedRoom,
|
||||
) : Presenter<SpaceSettingsState> {
|
||||
@Composable
|
||||
override fun present(): SpaceSettingsState {
|
||||
val roomInfo by room.roomInfoFlow.collectAsState()
|
||||
val isUserAdmin = room.isOwnUserAdmin()
|
||||
return SpaceSettingsState(
|
||||
roomId = room.roomId,
|
||||
name = roomInfo.name.orEmpty(),
|
||||
canonicalAlias = roomInfo.canonicalAlias,
|
||||
avatarUrl = roomInfo.avatarUrl,
|
||||
memberCount = roomInfo.activeMembersCount,
|
||||
showRolesAndPermissions = isUserAdmin,
|
||||
showSecurityAndPrivacy = isUserAdmin,
|
||||
eventSink = {},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.space.impl.settings
|
||||
|
||||
import io.element.android.libraries.matrix.api.core.RoomAlias
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
|
||||
data class SpaceSettingsState(
|
||||
val roomId: RoomId,
|
||||
val name: String,
|
||||
val canonicalAlias: RoomAlias?,
|
||||
val avatarUrl: String?,
|
||||
val memberCount: Long,
|
||||
val showRolesAndPermissions: Boolean,
|
||||
val showSecurityAndPrivacy: Boolean,
|
||||
val eventSink: (SpaceSettingsEvents) -> Unit
|
||||
)
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.space.impl.settings
|
||||
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import io.element.android.libraries.matrix.api.core.RoomAlias
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
|
||||
open class SpaceSettingsStateProvider : PreviewParameterProvider<SpaceSettingsState> {
|
||||
override val values: Sequence<SpaceSettingsState>
|
||||
get() = sequenceOf(
|
||||
aSpaceSettingsState(),
|
||||
aSpaceSettingsState(alias = null),
|
||||
aSpaceSettingsState(showSecurityAndPrivacy = true),
|
||||
aSpaceSettingsState(showRolesAndPermissions = true),
|
||||
)
|
||||
}
|
||||
|
||||
fun aSpaceSettingsState(
|
||||
roomId: RoomId = RoomId("!aRoomId:element.io"),
|
||||
name: String = "Space name",
|
||||
alias: RoomAlias? = RoomAlias("#spacename:element.io"),
|
||||
avatarUrl: String? = null,
|
||||
memberCount: Long = 100,
|
||||
showRolesAndPermissions: Boolean = false,
|
||||
showSecurityAndPrivacy: Boolean = false,
|
||||
eventSink: (SpaceSettingsEvents) -> Unit = {},
|
||||
) = SpaceSettingsState(
|
||||
roomId = roomId,
|
||||
name = name,
|
||||
canonicalAlias = alias,
|
||||
avatarUrl = avatarUrl,
|
||||
memberCount = memberCount,
|
||||
showRolesAndPermissions = showRolesAndPermissions,
|
||||
showSecurityAndPrivacy = showSecurityAndPrivacy,
|
||||
eventSink = eventSink,
|
||||
)
|
||||
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.space.impl.settings
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.compound.theme.ElementTheme
|
||||
import io.element.android.compound.tokens.generated.CompoundIcons
|
||||
import io.element.android.features.space.impl.R
|
||||
import io.element.android.libraries.designsystem.components.avatar.Avatar
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarType
|
||||
import io.element.android.libraries.designsystem.components.button.BackButton
|
||||
import io.element.android.libraries.designsystem.components.list.ListItemContent
|
||||
import io.element.android.libraries.designsystem.components.preferences.PreferenceCategory
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||
import io.element.android.libraries.designsystem.theme.components.IconSource
|
||||
import io.element.android.libraries.designsystem.theme.components.ListItem
|
||||
import io.element.android.libraries.designsystem.theme.components.ListItemStyle
|
||||
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
||||
import io.element.android.libraries.designsystem.theme.components.Text
|
||||
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
|
||||
@Composable
|
||||
fun SpaceSettingsView(
|
||||
state: SpaceSettingsState,
|
||||
onBackClick: () -> Unit,
|
||||
onSpaceInfoClick: () -> Unit,
|
||||
onMembersClick: () -> Unit,
|
||||
onRolesAndPermissionsClick: () -> Unit,
|
||||
onSecurityAndPrivacyClick: () -> Unit,
|
||||
onLeaveSpaceClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
Scaffold(
|
||||
modifier = modifier,
|
||||
topBar = {
|
||||
SpaceSettingsTopBar(onBackClick = onBackClick)
|
||||
},
|
||||
) { padding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(padding)
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
SpaceInfoSection(
|
||||
roomId = state.roomId,
|
||||
name = state.name,
|
||||
avatarUrl = state.avatarUrl,
|
||||
canonicalAlias = state.canonicalAlias?.value,
|
||||
onSpaceInfoClick = onSpaceInfoClick,
|
||||
)
|
||||
Section(isVisible = state.showSecurityAndPrivacy, content = {
|
||||
SecurityAndPrivacyItem(
|
||||
onClick = onSecurityAndPrivacyClick
|
||||
)
|
||||
})
|
||||
Section(content = {
|
||||
MembersItem(state.memberCount, onClick = onMembersClick)
|
||||
if (state.showRolesAndPermissions) {
|
||||
RolesAndPermissionsItem(onClick = onRolesAndPermissionsClick)
|
||||
}
|
||||
})
|
||||
Section(content = {
|
||||
LeaveSpaceItem(
|
||||
onClick = onLeaveSpaceClick
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SpaceInfoSection(
|
||||
roomId: RoomId,
|
||||
name: String,
|
||||
avatarUrl: String?,
|
||||
canonicalAlias: String?,
|
||||
onSpaceInfoClick: () -> Unit,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable(onClick = onSpaceInfoClick)
|
||||
.padding(16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Avatar(
|
||||
avatarData = AvatarData(roomId.value, name, avatarUrl, AvatarSize.SpaceListItem),
|
||||
avatarType = AvatarType.Space(),
|
||||
contentDescription = avatarUrl?.let { stringResource(CommonStrings.a11y_avatar) },
|
||||
)
|
||||
Spacer(Modifier.width(16.dp))
|
||||
Column {
|
||||
Text(
|
||||
text = name,
|
||||
style = ElementTheme.typography.fontHeadingMdRegular,
|
||||
color = ElementTheme.colors.textPrimary,
|
||||
)
|
||||
if (canonicalAlias != null) {
|
||||
Text(
|
||||
text = canonicalAlias,
|
||||
style = ElementTheme.typography.fontBodyMdRegular,
|
||||
color = ElementTheme.colors.textSecondary,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Section(
|
||||
modifier: Modifier = Modifier,
|
||||
isVisible: Boolean = true,
|
||||
content: @Composable ColumnScope.() -> Unit,
|
||||
) {
|
||||
if (isVisible) {
|
||||
PreferenceCategory(content = content, modifier = modifier)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun SpaceSettingsTopBar(
|
||||
onBackClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
TopAppBar(
|
||||
titleStr = stringResource(CommonStrings.common_settings),
|
||||
navigationIcon = { BackButton(onClick = onBackClick) },
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SecurityAndPrivacyItem(
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
ListItem(
|
||||
headlineContent = { Text(stringResource(R.string.screen_space_settings_security_and_privacy)) },
|
||||
leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.Lock())),
|
||||
onClick = onClick,
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MembersItem(
|
||||
memberCount: Long,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
ListItem(
|
||||
headlineContent = { Text(stringResource(CommonStrings.common_people)) },
|
||||
leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.User())),
|
||||
trailingContent = ListItemContent.Text(memberCount.toString()),
|
||||
onClick = onClick,
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RolesAndPermissionsItem(
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
ListItem(
|
||||
headlineContent = { Text(stringResource(R.string.screen_space_settings_roles_and_permissions)) },
|
||||
leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.Admin())),
|
||||
onClick = onClick,
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LeaveSpaceItem(
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
ListItem(
|
||||
headlineContent = {
|
||||
Text(stringResource(CommonStrings.action_leave_space))
|
||||
},
|
||||
leadingContent = ListItemContent.Icon(IconSource.Vector(CompoundIcons.Leave())),
|
||||
style = ListItemStyle.Destructive,
|
||||
onClick = onClick,
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
|
||||
@PreviewsDayNight
|
||||
@Composable
|
||||
internal fun SpaceSettingsViewPreview(
|
||||
@PreviewParameter(SpaceSettingsStateProvider::class) state: SpaceSettingsState
|
||||
) = ElementPreview {
|
||||
SpaceSettingsView(
|
||||
state = state,
|
||||
onBackClick = {},
|
||||
onSpaceInfoClick = {},
|
||||
onMembersClick = {},
|
||||
onRolesAndPermissionsClick = {},
|
||||
onSecurityAndPrivacyClick = {},
|
||||
onLeaveSpaceClick = {},
|
||||
modifier = Modifier,
|
||||
)
|
||||
}
|
||||
|
|
@ -10,4 +10,7 @@
|
|||
<string name="screen_leave_space_subtitle_only_last_admin">"You will not be removed from the following room(s) because you\'re the only administrator:"</string>
|
||||
<string name="screen_leave_space_title">"Leave %1$s?"</string>
|
||||
<string name="screen_leave_space_title_last_admin">"You are the only admin for %1$s"</string>
|
||||
<string name="screen_space_settings_leave_space">"Leave space"</string>
|
||||
<string name="screen_space_settings_roles_and_permissions">"Roles & permissions"</string>
|
||||
<string name="screen_space_settings_security_and_privacy">"Security & privacy"</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import io.element.android.features.space.api.SpaceEntryPoint
|
|||
import io.element.android.features.space.impl.di.FakeSpaceFlowGraph
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||
import io.element.android.libraries.matrix.test.room.FakeJoinedRoom
|
||||
import io.element.android.libraries.matrix.test.spaces.FakeSpaceRoomList
|
||||
import io.element.android.libraries.matrix.test.spaces.FakeSpaceService
|
||||
import io.element.android.tests.testutils.lambda.lambdaError
|
||||
|
|
@ -40,12 +41,12 @@ class DefaultSpaceEntryPointTest {
|
|||
spaceService = FakeSpaceService(
|
||||
spaceRoomListResult = { _: RoomId -> FakeSpaceRoomList(A_ROOM_ID) }
|
||||
),
|
||||
room = FakeJoinedRoom(),
|
||||
graphFactory = FakeSpaceFlowGraph.Factory
|
||||
)
|
||||
}
|
||||
val callback = object : SpaceEntryPoint.Callback {
|
||||
override fun navigateToRoom(roomId: RoomId, viaParameters: List<String>) = lambdaError()
|
||||
override fun navigateToRoomDetails() = lambdaError()
|
||||
override fun navigateToRoomMemberList() = lambdaError()
|
||||
}
|
||||
val result = entryPoint.createNode(
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ class UserProfileFlowNode(
|
|||
// Cannot happen
|
||||
}
|
||||
|
||||
override fun forwardEvent(eventId: EventId) {
|
||||
override fun forwardEvent(eventId: EventId, fromPinnedEvents: Boolean) {
|
||||
// Cannot happen
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue