wip
This commit is contained in:
parent
e3ee92d87d
commit
b8a86a17bf
|
@ -45,7 +45,7 @@ final class RosterModule: XmppModule {
|
||||||
case .stanzaInbound(let stanza):
|
case .stanzaInbound(let stanza):
|
||||||
if let query = stanza.wrapped.nodes.first(where: { $0.name == "query" }), query.xmlns == "jabber:iq:roster" {
|
if let query = stanza.wrapped.nodes.first(where: { $0.name == "query" }), query.xmlns == "jabber:iq:roster" {
|
||||||
if stanza.type == .iq(.set) {
|
if stanza.type == .iq(.set) {
|
||||||
return processSet(state: state, stanza: stanza)
|
return await processSet(state: state, stanza: stanza)
|
||||||
} else if stanza.type == .iq(.result) {
|
} else if stanza.type == .iq(.result) {
|
||||||
return processResult(state: state, stanza: stanza)
|
return processResult(state: state, stanza: stanza)
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,6 +61,13 @@ 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 extension RosterModule {
|
||||||
private func update(jidStr: String, args: [String: String]) -> Event? {
|
private func update(jidStr: String, args: [String: String]) -> Event? {
|
||||||
print(jidStr, args)
|
print(jidStr, args)
|
||||||
|
@ -72,13 +79,35 @@ private extension RosterModule {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
private func processSet(state: ClientState, stanza: Stanza) -> Event? {
|
private func processSet(state: ClientState, stanza: Stanza) async -> Event? {
|
||||||
// sanity check
|
// sanity check
|
||||||
if stanza.wrapped.attributes["from"] != state.jid.bare {
|
if stanza.wrapped.attributes["from"] != state.jid.bare {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get exists roster items
|
||||||
|
var existItems: [RosterItem] = []
|
||||||
|
if let data = await storage?.getRoster(jid: state.jid), let decoded = try? JSONDecoder().decode([XMLElement].self, from: data) {
|
||||||
|
existItems = decoded.compactMap { RosterItem(wrap: $0, owner: state.jid) }
|
||||||
|
}
|
||||||
|
|
||||||
// process
|
// process
|
||||||
|
let items = stanza.wrapped
|
||||||
|
.nodes
|
||||||
|
.first(where: { $0.name == "query" })?
|
||||||
|
.nodes
|
||||||
|
.filter { $0.name == "item" } ?? []
|
||||||
|
for item in items {
|
||||||
|
guard let itemJidStr = item.attributes["jid"], let itemJid = try? JID(itemJidStr) else { continue }
|
||||||
|
let subscription = item.attributes["subscription"]
|
||||||
|
switch subscription {
|
||||||
|
case "remove":
|
||||||
|
existItems = existItems.filter { $0.jid == itemJid }
|
||||||
|
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// according to RFC-6121 a set from server (push)
|
// according to RFC-6121 a set from server (push)
|
||||||
// shouyld be answered with result
|
// shouyld be answered with result
|
||||||
|
|
Loading…
Reference in a new issue