another.im-ios/AnotherIM/View/TestScreen.swift

133 lines
3.8 KiB
Swift
Raw Normal View History

2024-12-18 04:08:11 +00:00
import AnotherXMPP
2024-12-24 10:43:15 +00:00
import SwiftUI
2024-12-17 10:00:51 +00:00
// let login = "kudahtk@conversations.im"
// let pass = "derevo77!"
// let login = "testmon4@test.anal.company"
// let pass = "12345"
let login = "testmon3@test.anal.company"
let pass = "12345"
//
let userAgent = UserAgent(
uuid: "aaa65fa7-5555-4749-d1a5-740edbf81764",
software: "another.im",
device: "iOS"
)
let cls = XMPPClient(storage: TestStorage(), userAgent: userAgent)
struct TestScreen: View {
var body: some View {
ZStack {
Color.Material.Background.light
VStack {
Button {
doConnect()
} label: {
Text("Connect")
.padding()
.background { Color.blue.opacity(0.4) }
}
Button {
2024-12-17 16:07:13 +00:00
cls.addContact(jidStr: "asdadad@asdfsdf.df")
2024-12-17 10:00:51 +00:00
} label: {
2024-12-17 16:07:13 +00:00
Text("Add contact")
.padding()
.background { Color.blue.opacity(0.4) }
}
Button {
cls.deleteContact(jidStr: "asdadad@asdfsdf.df")
} label: {
Text("Remove contact")
2024-12-17 10:00:51 +00:00
.padding()
.background { Color.blue.opacity(0.4) }
}
}
}
.ignoresSafeArea()
}
func doConnect() {
// swiftlint:disable:next force_try
let jid = try! JID(login)
cls.tryLogin(jid: jid, credentialsId: UUID())
}
}
final class TestStorage: XMPPStorage {
private var roster: [String: Data] = [:]
2024-12-17 16:07:13 +00:00
func getCredentialsByUUID(_: UUID) async -> Credentials? {
["password": pass]
2024-12-17 10:00:51 +00:00
}
func deleteRoster(jid: JID) async {
roster.removeValue(forKey: jid.bare)
}
func getRoster(jid: JID) async -> Data? {
roster[jid.bare]
}
func setRoster(jid: JID, roster: Data) async {
self.roster[jid.bare] = roster
2024-12-17 16:07:13 +00:00
if let arr = try? JSONDecoder().decode([XMLElement].self, from: roster) {
print("ROSTER: \(arr)\n\n")
}
2024-12-17 10:00:51 +00:00
}
2024-12-24 10:43:15 +00:00
func getRosterVer(jid: JID) async -> String? {
print(jid)
return nil
}
func setRosterVer(jid: JID, version: String) async {
print(jid, version)
}
2024-12-17 10:00:51 +00:00
}
extension TestScreen {
// func doTestA() {
// let xml = XMLElement(
// name: "test-me",
// xmlns: "urn:test:me",
// attributes: ["some1": "some-val-1", "type": "test-req"],
// content: "asdffweqfqefq34234t2tergfsagewr",
// nodes: [
// XMLElement(
// name: "sub-test-me",
// xmlns: "urn:test:me",
// attributes: ["some1": "some-val-1"],
// content: "asdffweqfqefq34234t2tergfsagewr",
// nodes: [
// XMLElement(
// name: "sub2-test-me",
// xmlns: "urn:test:me",
// attributes: [:],
// content: nil,
// nodes: []
// )
// ]
// )
// ]
// )
// print("before")
// print(xml, "\n")
// print("after:")
// let encoded = try? JSONEncoder().encode(xml)
// if let encoded {
// print(String(decoding: encoded, as: UTF8.self))
// let xml2 = try? JSONDecoder().decode(XMLElement.self, from: encoded)
// if let xml2 {
// print("\n\n\n")
// print(xml2)
// }
// print("after all\n")
// print("\(encoded as NSData)")
// }
// }
}