diff --git a/AnotherXMPP/models/Presence.swift b/AnotherXMPP/models/Presence.swift deleted file mode 100644 index 911e90c..0000000 --- a/AnotherXMPP/models/Presence.swift +++ /dev/null @@ -1,28 +0,0 @@ -import Foundation - -enum PresenceType { - case chat - case online - case away - case xa - case dnd - - var weight: Int { - switch self { - case .chat: - return 5 - - case .online: - return 4 - - case .away: - return 3 - - case .xa: - return 2 - - case .dnd: - return 1 - } - } -} diff --git a/AnotherXMPP/models/Stanza.swift b/AnotherXMPP/models/Stanza.swift index f1d9700..325201e 100644 --- a/AnotherXMPP/models/Stanza.swift +++ b/AnotherXMPP/models/Stanza.swift @@ -26,7 +26,7 @@ enum StanzaType: Codable & Equatable { case iq(IqType) case message(MessageType) - case presense(PresenceType) + case presence(PresenceType) // Should never appear case unknown @@ -56,7 +56,7 @@ struct Stanza { case "presence": if let type = StanzaType.PresenceType(rawValue: wrapped.attributes["type"] ?? "") { - return .presense(type) + return .presence(type) } else { warn() return .unknown @@ -119,12 +119,27 @@ extension Stanza { } } +// MARK: Presence Stanza +// case chat +// case online +// case away +// case xa +// case dnd +extension Stanza { + static func initialPresence() -> Stanza { + Stanza(wrap: XMLElement(name: "presence", xmlns: nil, attributes: [:], content: nil, nodes: [])) + } +} + +// MARK: Additional private extension Stanza { func warn() { print("Something went wrong! with \(wrapped.stringRepresentation.prettyStr)") } } +// MARK: Stanza registry +// this is Actor which we use to keep request-response stanza logic final actor StanzaRegistry { var stanzas: [Stanza] = [] diff --git a/AnotherXMPP/modules/presence/PresenceModule.swift b/AnotherXMPP/modules/presence/PresenceModule.swift index 700b42c..87f836d 100644 --- a/AnotherXMPP/modules/presence/PresenceModule.swift +++ b/AnotherXMPP/modules/presence/PresenceModule.swift @@ -19,7 +19,8 @@ final class PresenceModule: XmppModule { func process(state _: ClientState, with event: Event) async -> Event? { switch event { case .rosterRequestDone: - return nil + guard let initial = Stanza.initialPresence() else { return nil } + return .stanzaOutbound(initial) case .stanzaInbound(let stanza): return nil