This commit is contained in:
fmodf 2025-01-14 04:19:12 +01:00
parent d95c9c1671
commit 495dbd158c
3 changed files with 19 additions and 31 deletions

View file

@ -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
}
}
}

View file

@ -26,7 +26,7 @@ enum StanzaType: Codable & Equatable {
case iq(IqType) case iq(IqType)
case message(MessageType) case message(MessageType)
case presense(PresenceType) case presence(PresenceType)
// Should never appear // Should never appear
case unknown case unknown
@ -56,7 +56,7 @@ struct Stanza {
case "presence": case "presence":
if let type = StanzaType.PresenceType(rawValue: wrapped.attributes["type"] ?? "") { if let type = StanzaType.PresenceType(rawValue: wrapped.attributes["type"] ?? "") {
return .presense(type) return .presence(type)
} else { } else {
warn() warn()
return .unknown 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 { private extension Stanza {
func warn() { func warn() {
print("Something went wrong! with \(wrapped.stringRepresentation.prettyStr)") 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 { final actor StanzaRegistry {
var stanzas: [Stanza] = [] var stanzas: [Stanza] = []

View file

@ -19,7 +19,8 @@ final class PresenceModule: XmppModule {
func process(state _: ClientState, with event: Event) async -> Event? { func process(state _: ClientState, with event: Event) async -> Event? {
switch event { switch event {
case .rosterRequestDone: case .rosterRequestDone:
return nil guard let initial = Stanza.initialPresence() else { return nil }
return .stanzaOutbound(initial)
case .stanzaInbound(let stanza): case .stanzaInbound(let stanza):
return nil return nil