wip
This commit is contained in:
parent
b8a86a17bf
commit
fd1fb2860f
|
@ -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) {
|
||||
|
|
22
AnotherXMPP/modules/presence/PresenceModule.swift
Normal file
22
AnotherXMPP/modules/presence/PresenceModule.swift
Normal file
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue