# subscribe method

Future <Result<PubSubError, bool>> subscribe(

1. JID jid,
2. String node

)

## Implementation

    Future<Result<PubSubError, bool>> subscribe(JID jid, String node) async {
      final attrs = getAttributes();
      final result = (await attrs.sendStanza(
        StanzaDetails(
          Stanza.iq(
            type: 'set',
            to: jid.toString(),
            children: [
              XMLNode.xmlns(
                tag: 'pubsub',
                xmlns: pubsubXmlns,
                children: [
                  XMLNode(
                    tag: 'subscribe',
                    attributes: <String, String>{
                      'node': node,
                      'jid': attrs.getFullJID().toBare().toString(),
                    },
                  ),
                ],
              ),
            ],
          ),
          shouldEncrypt: false,
        ),
      ))!;

      if (result.attributes['type'] != 'result') {
        return Result(UnknownPubSubError());
      }

      final pubsub = result.firstTag('pubsub', xmlns: pubsubXmlns);
      if (pubsub == null) {
        return Result(UnknownPubSubError());
      }

      final subscription = pubsub.firstTag('subscription');
      if (subscription == null) {
        return Result(UnknownPubSubError());
      }

      return Result(subscription.attributes['subscription'] == 'subscribed');
    }