diff --git a/AnotherIM/View/TestScreen.swift b/AnotherIM/View/TestScreen.swift index 433204d..80dc5c5 100644 --- a/AnotherIM/View/TestScreen.swift +++ b/AnotherIM/View/TestScreen.swift @@ -31,14 +31,14 @@ struct TestScreen: View { .background { Color.blue.opacity(0.4) } } Button { - cls.addContact(jidStr: "asdadad@asdfsdf.df") + cls.addContact(jidStr: "asdadad22@asdfsdf.df", name: "bobob") } label: { Text("Add contact") .padding() .background { Color.blue.opacity(0.4) } } Button { - cls.deleteContact(jidStr: "asdadad@asdfsdf.df") + cls.deleteContact(jidStr: "asdadad11@asdfsdf.df") } label: { Text("Remove contact") .padding() diff --git a/AnotherXMPP/XMPPClient.swift b/AnotherXMPP/XMPPClient.swift index a9e3afb..0e07127 100644 --- a/AnotherXMPP/XMPPClient.swift +++ b/AnotherXMPP/XMPPClient.swift @@ -123,9 +123,13 @@ public extension XMPPClient { } } - func addContact(jidStr: String) { + func addContact(jidStr: String, name: String? = nil) { Task { - await fire(.addRosterItem(jidStr: jidStr, args: [:])) + var args: [String: String] = [:] + if let name { + args["name"] = name + } + await fire(.addRosterItem(jidStr: jidStr, args: args)) } } diff --git a/AnotherXMPP/modules/roster/RosterModule.swift b/AnotherXMPP/modules/roster/RosterModule.swift index bcddec0..410d818 100644 --- a/AnotherXMPP/modules/roster/RosterModule.swift +++ b/AnotherXMPP/modules/roster/RosterModule.swift @@ -6,7 +6,6 @@ final class RosterModule: XmppModule { let id = "Roseter module" private weak var storage: (any XMPPStorage)? - private var fullReqId = "" private var isVerSupported = false init(_ storage: any XMPPStorage) { @@ -47,20 +46,43 @@ final class RosterModule: XmppModule { ) ) if let req { - fullReqId = req.id ?? "???" return .stanzaOutbound(req) } else { return nil } - case .addRosterItem(let jidStr, let args): - return await update(state: state, jidStr: jidStr, args: args) - - case .updateRosterItem(let jidStr, let args): - return await update(state: state, jidStr: jidStr, args: args) + case .addRosterItem(let jidStr, let args), .updateRosterItem(let jidStr, let args): + var attr = ["jid": jidStr] + if let name = args["name"] { + attr["name"] = name + } + let req = Stanza.iqSet( + from: state.jid.full, + payload: XMLElement( + name: "query", + xmlns: "jabber:iq:roster", + attributes: [:], + content: nil, + nodes: [ + XMLElement( + name: "item", + xmlns: nil, + attributes: attr, + content: nil, + nodes: [] + ) + ] + ) + ) + if let req { + return .stanzaOutbound(req) + } else { + return nil + } case .deleteRosterItem(let jidStr): - return await delete(state: state, jidStr: jidStr) + return nil + // return await delete(state: state, jidStr: jidStr) case .stanzaInbound(let stanza): if let query = stanza.wrapped.nodes.first(where: { $0.name == "query" }), query.xmlns == "jabber:iq:roster" { @@ -91,6 +113,13 @@ final class RosterModule: XmppModule { } } +private extension RosterModule { + private func sendUpdate(state: ClientState, jidStr: String, args: [String: String]) async -> Event? { + print(state, jidStr, args) + return nil + } +} + // private extension RosterModule { // private func update(state: ClientState, jidStr: String, args: [String: String]) async -> Event? { // print(state, jidStr, args)