tochie-facade/scenes/Stanza.gd
2023-09-02 20:33:41 +05:00

51 lines
1.8 KiB
GDScript

extends Node
class_name Stanza
const disco_info_queury := "<query xmlns='http://jabber.org/protocol/disco#info'/>"
const disco_items_queury := "<query xmlns='http://jabber.org/protocol/disco#items'/>"
static func yield_as_is():
return yield()
static func unwrap_query_result(iq: Xml.XmlElement) -> Sums.Result:
if iq == null or iq.name != "iq" or not "type" in iq.attributes:
return Sums.Result.make_error(ERR_INVALID_DATA)
# todo: Delegate strctured XMPP error.
if iq.attributes["type"] != "result":
return Sums.Result.make_error(ERR_INVALID_DATA)
for child in iq.children:
if child.is_element() and child.name == "query":
return Sums.Result.make_value(child)
return Sums.Result.make_error(ERR_INVALID_DATA)
static func form_presence(id: String, from: String, to: String, type, payload: String) -> String:
if type != null:
return """<presence from='{from}' id='{id}' to='{to}' type='{type}'>{payload}</presence>""".format({
"from": from.xml_escape(),
"id": id.xml_escape(),
"to": to.xml_escape(),
"type": type,
"payload": payload
})
else:
return """<presence from='{from}' id='{id}' to='{to}'>{payload}</presence>""".format({
"from": from.xml_escape(),
"id": id.xml_escape(),
"to": to.xml_escape(),
"payload": payload
})
static func presence_result(stanza: Xml.XmlElement) -> Sums.Result:
if "type" in stanza.attributes and stanza.attributes["type"] == "error":
return Sums.Result.make_error(stanza)
else:
return Sums.Result.make_value(stanza)
static func extract_resource_part(jid: String) -> String:
var parts = jid.rsplit("/")
assert(parts.size() > 0)
return parts[parts.size() - 1]