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));
}
});
}
Aggregations