wip
This commit is contained in:
parent
d2f22dc066
commit
ae81c5d617
|
@ -1,4 +1,5 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import AnotherXMPP
|
||||||
|
|
||||||
// let login = "kudahtk@conversations.im"
|
// let login = "kudahtk@conversations.im"
|
||||||
// let pass = "derevo77!"
|
// let pass = "derevo77!"
|
||||||
|
|
|
@ -49,7 +49,7 @@ enum Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: State
|
// MARK: State
|
||||||
struct ClientState: Codable & Equatable {
|
public struct ClientState: Codable & Equatable {
|
||||||
var jid: JID
|
var jid: JID
|
||||||
var credentialsId: UUID
|
var credentialsId: UUID
|
||||||
var userAgent: UserAgent
|
var userAgent: UserAgent
|
||||||
|
@ -91,7 +91,7 @@ struct ClientState: Codable & Equatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Client
|
// MARK: Client
|
||||||
final class XMPPClient {
|
public final class XMPPClient {
|
||||||
private var state = ClientState.initial
|
private var state = ClientState.initial
|
||||||
private let logger = ClientLogger()
|
private let logger = ClientLogger()
|
||||||
private let storage: XMPPStorage
|
private let storage: XMPPStorage
|
||||||
|
@ -106,14 +106,14 @@ final class XMPPClient {
|
||||||
RosterModule(self.storage)
|
RosterModule(self.storage)
|
||||||
]
|
]
|
||||||
|
|
||||||
init(storage: any XMPPStorage, userAgent: UserAgent) {
|
public init(storage: any XMPPStorage, userAgent: UserAgent) {
|
||||||
self.storage = storage
|
self.storage = storage
|
||||||
state.userAgent = userAgent
|
state.userAgent = userAgent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Public part
|
// MARK: Public part
|
||||||
extension XMPPClient {
|
public extension XMPPClient {
|
||||||
func tryLogin(jid: JID, credentialsId: UUID) {
|
func tryLogin(jid: JID, credentialsId: UUID) {
|
||||||
logger.update(jid.full)
|
logger.update(jid.full)
|
||||||
Task {
|
Task {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
typealias Credentials = [String: String]
|
public typealias Credentials = [String: String]
|
||||||
|
|
||||||
protocol XMPPStorage: AnyObject {
|
public protocol XMPPStorage: AnyObject {
|
||||||
// credentials
|
// credentials
|
||||||
func getCredentialsByUUID(_ uuid: UUID) async -> Credentials?
|
func getCredentialsByUUID(_ uuid: UUID) async -> Credentials?
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
struct JID: Hashable, CustomStringConvertible, Codable, Equatable {
|
public struct JID: Hashable, CustomStringConvertible, Codable, Equatable {
|
||||||
let localPart: String
|
let localPart: String
|
||||||
let domainPart: String
|
let domainPart: String
|
||||||
let resourcePart: String?
|
let resourcePart: String?
|
||||||
|
|
||||||
init(_ jid: String) throws {
|
public init(_ jid: String) throws {
|
||||||
let parts = try JID.parse(jid)
|
let parts = try JID.parse(jid)
|
||||||
localPart = parts.0
|
localPart = parts.0
|
||||||
domainPart = parts.1
|
domainPart = parts.1
|
||||||
resourcePart = parts.2
|
resourcePart = parts.2
|
||||||
}
|
}
|
||||||
|
|
||||||
var full: String {
|
public var full: String {
|
||||||
var str = "\(localPart)@\(domainPart)"
|
var str = "\(localPart)@\(domainPart)"
|
||||||
if let resource = resourcePart {
|
if let resource = resourcePart {
|
||||||
str += "/\(resource)"
|
str += "/\(resource)"
|
||||||
|
@ -18,11 +18,11 @@ struct JID: Hashable, CustomStringConvertible, Codable, Equatable {
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
var description: String {
|
public var description: String {
|
||||||
full
|
full
|
||||||
}
|
}
|
||||||
|
|
||||||
var hash: Int {
|
public var hash: Int {
|
||||||
if let resourcePart {
|
if let resourcePart {
|
||||||
return "\(localPart)@\(domainPart)/\(resourcePart)".hashValue
|
return "\(localPart)@\(domainPart)/\(resourcePart)".hashValue
|
||||||
} else {
|
} else {
|
||||||
|
@ -30,11 +30,11 @@ struct JID: Hashable, CustomStringConvertible, Codable, Equatable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var bare: String {
|
public var bare: String {
|
||||||
"\(localPart)@\(domainPart)"
|
"\(localPart)@\(domainPart)"
|
||||||
}
|
}
|
||||||
|
|
||||||
var bareHash: Int {
|
public var bareHash: Int {
|
||||||
"\(localPart)@\(domainPart)".hashValue
|
"\(localPart)@\(domainPart)".hashValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ extension JID {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum JIDError: String, Error {
|
public enum JIDError: String, Error {
|
||||||
case wrongJid = "Can't parse or operate with JID"
|
case wrongJid = "Can't parse or operate with JID"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct UserAgent: Codable & Equatable {
|
public struct UserAgent: Codable & Equatable {
|
||||||
let uuid: String
|
public let uuid: String
|
||||||
let software: String
|
public let software: String
|
||||||
let device: String
|
public let device: String
|
||||||
|
|
||||||
|
public init(uuid: String, software: String, device: String) {
|
||||||
|
self.uuid = uuid
|
||||||
|
self.software = software
|
||||||
|
self.device = device
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct XMLElement: Codable, Equatable, CustomStringConvertible {
|
public struct XMLElement: Codable, Equatable, CustomStringConvertible {
|
||||||
let name: String
|
public let name: String
|
||||||
let xmlns: String?
|
public let xmlns: String?
|
||||||
let attributes: [String: String]
|
public let attributes: [String: String]
|
||||||
let content: String?
|
public let content: String?
|
||||||
let nodes: [XMLElement]
|
public let nodes: [XMLElement]
|
||||||
var woClose: Bool = false
|
public var woClose: Bool = false
|
||||||
|
|
||||||
var stringRepresentation: String {
|
public var stringRepresentation: String {
|
||||||
var result = "<\(name)"
|
var result = "<\(name)"
|
||||||
for (key, value) in attributes {
|
for (key, value) in attributes {
|
||||||
let val = value.escaped
|
let val = value.escaped
|
||||||
|
@ -35,7 +35,7 @@ struct XMLElement: Codable, Equatable, CustomStringConvertible {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
var description: String {
|
public var description: String {
|
||||||
stringRepresentation.prettyStr
|
stringRepresentation.prettyStr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue