Skip to content
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
25 changes: 25 additions & 0 deletions app/src/main/kotlin/com/wire/android/datastore/GlobalDataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class GlobalDataStore @Inject constructor(@ApplicationContext private val contex

private fun userLastMigrationAppVersion(userId: String): Preferences.Key<Int> =
intPreferencesKey("migration_app_version_$userId")

private fun backendSupportEmailKey(backendApiUrl: String): Preferences.Key<String> =
stringPreferencesKey("backend_support_email_${backendApiUrl.sha256()}")
}

suspend fun clear() {
Expand Down Expand Up @@ -238,4 +241,26 @@ class GlobalDataStore @Inject constructor(@ApplicationContext private val contex
suspend fun setEnterToSend(enabled: Boolean) {
context.dataStore.edit { it[ENTER_TO_SENT] = enabled }
}

suspend fun setBackendSupportEmail(backendApiUrl: String, supportEmail: String?) {
if (backendApiUrl.isBlank()) return

context.dataStore.edit {
val key = backendSupportEmailKey(backendApiUrl)
val normalizedSupportEmail = supportEmail?.trim().orEmpty()
if (normalizedSupportEmail.isBlank()) {
it.remove(key)
} else {
it[key] = normalizedSupportEmail
}
}
}

suspend fun getBackendSupportEmail(backendApiUrl: String): String? =
if (backendApiUrl.isBlank()) {
null
} else {
context.dataStore.data.firstOrNull()?.get(backendSupportEmailKey(backendApiUrl))
?.takeIf { it.isNotBlank() }
}
}
52 changes: 41 additions & 11 deletions app/src/main/kotlin/com/wire/android/di/AuthServerConfigProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,57 @@ import javax.inject.Singleton
@Singleton
class AuthServerConfigProvider @Inject constructor() {
// todo check with soft logout
private val defaultBackendConfigs = ServerConfig.Links(
api = BuildConfig.DEFAULT_BACKEND_URL_BASE_API,
accounts = BuildConfig.DEFAULT_BACKEND_URL_ACCOUNTS,
webSocket = BuildConfig.DEFAULT_BACKEND_URL_BASE_WEBSOCKET,
teams = BuildConfig.DEFAULT_BACKEND_URL_TEAM_MANAGEMENT,
blackList = BuildConfig.DEFAULT_BACKEND_URL_BLACKLIST,
website = BuildConfig.DEFAULT_BACKEND_URL_WEBSITE,
title = BuildConfig.DEFAULT_BACKEND_TITLE,
isOnPremises = false,
apiProxy = null
)
private val defaultBackendConfigs = if (BuildConfig.DEFAULT_BACKEND_ENABLED) {
ServerConfig.Links(
api = BuildConfig.DEFAULT_BACKEND_URL_BASE_API,
accounts = BuildConfig.DEFAULT_BACKEND_URL_ACCOUNTS,
webSocket = BuildConfig.DEFAULT_BACKEND_URL_BASE_WEBSOCKET,
teams = BuildConfig.DEFAULT_BACKEND_URL_TEAM_MANAGEMENT,
blackList = BuildConfig.DEFAULT_BACKEND_URL_BLACKLIST,
website = BuildConfig.DEFAULT_BACKEND_URL_WEBSITE,
title = BuildConfig.DEFAULT_BACKEND_TITLE,
isOnPremises = false,
apiProxy = null
)
} else {
EmptyServerConfig
}
private val _authServer: MutableStateFlow<ServerConfig.Links> = MutableStateFlow(defaultBackendConfigs)
val authServer: StateFlow<ServerConfig.Links> = _authServer

private val _backendConfigSuccessVisible: MutableStateFlow<Boolean> = MutableStateFlow(false)
val backendConfigSuccessVisible: StateFlow<Boolean> = _backendConfigSuccessVisible

fun updateAuthServer(serverLinks: ServerConfig.Links) {
_authServer.value = serverLinks
}

fun updateAuthServerFromBackendConfiguration(serverLinks: ServerConfig.Links) {
updateAuthServer(serverLinks)
_backendConfigSuccessVisible.value = true
}

fun updateAuthServer(serverConfig: ServerConfig) {
_authServer.value = serverConfig.links
}

fun dismissBackendConfigSuccess() {
_backendConfigSuccessVisible.value = false
}

fun defaultServerLinks() = defaultBackendConfigs

companion object {
val EmptyServerConfig = ServerConfig.Links(
api = "",
accounts = "",
webSocket = "",
teams = "",
blackList = "",
website = "",
title = "",
isOnPremises = false,
apiProxy = null
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fun String.getBaseRoute(): String =

fun Direction.handleNavigation(context: Context, handleOtherDirection: (Direction) -> Unit) = when (this) {
is ExternalUriDirection -> CustomTabsHelper.launchUri(context, this.uri)
is ExternalUriStringResDirection -> CustomTabsHelper.launchUri(context, this.getUri(context.resources))
is ExternalUriStringResDirection -> CustomTabsHelper.launchUrl(context, context.resources.getString(this.uriStringRes))
is IntentDirection -> context.startActivity(this.intent(context))
else -> handleOtherDirection(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import androidx.annotation.StringRes
import com.ramcosta.composedestinations.spec.Direction
import com.wire.android.BuildConfig
import com.wire.android.R
import com.wire.android.util.BackendSupportConfig
import com.wire.android.util.EmailComposer
import com.wire.android.util.LogFileWriter
import com.wire.android.util.getDeviceIdString
import com.wire.android.util.getGitBuildId
import com.wire.android.util.getUrisOfFilesInDirectory
import com.wire.android.util.multipleFileSharingIntent
import com.wire.android.util.sha256
import kotlinx.coroutines.runBlocking

interface ExternalUriDirection : Direction {
val uri: Uri
Expand Down Expand Up @@ -96,11 +98,24 @@ object GiveFeedbackDestination : IntentDirection {
}

object ReportBugDestination : IntentDirection {
@Suppress("ReturnCount")
override fun intent(context: Context): Intent {
val supportEmail = runBlocking {
BackendSupportConfig.resolveEmail(context, context.getString(R.string.send_bug_report_email))
}
if (supportEmail == null) {
BackendSupportConfig.supportPageIntent()?.let { return it }
context.getString(R.string.url_support).takeIf { it.isNotBlank() }?.let {
return Intent(Intent.ACTION_VIEW, Uri.parse(it))
}
}

val dir = LogFileWriter.logsDirectory(context)
val logsUris = context.getUrisOfFilesInDirectory(dir)
val intent = context.multipleFileSharingIntent(logsUris)
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(context.getString(R.string.send_bug_report_email)))
supportEmail?.let {
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(it))
}
intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.send_bug_report_subject))
intent.putExtra(
Intent.EXTRA_TEXT,
Expand Down
30 changes: 28 additions & 2 deletions app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ import com.wire.android.ui.common.dialogs.CustomServerDialogState
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.BackendSupportConfig
import com.wire.android.util.CurrentScreen
import com.wire.android.util.CurrentScreenManager
import com.wire.android.util.CustomTabsHelper
import com.wire.android.util.deeplink.DeepLinkProcessor
import com.wire.android.util.deeplink.DeepLinkResult
import com.wire.android.util.dispatchers.DispatcherProvider
Expand Down Expand Up @@ -75,6 +77,7 @@ import com.wire.kalium.logic.feature.session.DoesValidSessionExistResult
import com.wire.kalium.logic.feature.session.DoesValidSessionExistUseCase
import com.wire.kalium.logic.feature.session.GetAllSessionsResult
import com.wire.kalium.logic.feature.session.GetSessionsUseCase
import com.wire.kalium.logic.feature.user.SelfServerConfigUseCase
import com.wire.kalium.logic.feature.user.screenshotCensoring.ObserveScreenshotCensoringConfigResult
import com.wire.kalium.logic.feature.user.webSocketStatus.ObservePersistentWebSocketConnectionStatusUseCase
import com.wire.kalium.util.DateTimeUtil.toIsoDateTimeString
Expand Down Expand Up @@ -151,6 +154,7 @@ class WireActivityViewModel @Inject constructor(
observeScreenshotCensoringConfigState()
observeAppThemeState()
observeLogoutState()
observeBackendWebsiteUrl()
}

private suspend fun shouldEnrollToE2ei(): Boolean = observeCurrentValidUserId.first()?.let {
Expand All @@ -168,6 +172,25 @@ class WireActivityViewModel @Inject constructor(
}
}

private fun observeBackendWebsiteUrl() {
viewModelScope.launch(dispatchers.io()) {
observeCurrentValidUserId.collect { userId ->
val serverLinks = userId?.let {
runCatching {
when (val result = coreLogic.getSessionScope(it).users.serverLinks()) {
is SelfServerConfigUseCase.Result.Success -> result.serverLinks.links
is SelfServerConfigUseCase.Result.Failure -> null
}
}.getOrNull()
} ?: authServerConfigProvider.get().authServer.value
BackendSupportConfig.setCurrentBackend(serverLinks)
val websiteUrl = serverLinks.website

CustomTabsHelper.setBackendWebsiteUrl(websiteUrl)
}
}
}

private fun observeSyncState() {
viewModelScope.launch(dispatchers.io()) {
observeCurrentValidUserId
Expand Down Expand Up @@ -348,7 +371,7 @@ class WireActivityViewModel @Inject constructor(
if (backendDialogState is CustomServerDetailsDialogState) {
viewModelScope.launch {
authServerConfigProvider.get()
.updateAuthServer(backendDialogState.serverLinks)
.updateAuthServerFromBackendConfiguration(backendDialogState.serverLinks)
dismissCustomBackendDialog()
if (checkNumberOfSessions() >= BuildConfig.MAX_ACCOUNTS) {
globalAppState = globalAppState.copy(maxAccountDialog = true)
Expand Down Expand Up @@ -422,7 +445,10 @@ class WireActivityViewModel @Inject constructor(

private suspend fun loadServerConfig(url: String): ServerConfig.Links? =
when (val result = getServerConfigUseCase.get().invoke(url)) {
is GetServerConfigResult.Success -> result.serverConfigLinks
is GetServerConfigResult.Success -> result.serverConfigLinks.also {
CustomTabsHelper.setBackendWebsiteUrl(it.website)
BackendSupportConfig.storeFromConfigUrl(globalDataStore.get(), it, url)
}
is GetServerConfigResult.Failure.Generic -> {
appLogger.e("something went wrong during handling the custom server deep link: ${result.genericFailure}")
null
Expand Down
Loading
Loading