This commit is contained in:
fmodf 2024-10-24 12:53:02 +02:00
parent e2002057db
commit 17f310dd6a
3 changed files with 9 additions and 20 deletions

View file

@ -33,7 +33,7 @@ enum UserSettings {
@Storage(key: kOmemoDevicesIds, defaultValue: [:]) @Storage(key: kOmemoDevicesIds, defaultValue: [:])
private static var omemoDevicesIds: [String: UInt32] private static var omemoDevicesIds: [String: UInt32]
@Storage(key: kSecureChatsByDefault, defaultValue: false) @Storage(key: kSecureChatsByDefault, defaultValue: true)
private static var vSecureChatsByDefault: Bool private static var vSecureChatsByDefault: Bool
} }
@ -41,7 +41,7 @@ enum UserSettings {
extension UserSettings { extension UserSettings {
static func reset() { static func reset() {
omemoDevicesIds = [:] omemoDevicesIds = [:]
vSecureChatsByDefault = false vSecureChatsByDefault = true
} }
static func set(omemoDeviceId: UInt32, for account: String) { static func set(omemoDeviceId: UInt32, for account: String) {

View file

@ -76,14 +76,13 @@ extension ClientsStore {
if let client = clients.first(where: { $0.credentials.bareJid == jidStr }) { if let client = clients.first(where: { $0.credentials.bareJid == jidStr }) {
// check if credentials already exist and enable it // check if credentials already exist and enable it
// this change will invoke reconnect automatically // this change will invoke reconnect automatically
try? await client.credentials.setActive(flag: true) await client.updActivity(true)
} else { } else {
// new client login with fake timeout // new client login with fake timeout
async let sleep: Void? = try? await Task.sleep(nanoseconds: 1 * NSEC_PER_SEC) async let sleep: Void? = try? await Task.sleep(nanoseconds: 1 * NSEC_PER_SEC)
async let request = try await Client.tryLogin(with: .init(bareJid: jidStr, pass: pass, isActive: true)) async let request = try await Client.tryLogin(with: .init(bareJid: jidStr, pass: pass, isActive: true))
let client = try await(request, sleep).0 let client = try await(request, sleep).0
clients.append(client)
try? await client.credentials.save() try? await client.credentials.save()
} }
} }

View file

@ -13,17 +13,8 @@ struct LoginScreen: View {
@FocusState private var focus: Field? @FocusState private var focus: Field?
#if DEBUG
@State private var jidStr: String = "grouptest1@test.anal.company"
@State private var pass: String = "12345"
// @State private var jidStr: String = "nartest1@conversations.im"
// @State private var pass: String = "nartest12345"
// @State private var jidStr: String = "test1@test.anal.company"
// @State private var pass: String = "12345"
#else
@State private var jidStr: String = "" @State private var jidStr: String = ""
@State private var pass: String = "" @State private var pass: String = ""
#endif
public var body: some View { public var body: some View {
ZStack { ZStack {
@ -107,19 +98,18 @@ struct LoginScreen: View {
} }
private func tryLogin() async { private func tryLogin() async {
defer {
router.dismissScreen()
}
do { do {
try await clientsStore.tryLogin(jidStr, pass) try await clientsStore.tryLogin(jidStr, pass)
router.dismissScreen()
} catch { } catch {
router.showAlert( router.showAlert(
.alert, .alert,
title: L10n.Global.Error.title, title: L10n.Global.Error.title,
subtitle: L10n.Login.error subtitle: L10n.Login.error
) { ) {
Button(L10n.Global.ok, role: .cancel) {} Button(L10n.Global.ok, role: .cancel) {
router.dismissModal()
}
} }
} }
} }