From fd1fb2860f02f3c04fcec8b491d293bac327051b Mon Sep 17 00:00:00 2001 From: fmodf Date: Thu, 26 Dec 2024 14:12:19 +0100 Subject: [PATCH] wip --- AnotherXMPP/XMPPClient.swift | 3 ++- .../modules/presence/PresenceModule.swift | 22 +++++++++++++++++++ AnotherXMPP/modules/roster/RosterModule.swift | 18 ++++++++------- 3 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 AnotherXMPP/modules/presence/PresenceModule.swift diff --git a/AnotherXMPP/XMPPClient.swift b/AnotherXMPP/XMPPClient.swift index 575d84a..a9e3afb 100644 --- a/AnotherXMPP/XMPPClient.swift +++ b/AnotherXMPP/XMPPClient.swift @@ -104,7 +104,8 @@ public final class XMPPClient { AuthorizationModule(self.storage), StanzaModule(self.storage), DiscoveryModule(), - RosterModule(self.storage) + RosterModule(self.storage), + PresenceModule() ] public init(storage: any XMPPStorage, userAgent: UserAgent) { diff --git a/AnotherXMPP/modules/presence/PresenceModule.swift b/AnotherXMPP/modules/presence/PresenceModule.swift new file mode 100644 index 0000000..964777a --- /dev/null +++ b/AnotherXMPP/modules/presence/PresenceModule.swift @@ -0,0 +1,22 @@ +import Foundation + +// NSString* const kSubBoth = @"both"; +// NSString* const kSubNone = @"none"; +// NSString* const kSubTo = @"to"; +// NSString* const kSubFrom = @"from"; +// NSString* const kSubRemove = @"remove"; +// NSString* const kAskSubscribe = @"subscribe"; + +// TODO: Cancel subscr. request when contact deleted from roster +// Update when server sends roster push also +final class PresenceModule: XmppModule { + let id = "Presence module" + + func reduce(oldState: ClientState, with _: Event) -> ClientState { + oldState + } + + func process(state _: ClientState, with _: Event) async -> Event? { + nil + } +} diff --git a/AnotherXMPP/modules/roster/RosterModule.swift b/AnotherXMPP/modules/roster/RosterModule.swift index 9c23ff3..01b3049 100644 --- a/AnotherXMPP/modules/roster/RosterModule.swift +++ b/AnotherXMPP/modules/roster/RosterModule.swift @@ -61,13 +61,6 @@ final class RosterModule: XmppModule { } } -// NSString* const kSubBoth = @"both"; -// NSString* const kSubNone = @"none"; -// NSString* const kSubTo = @"to"; -// NSString* const kSubFrom = @"from"; -// NSString* const kSubRemove = @"remove"; -// NSString* const kAskSubscribe = @"subscribe"; - private extension RosterModule { private func update(jidStr: String, args: [String: String]) -> Event? { print(jidStr, args) @@ -105,10 +98,19 @@ private extension RosterModule { existItems = existItems.filter { $0.jid == itemJid } default: - continue + if let rosterItem = RosterItem(wrap: item, owner: state.jid) { + existItems = existItems.filter { $0.jid == itemJid } + existItems.append(rosterItem) + } else { + continue + } } } + // save roster + guard let data = try? JSONEncoder().encode(existItems.map { $0.wrapped }) else { return nil } + await storage?.setRoster(jid: state.jid, roster: data) + // according to RFC-6121 a set from server (push) // shouyld be answered with result guard