This commit is contained in:
fmodf 2025-01-09 17:04:09 +01:00
parent 6d669f924d
commit dbcd071b92
3 changed files with 45 additions and 12 deletions

View file

@ -31,14 +31,14 @@ struct TestScreen: View {
.background { Color.blue.opacity(0.4) } .background { Color.blue.opacity(0.4) }
} }
Button { Button {
cls.addContact(jidStr: "asdadad@asdfsdf.df") cls.addContact(jidStr: "asdadad22@asdfsdf.df", name: "bobob")
} label: { } label: {
Text("Add contact") Text("Add contact")
.padding() .padding()
.background { Color.blue.opacity(0.4) } .background { Color.blue.opacity(0.4) }
} }
Button { Button {
cls.deleteContact(jidStr: "asdadad@asdfsdf.df") cls.deleteContact(jidStr: "asdadad11@asdfsdf.df")
} label: { } label: {
Text("Remove contact") Text("Remove contact")
.padding() .padding()

View file

@ -123,9 +123,13 @@ public extension XMPPClient {
} }
} }
func addContact(jidStr: String) { func addContact(jidStr: String, name: String? = nil) {
Task { Task {
await fire(.addRosterItem(jidStr: jidStr, args: [:])) var args: [String: String] = [:]
if let name {
args["name"] = name
}
await fire(.addRosterItem(jidStr: jidStr, args: args))
} }
} }

View file

@ -6,7 +6,6 @@ final class RosterModule: XmppModule {
let id = "Roseter module" let id = "Roseter module"
private weak var storage: (any XMPPStorage)? private weak var storage: (any XMPPStorage)?
private var fullReqId = ""
private var isVerSupported = false private var isVerSupported = false
init(_ storage: any XMPPStorage) { init(_ storage: any XMPPStorage) {
@ -47,20 +46,43 @@ final class RosterModule: XmppModule {
) )
) )
if let req { if let req {
fullReqId = req.id ?? "???"
return .stanzaOutbound(req) return .stanzaOutbound(req)
} else { } else {
return nil return nil
} }
case .addRosterItem(let jidStr, let args): case .addRosterItem(let jidStr, let args), .updateRosterItem(let jidStr, let args):
return await update(state: state, jidStr: jidStr, args: args) var attr = ["jid": jidStr]
if let name = args["name"] {
case .updateRosterItem(let jidStr, let args): attr["name"] = name
return await update(state: state, jidStr: jidStr, args: args) }
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): case .deleteRosterItem(let jidStr):
return await delete(state: state, jidStr: jidStr) return nil
// return await delete(state: state, jidStr: jidStr)
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" {
@ -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 extension RosterModule {
// private func update(state: ClientState, jidStr: String, args: [String: String]) async -> Event? { // private func update(state: ClientState, jidStr: String, args: [String: String]) async -> Event? {
// print(state, jidStr, args) // print(state, jidStr, args)