From c2cd58f63d513c0dd8b687d3f9db703e6d549d1a Mon Sep 17 00:00:00 2001
From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com>
Date: Tue, 31 Jan 2023 18:50:20 +0000
Subject: [PATCH] android: adapted UserExists error (#1863)
* android: Adapted UserExists error
* updated texts
---------
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
---
.../src/main/java/chat/simplex/app/model/SimpleXAPI.kt | 9 +++++++--
apps/android/app/src/main/res/values/strings.xml | 3 ++-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt
index af9acf9190..d99feccc35 100644
--- a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt
+++ b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt
@@ -383,8 +383,11 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a
suspend fun apiCreateActiveUser(p: Profile): User? {
val r = sendCmd(CC.CreateActiveUser(p))
if (r is CR.ActiveUser) return r.user
- else if (r is CR.ChatCmdError && r.chatError is ChatError.ChatErrorStore && r.chatError.storeError is StoreError.DuplicateName) {
- AlertManager.shared.showAlertMsg(generalGetString(R.string.failed_to_create_user_title), generalGetString(R.string.failed_to_create_user_duplicate_desc))
+ else if (
+ r is CR.ChatCmdError && r.chatError is ChatError.ChatErrorStore && r.chatError.storeError is StoreError.DuplicateName ||
+ r is CR.ChatCmdError && r.chatError is ChatError.ChatErrorChat && r.chatError.errorType is ChatErrorType.UserExists
+ ) {
+ AlertManager.shared.showAlertMsg(generalGetString(R.string.failed_to_create_user_duplicate_title), generalGetString(R.string.failed_to_create_user_duplicate_desc))
} else {
AlertManager.shared.showAlertMsg(generalGetString(R.string.failed_to_create_user_title), r.details)
}
@@ -3231,12 +3234,14 @@ sealed class ChatErrorType {
val string: String get() = when (this) {
is NoActiveUser -> "noActiveUser"
is DifferentActiveUser -> "differentActiveUser"
+ is UserExists -> "userExists"
is InvalidConnReq -> "invalidConnReq"
is FileAlreadyReceiving -> "fileAlreadyReceiving"
is СommandError -> "commandError $message"
}
@Serializable @SerialName("noActiveUser") class NoActiveUser: ChatErrorType()
@Serializable @SerialName("differentActiveUser") class DifferentActiveUser: ChatErrorType()
+ @Serializable @SerialName("userExists") class UserExists(val contactName: String): ChatErrorType()
@Serializable @SerialName("invalidConnReq") class InvalidConnReq: ChatErrorType()
@Serializable @SerialName("fileAlreadyReceiving") class FileAlreadyReceiving: ChatErrorType()
@Serializable @SerialName("commandError") class СommandError(val message: String): ChatErrorType()
diff --git a/apps/android/app/src/main/res/values/strings.xml b/apps/android/app/src/main/res/values/strings.xml
index 758fe3cece..0590bd68e4 100644
--- a/apps/android/app/src/main/res/values/strings.xml
+++ b/apps/android/app/src/main/res/values/strings.xml
@@ -63,7 +63,8 @@
Failed to load chat
Failed to load chats
Please update the app and contact developers.
- Duplicate display name!
+ Error creating profile!
+ Duplicate display name!
You already have a chat profile with the same display name. Please choose another name.
Error switching profile!