wip
This commit is contained in:
parent
6d669f924d
commit
dbcd071b92
|
@ -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()
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue