Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Custom server no network dialog #WPB-11627 #3543

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,14 @@ class WireActivity : AppCompatActivity() {
)
CustomBackendDialog(
viewModel.globalAppState,
viewModel::dismissCustomBackendDialog
) {
viewModel.customBackendDialogProceedButtonClicked {
navigate(
NavigationCommand(
WelcomeScreenDestination
)
)
}
}
viewModel::dismissCustomBackendDialog,
onConfirm = {
viewModel.customBackendDialogProceedButtonClicked {
navigate(NavigationCommand(WelcomeScreenDestination))
}
},
onTryAgain = viewModel::onCustomServerConfig
)
MaxAccountDialog(
shouldShow = viewModel.globalAppState.maxAccountDialog,
onConfirm = {
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/kotlin/com/wire/android/ui/WireActivityDialogs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import com.wire.android.ui.common.dialogs.CustomServerDetailsDialog
import com.wire.android.ui.common.dialogs.CustomServerDetailsDialogState
import com.wire.android.ui.common.dialogs.CustomServerInvalidJsonDialog
import com.wire.android.ui.common.dialogs.CustomServerInvalidJsonDialogState
import com.wire.android.ui.common.dialogs.CustomServerNoNetworkDialog
import com.wire.android.ui.common.dialogs.CustomServerNoNetworkDialogState
import com.wire.android.ui.common.dialogs.MaxAccountAllowedDialogContent
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.common.wireDialogPropertiesBuilder
Expand Down Expand Up @@ -244,7 +246,8 @@ fun JoinConversationDialog(
fun CustomBackendDialog(
globalAppState: GlobalAppState,
onDismiss: () -> Unit,
onConfirm: () -> Unit
onConfirm: () -> Unit,
onTryAgain: (String) -> Unit
) {
when (globalAppState.customBackendDialog) {
is CustomServerDetailsDialogState -> {
Expand All @@ -261,6 +264,13 @@ fun CustomBackendDialog(
)
}

is CustomServerNoNetworkDialogState -> {
CustomServerNoNetworkDialog(
onTryAgain = { onTryAgain(globalAppState.customBackendDialog.customServerUrl) },
onDismiss = onDismiss
)
}

else -> {
// nop
}
Expand Down Expand Up @@ -581,6 +591,7 @@ fun PreviewCustomBackendDialog() {
)
),
{},
{},
{}
)
}
Expand Down
30 changes: 21 additions & 9 deletions app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.wire.android.ui.authentication.devices.model.displayName
import com.wire.android.ui.common.dialogs.CustomServerDetailsDialogState
import com.wire.android.ui.common.dialogs.CustomServerDialogState
import com.wire.android.ui.common.dialogs.CustomServerInvalidJsonDialogState
import com.wire.android.ui.common.dialogs.CustomServerNoNetworkDialogState
import com.wire.android.ui.joinConversation.JoinConversationViaCodeState
import com.wire.android.ui.theme.ThemeOption
import com.wire.android.util.CurrentScreen
Expand Down Expand Up @@ -77,6 +78,8 @@ import com.wire.kalium.logic.feature.session.GetAllSessionsResult
import com.wire.kalium.logic.feature.session.GetSessionsUseCase
import com.wire.kalium.logic.feature.user.screenshotCensoring.ObserveScreenshotCensoringConfigResult
import com.wire.kalium.logic.feature.user.webSocketStatus.ObservePersistentWebSocketConnectionStatusUseCase
import com.wire.kalium.network.NetworkState
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.util.DateTimeUtil.toIsoDateTimeString
import dagger.Lazy
import dagger.hilt.android.lifecycle.HiltViewModel
Expand Down Expand Up @@ -122,7 +125,8 @@ class WireActivityViewModel @Inject constructor(
private val observeScreenshotCensoringConfigUseCaseProviderFactory: ObserveScreenshotCensoringConfigUseCaseProvider.Factory,
private val globalDataStore: Lazy<GlobalDataStore>,
private val observeIfE2EIRequiredDuringLoginUseCaseProviderFactory: ObserveIfE2EIRequiredDuringLoginUseCaseProvider.Factory,
private val workManager: Lazy<WorkManager>
private val workManager: Lazy<WorkManager>,
private val networkStateObserver: Lazy<NetworkStateObserver>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is over kill you don't need to check the network state, we can do the request to get the json with custom server meta data and check the error returned it is a network error with something list Io Exception then display this error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is unfortunately not doable:

  • When we dont have internet connection and the config is valid we're getting:
    GenericError(cause=java.net.UnknownHostException: Unable to resolve host "nginz-https.bund-next-column-offline-android.wire.link": No address associated with hostname)

  • When we have internet connection and the config is invalid we're getting:
    GenericError(cause=java.net.UnknownHostException: Unable to resolve host "nginz-https.unreachable.wire.link": No address associated with hostname)

So we're unable to know if the config was wrong or not with the exception we're getting

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could slightly change the copy and use this dialog in both cases?
Like: "You don't seem to be connected to the Internet or the config link you used is broken. Please check your Internet connection and try again." 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well yeah we could have only one for malformed json and no internet connection :D that'd solve the issue too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we dont have internet connection and the config is valid we're getting:
GenericError(cause=java.net.UnknownHostException: Unable to resolve host "nginz-https.bund-next-column-offline-android.wire.link": No address associated with hostname)

I feel like i am missing something?
this will never happen how was the app able to know that the constant is valid if we are not able to read the content, since there is no internet?

) : ViewModel() {

var globalAppState: GlobalAppState by mutableStateOf(GlobalAppState())
Expand Down Expand Up @@ -356,7 +360,7 @@ class WireActivityViewModel @Inject constructor(
when (val result = deepLinkProcessor.get().invoke(intent?.data, isSharingIntent)) {
DeepLinkResult.AuthorizationNeeded -> onAuthorizationNeeded()
is DeepLinkResult.SSOLogin -> onSSOLogin(result)
is DeepLinkResult.CustomServerConfig -> onCustomServerConfig(result)
is DeepLinkResult.CustomServerConfig -> onCustomServerConfig(result.url)
is DeepLinkResult.Failure.OngoingCall -> onCannotLoginDuringACall()
is DeepLinkResult.Failure.Unknown -> appLogger.e("unknown deeplink failure")
is DeepLinkResult.JoinConversation -> onConversationInviteDeepLink(
Expand Down Expand Up @@ -465,13 +469,21 @@ class WireActivityViewModel @Inject constructor(
}
}

private suspend fun onCustomServerConfig(result: DeepLinkResult.CustomServerConfig) {
val customBackendDialogData = loadServerConfig(result.url)?.let { serverLinks ->
CustomServerDetailsDialogState(serverLinks = serverLinks)
} ?: CustomServerInvalidJsonDialogState
globalAppState = globalAppState.copy(
customBackendDialog = customBackendDialogData
)
fun onCustomServerConfig(customServerUrl: String) {
viewModelScope.launch(dispatchers.io()) {
val customBackendDialogData =
if (networkStateObserver.get().observeNetworkState().value != NetworkState.ConnectedWithInternet) {
CustomServerNoNetworkDialogState(customServerUrl)
} else {
loadServerConfig(customServerUrl)
?.let { serverLinks -> CustomServerDetailsDialogState(serverLinks = serverLinks) }
?: CustomServerInvalidJsonDialogState
}

globalAppState = globalAppState.copy(
customBackendDialog = customBackendDialogData
)
}
}

private suspend fun onConversationInviteDeepLink(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ internal fun CustomServerInvalidJsonDialog(
onDismiss: () -> Unit
) {
WireDialog(
title = stringResource(R.string.custom_backend_invalid_deeplink_data_title),
text = stringResource(R.string.custom_backend_invalid_deeplink_data_body),
title = stringResource(R.string.custom_backend_error_title),
text = stringResource(R.string.custom_backend_error_invalid_deeplink_data_body),
onDismiss = onDismiss,
optionButton1Properties = WireDialogButtonProperties(
onClick = onDismiss,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.ui.common.dialogs

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.wire.android.R
import com.wire.android.ui.common.WireDialog
import com.wire.android.ui.common.WireDialogButtonProperties
import com.wire.android.ui.common.WireDialogButtonType
import com.wire.android.ui.common.button.WireButtonState
import com.wire.android.ui.theme.WireTheme
import com.wire.android.util.ui.PreviewMultipleThemes

@Composable
internal fun CustomServerNoNetworkDialog(
onTryAgain: () -> Unit,
onDismiss: () -> Unit
) {
WireDialog(
title = stringResource(R.string.custom_backend_error_title),
text = stringResource(R.string.custom_backend_error_no_internet_connection_body),
onDismiss = onDismiss,
buttonsHorizontalAlignment = false,
optionButton1Properties = WireDialogButtonProperties(
onClick = {
onTryAgain()
onDismiss()
},
text = stringResource(id = R.string.custom_backend_error_no_internet_connection_try_again),
type = WireDialogButtonType.Primary,
state = WireButtonState.Default
),
optionButton2Properties = WireDialogButtonProperties(
onClick = onDismiss,
text = stringResource(id = R.string.label_cancel),
type = WireDialogButtonType.Secondary,
state = WireButtonState.Default
)
)
}

data class CustomServerNoNetworkDialogState(val customServerUrl: String) : CustomServerDialogState()

@PreviewMultipleThemes
@Composable
fun PreviewCustomServerNoNetworkDialog() = WireTheme {
CustomServerNoNetworkDialog(
onTryAgain = {},
onDismiss = {}
)
}
4 changes: 2 additions & 2 deletions app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,8 @@ Ez a beállítás az összes beszélgetésre érvényes ezen az eszközön.</str
<string name="custom_backend_dialog_body_backend_accounts">Fiókok URL:</string>
<string name="custom_backend_dialog_body_backend_website">Honlap URL:</string>
<string name="custom_backend_dialog_body_backend_websocket">Kiszolgáló WSURL:</string>
<string name="custom_backend_invalid_deeplink_data_title">Hiba történt</string>
<string name="custom_backend_invalid_deeplink_data_body">A saját kiszolgálóra történő átirányítás nem volt lehetséges, mivel a JSON fájl érvénytelen beállítást tartalmazott.\n\nLépjen kapcsolatba a rendszergazdával, vagy ellenőrizze a mélylinket, ami ide vezette.</string>
<string name="custom_backend_error_title">Hiba történt</string>
<string name="custom_backend_error_invalid_deeplink_data_body">A saját kiszolgálóra történő átirányítás nem volt lehetséges, mivel a JSON fájl érvénytelen beállítást tartalmazott.\n\nLépjen kapcsolatba a rendszergazdával, vagy ellenőrizze a mélylinket, ami ide vezette.</string>
<string name="label_fetching_your_messages">Új üzenetek lekérdezése</string>
<string name="label_text_copied">Szöveg a vágólapra másolva</string>
<string name="label_logs_option_title">Naplók</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1090,8 +1090,8 @@
<string name="custom_backend_dialog_body_backend_accounts">URL аккаунта:</string>
<string name="custom_backend_dialog_body_backend_website">URL веб-сайта:</string>
<string name="custom_backend_dialog_body_backend_websocket">WSURL бэкэнда:</string>
<string name="custom_backend_invalid_deeplink_data_title">Произошла ошибка</string>
<string name="custom_backend_invalid_deeplink_data_body">Перенаправление на локальный бэкэнд было неудачным, поскольку в JSON-файле была неверная конфигурация.\n\nСвяжитесь с администратором или проверьте ссылку, которая привела вас сюда.</string>
<string name="custom_backend_error_title">Произошла ошибка</string>
<string name="custom_backend_error_invalid_deeplink_data_body">Перенаправление на локальный бэкэнд было неудачным, поскольку в JSON-файле была неверная конфигурация.\n\nСвяжитесь с администратором или проверьте ссылку, которая привела вас сюда.</string>
<string name="label_fetching_your_messages">Получение новых сообщений</string>
<string name="label_text_copied">Текст скопирован в буфер обмена</string>
<string name="label_logs_option_title">Журналы</string>
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1080,8 +1080,10 @@ In group conversations, the group admin can overwrite this setting.</string>
<string name="custom_backend_dialog_body_backend_accounts">Accounts URL:</string>
<string name="custom_backend_dialog_body_backend_website">Website URL:</string>
<string name="custom_backend_dialog_body_backend_websocket">Backend WSURL:</string>
<string name="custom_backend_invalid_deeplink_data_title">An error occurred</string>
<string name="custom_backend_invalid_deeplink_data_body">Redirecting to an on-premises backend was not possible, as there was an invalid configuration in the JSON file.\n\nContact your admin or check the deeplink that brought you here.</string>
<string name="custom_backend_error_title">An error occurred</string>
<string name="custom_backend_error_invalid_deeplink_data_body">Redirecting to an on-premises backend was not possible, as there was an invalid configuration in the JSON file.\n\nContact your admin or check the deeplink that brought you here.</string>
<string name="custom_backend_error_no_internet_connection_body">Redirecting to an on-premises backend was not possible, you don’t seem to be connected to the internet.\n\nEstablish an internet connection and try again.</string>
<string name="custom_backend_error_no_internet_connection_try_again">Try again</string>
<string name="label_fetching_your_messages">Receiving new messages</string>
<string name="label_text_copied">Text copied to clipboard</string>
<string name="label_logs_option_title">Logs</string>
Expand Down
Loading
Loading