extends Reference class_name MucService ## https://xmpp.org/extensions/xep-0045.html class MucRoom extends Reference: var jid: String var name: String func as_string() -> String: return "MucRoom \"%s\", Jid: \"%s\"" % [name, jid] var jid: String var _connection: Connections.Connection var _rooms_promise: Sums.Promise = null func try_init(connection: Connections.Connection, p_jid: String, disco_info: Xml.XmlElement): var is_muc := false for item in disco_info.children: if item.is_element() and item.name == "feature": if item.attributes["var"] == "http://jabber.org/protocol/muc": is_muc = true break if not is_muc: return null self.jid = p_jid self._connection = connection return self func request_rooms() -> Sums.Promise: if self._rooms_promise != null: return self._rooms_promise self._rooms_promise = _connection.promise_iq( jid, "get", Stanza.disco_items_queury, _iq_rooms()) return self._rooms_promise func _iq_rooms(): var response = yield() if not response.is_ok: return response var query := Stanza.unwrap_query_result(response.value) if not query.is_ok: return query var rooms := Array() for item in query.value.children: if item.is_element() and item.name == "item": var muc_room := MucRoom.new() muc_room.jid = item.attributes["jid"] muc_room.name = item.attributes["name"] rooms.push_back(muc_room) return Sums.Result.make_value(rooms)