diff --git a/.swiftlint.yml b/.swiftlint.yml index e2fe687..fbe731e 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -81,6 +81,7 @@ identifier_name: - db - _db - iq + - xa # Disable rules from the default enabled set. disabled_rules: diff --git a/AnotherXMPP/XMPPClient.swift b/AnotherXMPP/XMPPClient.swift index 0e07127..e7759b9 100644 --- a/AnotherXMPP/XMPPClient.swift +++ b/AnotherXMPP/XMPPClient.swift @@ -43,6 +43,7 @@ enum Event { case streamReady case requestRoster + case rosterRequestDone case addRosterItem(jidStr: String, args: [String: String]) case updateRosterItem(jidStr: String, args: [String: String]) case deleteRosterItem(jidStr: String) diff --git a/AnotherXMPP/models/Presence.swift b/AnotherXMPP/models/Presence.swift new file mode 100644 index 0000000..911e90c --- /dev/null +++ b/AnotherXMPP/models/Presence.swift @@ -0,0 +1,28 @@ +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/modules/presence/PresenceModule.swift b/AnotherXMPP/modules/presence/PresenceModule.swift index 964777a..700b42c 100644 --- a/AnotherXMPP/modules/presence/PresenceModule.swift +++ b/AnotherXMPP/modules/presence/PresenceModule.swift @@ -16,7 +16,16 @@ final class PresenceModule: XmppModule { oldState } - func process(state _: ClientState, with _: Event) async -> Event? { - nil + func process(state _: ClientState, with event: Event) async -> Event? { + switch event { + case .rosterRequestDone: + return nil + + case .stanzaInbound(let stanza): + return nil + + default: + return nil + } } } diff --git a/AnotherXMPP/modules/roster/RosterModule.swift b/AnotherXMPP/modules/roster/RosterModule.swift index b86b0fd..9e117c9 100644 --- a/AnotherXMPP/modules/roster/RosterModule.swift +++ b/AnotherXMPP/modules/roster/RosterModule.swift @@ -130,6 +130,10 @@ final class RosterModule: XmppModule { return nil } + // when roster requested, also raise .done event + case .rosterRequestDone: + return .rosterUpdated + default: return nil } @@ -220,7 +224,7 @@ private extension RosterModule { // save roster guard let data = try? JSONEncoder().encode(existItems.map { $0.wrapped }) else { return nil } await storage?.setRoster(jid: state.jid, roster: data) - return .rosterUpdated + return .rosterRequestDone // for result of one of our request case .iq(.set):