getAllLists method

Future<PrivacyLists> getAllLists()

Implementation

Future<PrivacyLists> getAllLists() {
  if (!isPrivacyListsSupported()) {
    return Future.error(Exception(feature_not_supported_error));
  }

  var completer = Completer<PrivacyLists>();

  var iqStanza = IqStanza(AbstractStanza.getRandomId(), IqStanzaType.GET)
    ..fromJid = _connection.fullJid;

  var queryStanza = QueryElement();
  queryStanza.setXmlns('jabber:iq:privacy');
  iqStanza.addChild(queryStanza);

  _unrespondedStanzas[iqStanza.id!] = Tuple2((resultStanza) {
    var result = PrivacyLists()..allPrivacyLists = [];

    var queryElement = resultStanza.getChild('query');
    queryElement?.children.forEach((listElement) {
      if (listElement.name == 'active') {
        result.activeList = listElement.getAttribute('name')?.value;
      } else if (listElement.name == 'default') {
        result.defaultList = listElement.getAttribute('name')?.value;
      } else if (listElement.name == 'list') {
        result.allPrivacyLists!
            .add(listElement.getAttribute('name')?.value ?? 'unknown');
      }
    });

    return result;
  }, completer);

  _connection.writeStanza(iqStanza);

  return completer.future;
}