Search in sources :

Example 1 with EasyOnboardingInvite

use of eu.siacs.conversations.utils.EasyOnboardingInvite in project Conversations by siacs.

the class XmppConnectionService method requestEasyOnboardingInvite.

public void requestEasyOnboardingInvite(final Account account, final EasyOnboardingInvite.OnInviteRequested callback) {
    final XmppConnection connection = account.getXmppConnection();
    final Jid jid = connection == null ? null : connection.getJidForCommand(Namespace.EASY_ONBOARDING_INVITE);
    if (jid == null) {
        callback.inviteRequestFailed(getString(R.string.server_does_not_support_easy_onboarding_invites));
        return;
    }
    final IqPacket request = new IqPacket(IqPacket.TYPE.SET);
    request.setTo(jid);
    final Element command = request.addChild("command", Namespace.COMMANDS);
    command.setAttribute("node", Namespace.EASY_ONBOARDING_INVITE);
    command.setAttribute("action", "execute");
    sendIqPacket(account, request, (a, response) -> {
        if (response.getType() == IqPacket.TYPE.RESULT) {
            final Element resultCommand = response.findChild("command", Namespace.COMMANDS);
            final Element x = resultCommand == null ? null : resultCommand.findChild("x", Namespace.DATA);
            if (x != null) {
                final Data data = Data.parse(x);
                final String uri = data.getValue("uri");
                final String landingUrl = data.getValue("landing-url");
                if (uri != null) {
                    final EasyOnboardingInvite invite = new EasyOnboardingInvite(jid.getDomain().toEscapedString(), uri, landingUrl);
                    callback.inviteRequested(invite);
                    return;
                }
            }
            callback.inviteRequestFailed(getString(R.string.unable_to_parse_invite));
            Log.d(Config.LOGTAG, response.toString());
        } else if (response.getType() == IqPacket.TYPE.ERROR) {
            callback.inviteRequestFailed(IqParser.errorMessage(response));
        } else {
            callback.inviteRequestFailed(getString(R.string.remote_server_timeout));
        }
    });
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) EasyOnboardingInvite(eu.siacs.conversations.utils.EasyOnboardingInvite) Jid(eu.siacs.conversations.xmpp.Jid) Element(eu.siacs.conversations.xml.Element) Data(eu.siacs.conversations.xmpp.forms.Data) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Aggregations

EasyOnboardingInvite (eu.siacs.conversations.utils.EasyOnboardingInvite)1 Element (eu.siacs.conversations.xml.Element)1 Jid (eu.siacs.conversations.xmpp.Jid)1 XmppConnection (eu.siacs.conversations.xmpp.XmppConnection)1 Data (eu.siacs.conversations.xmpp.forms.Data)1 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)1