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