124 lines
3.6 KiB
Swift
124 lines
3.6 KiB
Swift
import SwiftUI
|
|
import AnotherXMPP
|
|
|
|
// 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 {
|
|
cls.addContact(jidStr: "asdadad@asdfsdf.df")
|
|
} label: {
|
|
Text("Add contact")
|
|
.padding()
|
|
.background { Color.blue.opacity(0.4) }
|
|
}
|
|
Button {
|
|
cls.deleteContact(jidStr: "asdadad@asdfsdf.df")
|
|
} label: {
|
|
Text("Remove contact")
|
|
.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] = [:]
|
|
|
|
func getCredentialsByUUID(_: UUID) async -> Credentials? {
|
|
["password": pass]
|
|
}
|
|
|
|
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
|
|
|
|
if let arr = try? JSONDecoder().decode([XMLElement].self, from: roster) {
|
|
print("ROSTER: \(arr)\n\n")
|
|
}
|
|
}
|
|
}
|
|
|
|
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)")
|
|
// }
|
|
// }
|
|
}
|