ios: switch contact and member to another address (#1282)

* ios: switch contact and member to another address

* update simplexmq (JSON encoding)
This commit is contained in:
Evgeny Poberezkin
2022-11-02 09:48:20 +00:00
committed by GitHub
parent d5fc0d7dfc
commit cbdd9b9e37
6 changed files with 63 additions and 9 deletions

View File

@@ -65,12 +65,16 @@ struct ChatInfoView: View {
case deleteContactAlert
case clearChatAlert
case networkStatusAlert
case switchAddressAlert
case error(title: LocalizedStringKey, error: LocalizedStringKey = "")
var id: String {
switch self {
case .deleteContactAlert: return "deleteContactAlert"
case .clearChatAlert: return "clearChatAlert"
case .networkStatusAlert: return "networkStatusAlert"
case .switchAddressAlert: return "switchAddressAlert"
case let .error(title, _): return "error \(title)"
}
}
}
@@ -100,8 +104,10 @@ struct ChatInfoView: View {
.onTapGesture {
alert = .networkStatusAlert
}
Button("Switch receiving address") {
if developerTools {
Button("Switch receiving address (BETA)") {
alert = .switchAddressAlert
}
}
if let connStats = connectionStats {
smpServers("Receiving via", connStats.rcvServers)
@@ -129,6 +135,8 @@ struct ChatInfoView: View {
case .deleteContactAlert: return deleteContactAlert()
case .clearChatAlert: return clearChatAlert()
case .networkStatusAlert: return networkStatusAlert()
case .switchAddressAlert: return switchAddressAlert(switchContactAddress)
case let .error(title, error): return mkAlert(title: title, message: error)
}
}
}
@@ -236,7 +244,11 @@ struct ChatInfoView: View {
dismiss()
}
} catch let error {
logger.error("deleteContactAlert apiDeleteChat error: \(error.localizedDescription)")
logger.error("deleteContactAlert apiDeleteChat error: \(responseError(error))")
let a = getErrorAlert(error, "Error deleting contact")
await MainActor.run {
alert = .error(title: a.title, error: a.message)
}
}
}
},
@@ -264,6 +276,29 @@ struct ChatInfoView: View {
message: Text(chat.serverInfo.networkStatus.statusExplanation)
)
}
private func switchContactAddress() {
Task {
do {
try await apiSwitchContact(contactId: contact.apiId)
} catch let error {
logger.error("switchContactAddress apiSwitchContact error: \(responseError(error))")
let a = getErrorAlert(error, "Error changing address")
await MainActor.run {
alert = .error(title: a.title, error: a.message)
}
}
}
}
}
func switchAddressAlert(_ switchAddress: @escaping () -> Void) -> Alert {
Alert(
title: Text("Change receiving address?"),
message: Text("This feature is experimental! It will only work if the other client has version 4.2 installed. You should see the message in the conversation once the address change is completed please check that you can still receive messages from this contact (or group member)."),
primaryButton: .destructive(Text("Change"), action: switchAddress),
secondaryButton: .cancel()
)
}
struct ChatInfoView_Previews: PreviewProvider {

View File

@@ -22,12 +22,14 @@ struct GroupMemberInfoView: View {
enum GroupMemberInfoViewAlert: Identifiable {
case removeMemberAlert
case changeMemberRoleAlert(role: GroupMemberRole)
case switchAddressAlert
case error(title: LocalizedStringKey, error: LocalizedStringKey)
var id: String {
switch self {
case .removeMemberAlert: return "removeMemberAlert"
case let .changeMemberRoleAlert(role): return "changeMemberRoleAlert \(role.rawValue)"
case .switchAddressAlert: return "switchAddressAlert"
case let .error(title, _): return "error \(title)"
}
}
@@ -79,8 +81,10 @@ struct GroupMemberInfoView: View {
Section("Servers") {
// TODO network connection status
Button("Switch receiving address") {
if developerTools {
Button("Switch receiving address (BETA)") {
alert = .switchAddressAlert
}
}
if let connStats = connectionStats {
smpServers("Receiving via", connStats.rcvServers)
@@ -108,6 +112,7 @@ struct GroupMemberInfoView: View {
switch(alertItem) {
case .removeMemberAlert: return removeMemberAlert()
case .changeMemberRoleAlert: return changeMemberRoleAlert()
case .switchAddressAlert: return switchAddressAlert(switchMemberAddress)
case let .error(title, error): return Alert(title: Text(title), message: Text(error))
}
}
@@ -213,6 +218,20 @@ struct GroupMemberInfoView: View {
}
)
}
private func switchMemberAddress() {
Task {
do {
try await apiSwitchGroupMember(groupInfo.apiId, member.groupMemberId)
} catch let error {
logger.error("switchMemberAddress apiSwitchGroupMember error: \(responseError(error))")
let a = getErrorAlert(error, "Error changing address")
await MainActor.run {
alert = .error(title: a.title, error: a.message)
}
}
}
}
}
struct GroupMemberInfoView_Previews: PreviewProvider {

View File

@@ -7,7 +7,7 @@ constraints: zip +disable-bzip2 +disable-zstd
source-repository-package
type: git
location: https://github.com/simplex-chat/simplexmq.git
tag: d9a0e78b04d2bdc79a197125b7cc104c309bdbd8
tag: 029fc6e781d78249d0b3a17edff7416ef22afed1
source-repository-package
type: git

View File

@@ -1,5 +1,5 @@
{
"https://github.com/simplex-chat/simplexmq.git"."d9a0e78b04d2bdc79a197125b7cc104c309bdbd8" = "08g686fnzmimiqfv1lqjphafkvw858dip1awg137days5sb5rqsf";
"https://github.com/simplex-chat/simplexmq.git"."029fc6e781d78249d0b3a17edff7416ef22afed1" = "054bjknwr75n7rpi4q41x966mnf4903rvy402vwyp1y9njzbd20q";
"https://github.com/simplex-chat/direct-sqlcipher.git"."34309410eb2069b029b8fc1872deb1e0db123294" = "0kwkmhyfsn2lixdlgl15smgr1h5gjk7fky6abzh8rng2h5ymnffd";
"https://github.com/simplex-chat/sqlcipher-simple.git"."5e154a2aeccc33ead6c243ec07195ab673137221" = "1d1gc5wax4vqg0801ajsmx1sbwvd9y7p7b8mmskvqsmpbwgbh0m0";
"https://github.com/simplex-chat/aeson.git"."3eb66f9a68f103b5f1489382aad89f5712a64db7" = "0kilkx59fl6c3qy3kjczqvm8c3f4n3p0bdk9biyflf51ljnzp4yp";

View File

@@ -32,7 +32,7 @@ import GHC.Generics (Generic)
import Simplex.Chat.Markdown
import Simplex.Chat.Protocol
import Simplex.Chat.Types
import Simplex.Messaging.Agent.Protocol (SwitchPhase (..), AgentErrorType, AgentMsgId, MsgErrorType (..), MsgMeta (..), SwitchPhase)
import Simplex.Messaging.Agent.Protocol (AgentErrorType, AgentMsgId, MsgErrorType (..), MsgMeta (..), SwitchPhase (..))
import Simplex.Messaging.Encoding.String
import Simplex.Messaging.Parsers (dropPrefix, enumJSON, fromTextField_, fstToLower, singleFieldJSON, sumTypeJSON)
import Simplex.Messaging.Protocol (MsgBody)

View File

@@ -49,7 +49,7 @@ extra-deps:
# - simplexmq-1.0.0@sha256:34b2004728ae396e3ae449cd090ba7410781e2b3cefc59259915f4ca5daa9ea8,8561
# - ../simplexmq
- github: simplex-chat/simplexmq
commit: d9a0e78b04d2bdc79a197125b7cc104c309bdbd8
commit: 029fc6e781d78249d0b3a17edff7416ef22afed1
# - ../direct-sqlcipher
- github: simplex-chat/direct-sqlcipher
commit: 34309410eb2069b029b8fc1872deb1e0db123294