Skip to content

Commit

Permalink
feat: [RC] feature flag passowrd guest link (WPB-1531) (#2282)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandreferris authored and github-actions[bot] committed Sep 28, 2023
1 parent 0e96dfb commit 9265918
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 54 deletions.
15 changes: 15 additions & 0 deletions app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,19 @@ class UseCaseModule {
@KaliumCoreLogic coreLogic: CoreLogic,
@CurrentAccount currentAccount: UserId
): ObserveScreenshotCensoringConfigUseCase = coreLogic.getSessionScope(currentAccount).observeScreenshotCensoringConfig

@ViewModelScoped
@Provides
fun provideGetConversationVerificationStatusUseCase(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) =
coreLogic.getSessionScope(currentAccount).getConversationVerificationStatus

@ViewModelScoped
@Provides
fun providesJoinConversationViaCodeUseCase(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) =
coreLogic.getSessionScope(currentAccount).conversations.joinConversationViaCode

@ViewModelScoped
@Provides
fun providesCanCreatePasswordProtectedLinksUseCase(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) =
coreLogic.getSessionScope(currentAccount).conversations.canCreatePasswordProtectedLinks
}
252 changes: 205 additions & 47 deletions app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class WireActivity : AppCompatActivity() {
ReportDrawnWhen { isLoaded }
val navigator = rememberNavigator(this@WireActivity::finish)
val scope = rememberCoroutineScope()

CommonTopAppBar(
connectivityUIState = commonTopAppBarViewModel.connectivityState,
onReturnToCallClick = { establishedCall ->
Expand Down Expand Up @@ -231,57 +232,14 @@ class WireActivity : AppCompatActivity() {

@Composable
private fun handleDialogs(navigate: (NavigationCommand) -> Unit) {
featureFlagNotificationViewModel.loadInitialSync()
with(featureFlagNotificationViewModel.featureFlagState) {
if (showFileSharingDialog) {
FileRestrictionDialog(
isFileSharingEnabled = isFileSharingEnabledState,
hideDialogStatus = featureFlagNotificationViewModel::dismissFileSharingDialog
)
}

if (shouldShowGuestRoomLinkDialog) {
GuestRoomLinkFeatureFlagDialog(
isGuestRoomLinkEnabled = isGuestRoomLinkEnabled,
onDismiss = featureFlagNotificationViewModel::dismissGuestRoomLinkDialog
)
}

if (shouldShowSelfDeletingMessagesDialog) {
SelfDeletingMessagesDialog(
areSelfDeletingMessagesEnabled = areSelfDeletedMessagesEnabled,
enforcedTimeout = enforcedTimeoutDuration,
hideDialogStatus = featureFlagNotificationViewModel::dismissSelfDeletingMessagesDialog
)
}

e2EIRequired?.let {
E2EIRequiredDialog(
result = e2EIRequired,
getCertificate = featureFlagNotificationViewModel::getE2EICertificate,
snoozeDialog = featureFlagNotificationViewModel::snoozeE2EIdRequiredDialog
)
}

e2EISnoozeInfo?.let {
E2EISnoozeDialog(
timeLeft = e2EISnoozeInfo.timeLeft,
dismissDialog = featureFlagNotificationViewModel::dismissSnoozeE2EIdRequiredDialog
)
}
}
UpdateAppDialog(viewModel.globalAppState.updateAppDialog, ::updateTheApp)
JoinConversationDialog(
updateAppDialog({ updateTheApp() }, viewModel.globalAppState.updateAppDialog)
joinConversationDialog(
viewModel.globalAppState.conversationJoinedDialog,
navigate,
viewModel::onJoinConversationFlowCompleted
)
CustomBackendDialog(
viewModel.globalAppState,
viewModel::dismissCustomBackendDialog
) { viewModel.customBackendDialogProceedButtonClicked { navigate(NavigationCommand(WelcomeScreenDestination)) } }
MaxAccountDialog(
shouldShow = viewModel.globalAppState.maxAccountDialog,
customBackendDialog(navigate)
maxAccountDialog(
onConfirm = {
viewModel.dismissMaxAccountDialog()
navigate(NavigationCommand(SelfUserProfileScreenDestination))
Expand All @@ -304,6 +262,206 @@ class WireActivity : AppCompatActivity() {
)
}

@Composable
private fun updateAppDialog(onUpdateClick: () -> Unit, shouldShow: Boolean) {
if (shouldShow) {
WireDialog(
title = stringResource(id = R.string.update_app_dialog_title),
text = stringResource(id = R.string.update_app_dialog_body),
onDismiss = { },
optionButton1Properties = WireDialogButtonProperties(
text = stringResource(id = R.string.update_app_dialog_button),
onClick = onUpdateClick,
type = WireDialogButtonType.Primary
),
properties = wireDialogPropertiesBuilder(
dismissOnBackPress = false,
dismissOnClickOutside = false,
usePlatformDefaultWidth = true
)
)
}
}

@Composable
private fun joinConversationDialog(
joinedDialogState: JoinConversationViaCodeState?,
navigate: (NavigationCommand) -> Unit,
onJoinConversationFlowCompleted: () -> Unit
) {
joinedDialogState?.let {

val onComplete: (convId: ConversationId?) -> Unit = remember {
{
onJoinConversationFlowCompleted()
it?.also {
appLogger.d("Join conversation via code dialog completed, navigating to conversation screen")
navigate(
NavigationCommand(
ConversationScreenDestination(it),
BackStackMode.CLEAR_TILL_START
)
)
}
}
}

when (it) {
is JoinConversationViaCodeState.Error -> JoinConversationViaInviteLinkError(
errorState = it,
onCancel = { onComplete(null) }
)

is JoinConversationViaCodeState.Show -> {
JoinConversationViaDeepLinkDialog(
name = it.conversationName,
code = it.code,
domain = it.domain,
key = it.key,
requirePassword = it.passwordProtected,
onFlowCompleted = onComplete
)
}
}
}
}

@Composable
private fun customBackendDialog(navigate: (NavigationCommand) -> Unit) {
with(viewModel) {
if (globalAppState.customBackendDialog != null) {
CustomServerDialog(
serverLinksTitle = globalAppState.customBackendDialog!!.serverLinks.title,
serverLinksApi = globalAppState.customBackendDialog!!.serverLinks.api,
onDismiss = this::dismissCustomBackendDialog,
onConfirm = { customBackendDialogProceedButtonClicked { navigate(NavigationCommand(WelcomeScreenDestination)) } }
)
}
}
}

@Composable
private fun maxAccountDialog(onConfirm: () -> Unit, onDismiss: () -> Unit, shouldShow: Boolean) {
if (shouldShow) {
MaxAccountReachedDialog(
onConfirm = onConfirm,
onDismiss = onDismiss,
buttonText = R.string.max_account_reached_dialog_button_open_profile
)
}
}

@Composable
private fun accountLoggedOutDialog(blockUserUI: CurrentSessionErrorState?, navigate: (NavigationCommand) -> Unit) {
blockUserUI?.let {
accountLoggedOutDialog(reason = it) { viewModel.tryToSwitchAccount(NavigationSwitchAccountActions(navigate)) }
}
}

@Composable
fun accountLoggedOutDialog(reason: CurrentSessionErrorState, navigateAway: () -> Unit) {
appLogger.e("AccountLongedOutDialog: $reason")
val (@StringRes title: Int, text: String) = when (reason) {
CurrentSessionErrorState.SessionExpired -> {
if (BuildConfig.WIPE_ON_COOKIE_INVALID) {
R.string.session_expired_error_title to (
stringResource(id = R.string.session_expired_error_message)
+ "\n\n"
+ stringResource(id = R.string.conversation_history_wipe_explanation)
)
} else {
R.string.session_expired_error_title to stringResource(id = R.string.session_expired_error_message)
}
}

CurrentSessionErrorState.RemovedClient -> {
if (BuildConfig.WIPE_ON_DEVICE_REMOVAL) {
R.string.removed_client_error_title to (
stringResource(id = R.string.removed_client_error_message)
+ "\n\n"
+ stringResource(id = R.string.conversation_history_wipe_explanation)
)
} else {
R.string.removed_client_error_title to stringResource(R.string.removed_client_error_message)
}
}

CurrentSessionErrorState.DeletedAccount -> {
R.string.deleted_user_error_title to stringResource(R.string.deleted_user_error_message)
}
}
WireDialog(
title = stringResource(id = title),
text = text,
onDismiss = remember { { } },
optionButton1Properties = WireDialogButtonProperties(
text = stringResource(R.string.label_ok),
onClick = navigateAway,
type = WireDialogButtonType.Primary
)
)
}

@Composable
private fun newClientDialog(
data: NewClientsData?,
openDeviceManager: () -> Unit,
switchAccountAndOpenDeviceManager: (UserId) -> Unit,
dismiss: (UserId) -> Unit
) {
data?.let {
val title: String
val text: String
val btnText: String
val btnAction: () -> Unit
val dismissAction: () -> Unit = { dismiss(data.userId) }
val devicesList = data.clientsInfo.map {
stringResource(
R.string.new_device_dialog_message_defice_info,
it.date.formatMediumDateTime() ?: "",
it.deviceInfo.asString()
)
}.joinToString("")
when (data) {
is NewClientsData.OtherUser -> {
title = stringResource(
R.string.new_device_dialog_other_user_title,
data.userName ?: "",
data.userHandle ?: ""
)
text = stringResource(R.string.new_device_dialog_other_user_message, devicesList)
btnText = stringResource(R.string.new_device_dialog_other_user_btn)
btnAction = { switchAccountAndOpenDeviceManager(data.userId) }
}

is NewClientsData.CurrentUser -> {
title = stringResource(R.string.new_device_dialog_current_user_title)
text = stringResource(R.string.new_device_dialog_current_user_message, devicesList)
btnText = stringResource(R.string.new_device_dialog_current_user_btn)
btnAction = openDeviceManager
}
}
WireDialog(
title = title,
text = text,
onDismiss = dismissAction,
optionButton1Properties = WireDialogButtonProperties(
onClick = {
dismissAction()
btnAction()
},
text = btnText,
type = WireDialogButtonType.Secondary
),
optionButton2Properties = WireDialogButtonProperties(
text = stringResource(id = R.string.label_ok),
onClick = dismissAction,
type = WireDialogButtonType.Primary
)
)
}
}

private fun updateTheApp() {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(BuildConfig.UPDATE_APP_URL))
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
Expand Down
76 changes: 76 additions & 0 deletions app/src/main/kotlin/com/wire/android/ui/home/HomeDialogs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,82 @@ import com.wire.android.ui.theme.WireTheme
import com.wire.android.util.CustomTabsHelper
import com.wire.android.util.ui.PreviewMultipleThemes

@Composable
fun FileRestrictionDialog(
isFileSharingEnabled: Boolean,
hideDialogStatus: () -> Unit,
) {
val text: String =
stringResource(id = if (isFileSharingEnabled) R.string.sharing_files_enabled else R.string.sharing_files_disabled)

WireDialog(
title = stringResource(id = R.string.team_settings_changed),
text = text,
onDismiss = hideDialogStatus,
optionButton1Properties = WireDialogButtonProperties(
onClick = hideDialogStatus,
text = stringResource(id = R.string.label_ok),
type = WireDialogButtonType.Primary,
)
)
}

@Composable
fun SelfDeletingMessagesDialog(
areSelfDeletingMessagesEnabled: Boolean,
enforcedTimeout: SelfDeletionDuration,
hideDialogStatus: () -> Unit,
) {
val formattedTimeout = enforcedTimeout.longLabel.asString()
val text: String = when {
areSelfDeletingMessagesEnabled && enforcedTimeout == SelfDeletionDuration.None -> {
stringResource(id = R.string.self_deleting_messages_team_setting_enabled)
}

areSelfDeletingMessagesEnabled -> {
stringResource(
R.string.self_deleting_messages_team_setting_enabled_enforced_timeout,
formattedTimeout
)
}

else -> {
stringResource(id = R.string.self_deleting_messages_team_setting_disabled)
}
}

WireDialog(
title = stringResource(id = R.string.team_settings_changed),
text = text,
onDismiss = hideDialogStatus,
optionButton1Properties = WireDialogButtonProperties(
onClick = hideDialogStatus,
text = stringResource(id = R.string.label_ok),
type = WireDialogButtonType.Primary,
)
)
}

@Composable
fun GuestRoomLinkFeatureFlagDialog(
isGuestRoomLinkEnabled: Boolean,
onDismiss: () -> Unit,
) {
val text: String =
stringResource(id = if (isGuestRoomLinkEnabled) R.string.guest_room_link_enabled else R.string.guest_room_link_disabled)

WireDialog(
title = stringResource(id = R.string.team_settings_changed),
text = text,
onDismiss = onDismiss,
optionButton1Properties = WireDialogButtonProperties(
onClick = onDismiss,
text = stringResource(id = R.string.label_ok),
type = WireDialogButtonType.Primary,
)
)
}

@Composable
fun WelcomeNewUserDialog(
dismissDialog: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ fun EditGuestAccessScreen(
CreateGuestLinkBottomSheet(
sheetState = sheetState,
onSheetItemClick,
isPasswordInviteLinksAllowed = editGuestAccessViewModel.editGuestAccessState.isPasswordProtectedLinksAllowed
isPasswordInviteLinksAllowed = editGuestAccessViewModel
.editGuestAccessState
.isPasswordProtectedLinksAllowed
)

WireScaffold(topBar = {
Expand Down

0 comments on commit 9265918

Please sign in to comment.