configure method

Future<Result<PubSubError, bool>> configure(
  1. JID jid,
  2. String node,
  3. PubSubPublishOptions options
)

Implementation

Future<Result<PubSubError, bool>> configure(
  JID jid,
  String node,
  PubSubPublishOptions options,
) async {
  final attrs = getAttributes();

  // Request the form
  final form = (await attrs.sendStanza(
    StanzaDetails(
      Stanza.iq(
        type: 'get',
        to: jid.toString(),
        children: [
          XMLNode.xmlns(
            tag: 'pubsub',
            xmlns: pubsubOwnerXmlns,
            children: [
              XMLNode(
                tag: 'configure',
                attributes: <String, String>{
                  'node': node,
                },
              ),
            ],
          ),
        ],
      ),
      shouldEncrypt: false,
    ),
  ))!;
  if (form.attributes['type'] != 'result') {
    return Result(getPubSubError(form));
  }

  final submit = (await attrs.sendStanza(
    StanzaDetails(
      Stanza.iq(
        type: 'set',
        to: jid.toString(),
        children: [
          XMLNode.xmlns(
            tag: 'pubsub',
            xmlns: pubsubOwnerXmlns,
            children: [
              XMLNode(
                tag: 'configure',
                attributes: <String, String>{
                  'node': node,
                },
                children: [
                  options.toXml(),
                ],
              ),
            ],
          ),
        ],
      ),
      shouldEncrypt: false,
    ),
  ))!;
  if (submit.attributes['type'] != 'result') {
    return Result(getPubSubError(form));
  }

  return const Result(true);
}