android: stopping chat after deleting the last user (#3937)

* android: stopping chat after deleting the last user

* fix for hidden users + onboarding
This commit is contained in:
Stanislav Dmitrenko
2024-03-21 21:02:38 +07:00
committed by GitHub
parent c2adf40b5a
commit 0706e6e464
8 changed files with 25 additions and 22 deletions
@@ -154,7 +154,7 @@ actual fun ActiveCallView() {
setCallSound(call.soundSpeaker, audioViaBluetooth)
}
withBGApi { chatModel.controller.apiCallStatus(callRh, call.contact, callStatus) }
} catch (e: Error) {
} catch (e: Throwable) {
Log.d(TAG,"call status ${r.state.connectionState} not used")
}
is WCallResponse.Connected -> {
@@ -75,7 +75,7 @@ class AppPreferences {
val value = _callOnLockScreen.get() ?: return CallOnLockScreen.default
return try {
CallOnLockScreen.valueOf(value)
} catch (e: Error) {
} catch (e: Throwable) {
CallOnLockScreen.default
}
},
@@ -95,7 +95,7 @@ class AppPreferences {
val value = _simplexLinkMode.get() ?: return SimplexLinkMode.default
return try {
SimplexLinkMode.valueOf(value)
} catch (e: Error) {
} catch (e: Throwable) {
SimplexLinkMode.default
}
},
@@ -123,7 +123,7 @@ class AppPreferences {
val value = _networkSessionMode.get() ?: return TransportSessionMode.default
return try {
TransportSessionMode.valueOf(value)
} catch (e: Error) {
} catch (e: Throwable) {
TransportSessionMode.default
}
},
@@ -393,7 +393,7 @@ object ChatController {
}
Log.d(TAG, "startChat: running")
}
} catch (e: Error) {
} catch (e: Throwable) {
Log.e(TAG, "failed starting chat $e")
throw e
}
@@ -411,7 +411,7 @@ object ChatController {
startReceiver()
setLocalDeviceName(appPrefs.deviceNameForRemoteAccess.get()!!)
Log.d(TAG, "startChat: started without user")
} catch (e: Error) {
} catch (e: Throwable) {
Log.e(TAG, "failed starting chat without user $e")
throw e
}
@@ -628,7 +628,7 @@ object ChatController {
when (r) {
is CR.ChatStarted -> return true
is CR.ChatRunning -> return false
else -> throw Error("failed starting chat: ${r.responseType} ${r.details}")
else -> throw Exception("failed starting chat: ${r.responseType} ${r.details}")
}
}
@@ -636,26 +636,26 @@ object ChatController {
val r = sendCmd(null, CC.ApiStopChat())
when (r) {
is CR.ChatStopped -> return true
else -> throw Error("failed stopping chat: ${r.responseType} ${r.details}")
else -> throw Exception("failed stopping chat: ${r.responseType} ${r.details}")
}
}
suspend fun apiSetTempFolder(tempFolder: String, ctrl: ChatCtrl? = null) {
val r = sendCmd(null, CC.SetTempFolder(tempFolder), ctrl)
if (r is CR.CmdOk) return
throw Error("failed to set temp folder: ${r.responseType} ${r.details}")
throw Exception("failed to set temp folder: ${r.responseType} ${r.details}")
}
suspend fun apiSetFilesFolder(filesFolder: String, ctrl: ChatCtrl? = null) {
val r = sendCmd(null, CC.SetFilesFolder(filesFolder), ctrl)
if (r is CR.CmdOk) return
throw Error("failed to set files folder: ${r.responseType} ${r.details}")
throw Exception("failed to set files folder: ${r.responseType} ${r.details}")
}
suspend fun apiSetRemoteHostsFolder(remoteHostsFolder: String) {
val r = sendCmd(null, CC.SetRemoteHostsFolder(remoteHostsFolder))
if (r is CR.CmdOk) return
throw Error("failed to set remote hosts folder: ${r.responseType} ${r.details}")
throw Exception("failed to set remote hosts folder: ${r.responseType} ${r.details}")
}
suspend fun apiSetEncryptLocalFiles(enable: Boolean) = sendCommandOkResp(null, CC.ApiSetEncryptLocalFiles(enable))
@@ -663,13 +663,13 @@ object ChatController {
suspend fun apiSaveAppSettings(settings: AppSettings) {
val r = sendCmd(null, CC.ApiSaveSettings(settings))
if (r is CR.CmdOk) return
throw Error("failed to set app settings: ${r.responseType} ${r.details}")
throw Exception("failed to set app settings: ${r.responseType} ${r.details}")
}
suspend fun apiGetAppSettings(settings: AppSettings): AppSettings {
val r = sendCmd(null, CC.ApiGetSettings(settings))
if (r is CR.AppSettingsR) return r.appSettings
throw Error("failed to get app settings: ${r.responseType} ${r.details}")
throw Exception("failed to get app settings: ${r.responseType} ${r.details}")
}
suspend fun apiSetPQEncryption(enable: Boolean) = sendCommandOkResp(null, CC.ApiSetPQEncryption(enable))
@@ -684,19 +684,19 @@ object ChatController {
suspend fun apiExportArchive(config: ArchiveConfig) {
val r = sendCmd(null, CC.ApiExportArchive(config))
if (r is CR.CmdOk) return
throw Error("failed to export archive: ${r.responseType} ${r.details}")
throw Exception("failed to export archive: ${r.responseType} ${r.details}")
}
suspend fun apiImportArchive(config: ArchiveConfig): List<ArchiveError> {
val r = sendCmd(null, CC.ApiImportArchive(config))
if (r is CR.ArchiveImported) return r.archiveErrors
throw Error("failed to import archive: ${r.responseType} ${r.details}")
throw Exception("failed to import archive: ${r.responseType} ${r.details}")
}
suspend fun apiDeleteStorage() {
val r = sendCmd(null, CC.ApiDeleteStorage())
if (r is CR.CmdOk) return
throw Error("failed to delete storage: ${r.responseType} ${r.details}")
throw Exception("failed to delete storage: ${r.responseType} ${r.details}")
}
suspend fun apiStorageEncryption(currentKey: String = "", newKey: String = ""): CR.ChatCmdError? {
@@ -42,7 +42,7 @@ fun copyFileToFile(from: File, to: URI, finally: () -> Unit) {
}
}
showToast(generalGetString(MR.strings.file_saved))
} catch (e: Error) {
} catch (e: Throwable) {
showToast(generalGetString(MR.strings.error_saving_file))
Log.e(TAG, "copyFileToFile error saving file $e")
} finally {
@@ -58,7 +58,7 @@ fun copyBytesToFile(bytes: ByteArrayInputStream, to: URI, finally: () -> Unit) {
}
}
showToast(generalGetString(MR.strings.file_saved))
} catch (e: Error) {
} catch (e: Throwable) {
showToast(generalGetString(MR.strings.error_saving_file))
Log.e(TAG, "copyBytesToFile error saving file $e")
} finally {
@@ -214,7 +214,8 @@ fun createProfileOnboarding(chatModel: ChatModel, displayName: String, close: ()
) ?: return@withBGApi
chatModel.localUserCreated.value = true
val onboardingStage = chatModel.controller.appPrefs.onboardingStage
if (chatModel.users.isEmpty()) {
// No users or no visible users
if (chatModel.users.none { u -> !u.user.hidden }) {
onboardingStage.set(if (appPlatform.isDesktop && chatModel.controller.appPrefs.initialRandomDBPassphrase.get() && !chatModel.desktopOnboardingRandomPassword.value) {
OnboardingStage.Step2_5_SetupDatabasePassphrase
} else {
@@ -388,7 +388,7 @@ fun startChat(m: ChatModel, chatLastStart: MutableState<Instant?>, chatDbChanged
m.controller.appPrefs.chatLastStart.set(ts)
chatLastStart.value = ts
platform.androidChatStartedAfterBeingOff()
} catch (e: Error) {
} catch (e: Throwable) {
m.chatRunning.value = false
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.error_starting_chat), e.toString())
} finally {
@@ -169,7 +169,8 @@ private fun ProgressIndicator() {
}
private fun prepareChatBeforeAddressCreation(rhId: Long?) {
if (chatModel.users.isNotEmpty()) return
// No visible users but may have hidden. In this case chat should be started anyway because it's stopped on this stage with hidden users
if (chatModel.users.any { u -> !u.user.hidden }) return
withBGApi {
val user = chatModel.controller.apiGetActiveUser(rhId) ?: return@withBGApi
chatModel.currentUser.value = user
@@ -356,6 +356,7 @@ private suspend fun doRemoveUser(m: ChatModel, user: User, users: List<User>, de
m.controller.apiDeleteUser(user, delSMPQueues, viewPwd)
m.controller.changeActiveUser_(user.remoteHostId, null, null)
if (appPlatform.isAndroid) {
m.controller.apiStopChat()
controller.appPrefs.onboardingStage.set(OnboardingStage.Step1_SimpleXInfo)
ModalManager.closeAllModalsEverywhere()
}
@@ -75,7 +75,7 @@ actual fun ActiveCallView() {
chatModel.activeCall.value = call.copy(callState = CallState.Connected, connectedAt = Clock.System.now())
}
withBGApi { chatModel.controller.apiCallStatus(callRh, call.contact, callStatus) }
} catch (e: Error) {
} catch (e: Throwable) {
Log.d(TAG, "call status ${r.state.connectionState} not used")
}
is WCallResponse.Connected -> {