From ae81c5d617813e310a22d65575bf119a0c3a833b Mon Sep 17 00:00:00 2001 From: fmodf Date: Wed, 18 Dec 2024 05:08:11 +0100 Subject: [PATCH] wip --- AnotherIM/View/TestScreen.swift | 1 + AnotherXMPP/XMPPClient.swift | 8 ++++---- AnotherXMPP/XMPPStorage.swift | 4 ++-- AnotherXMPP/models/JID.swift | 16 ++++++++-------- AnotherXMPP/models/UserAgent.swift | 14 ++++++++++---- AnotherXMPP/models/XMLElement.swift | 18 +++++++++--------- 6 files changed, 34 insertions(+), 27 deletions(-) diff --git a/AnotherIM/View/TestScreen.swift b/AnotherIM/View/TestScreen.swift index 36372ab..9bce07d 100644 --- a/AnotherIM/View/TestScreen.swift +++ b/AnotherIM/View/TestScreen.swift @@ -1,4 +1,5 @@ import SwiftUI +import AnotherXMPP // let login = "kudahtk@conversations.im" // let pass = "derevo77!" diff --git a/AnotherXMPP/XMPPClient.swift b/AnotherXMPP/XMPPClient.swift index 481b3d4..e4d95cd 100644 --- a/AnotherXMPP/XMPPClient.swift +++ b/AnotherXMPP/XMPPClient.swift @@ -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 { diff --git a/AnotherXMPP/XMPPStorage.swift b/AnotherXMPP/XMPPStorage.swift index 11b8186..6e208c1 100644 --- a/AnotherXMPP/XMPPStorage.swift +++ b/AnotherXMPP/XMPPStorage.swift @@ -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? diff --git a/AnotherXMPP/models/JID.swift b/AnotherXMPP/models/JID.swift index 4c77e72..4b54f12 100644 --- a/AnotherXMPP/models/JID.swift +++ b/AnotherXMPP/models/JID.swift @@ -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" } diff --git a/AnotherXMPP/models/UserAgent.swift b/AnotherXMPP/models/UserAgent.swift index d85a66b..b1e7fca 100644 --- a/AnotherXMPP/models/UserAgent.swift +++ b/AnotherXMPP/models/UserAgent.swift @@ -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 + } } diff --git a/AnotherXMPP/models/XMLElement.swift b/AnotherXMPP/models/XMLElement.swift index 64919ce..0728843 100644 --- a/AnotherXMPP/models/XMLElement.swift +++ b/AnotherXMPP/models/XMLElement.swift @@ -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 }