refactor captcha response handling to avoid network on main thread exception
This commit is contained in:
parent
8a81f85734
commit
12704fa640
|
@ -303,8 +303,10 @@ public class IqGenerator extends AbstractGenerator {
|
|||
|
||||
register.setTo(account.getServer());
|
||||
register.setId(id);
|
||||
register.query("jabber:iq:register").addChild(data);
|
||||
|
||||
Element query = register.query("jabber:iq:register");
|
||||
if (data != null) {
|
||||
query.addChild(data);
|
||||
}
|
||||
return register;
|
||||
}
|
||||
|
||||
|
|
|
@ -3002,9 +3002,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||
}
|
||||
|
||||
public void sendCreateAccountWithCaptchaPacket(Account account, String id, Data data) {
|
||||
XmppConnection connection = account.getXmppConnection();
|
||||
final XmppConnection connection = account.getXmppConnection();
|
||||
if (connection != null) {
|
||||
connection.sendCaptchaRegistryRequest(id, data);
|
||||
IqPacket request = mIqGenerator.generateCreateAccountWithCaptcha(account, id, data);
|
||||
sendIqPacket(account, request, connection.registrationResponseListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -176,18 +176,15 @@ public class XmppConnection implements Runnable {
|
|||
};
|
||||
private Identity mServerIdentity = Identity.UNKNOWN;
|
||||
|
||||
private OnIqPacketReceived createPacketReceiveHandler() {
|
||||
return new OnIqPacketReceived() {
|
||||
public final OnIqPacketReceived registrationResponseListener = new OnIqPacketReceived() {
|
||||
@Override
|
||||
public void onIqPacketReceived(Account account, IqPacket packet) {
|
||||
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
||||
account.setOption(Account.OPTION_REGISTER,
|
||||
false);
|
||||
account.setOption(Account.OPTION_REGISTER, false);
|
||||
forceCloseSocket();
|
||||
changeStatus(Account.State.REGISTRATION_SUCCESSFUL);
|
||||
} else if (packet.hasChild("error")
|
||||
&& (packet.findChild("error")
|
||||
.hasChild("conflict"))) {
|
||||
&& (packet.findChild("error").hasChild("conflict"))) {
|
||||
forceCloseSocket();
|
||||
changeStatus(Account.State.REGISTRATION_CONFLICT);
|
||||
} else {
|
||||
|
@ -197,7 +194,6 @@ public class XmppConnection implements Runnable {
|
|||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public XmppConnection(final Account account, final XmppConnectionService service) {
|
||||
this.account = account;
|
||||
|
@ -809,15 +805,6 @@ public class XmppConnection implements Runnable {
|
|||
return mechanisms;
|
||||
}
|
||||
|
||||
public void sendCaptchaRegistryRequest(String id, Data data) {
|
||||
if (data == null) {
|
||||
setAccountCreationFailed("");
|
||||
} else {
|
||||
IqPacket request = getIqGenerator().generateCreateAccountWithCaptcha(account, id, data);
|
||||
sendIqPacket(request, createPacketReceiveHandler());
|
||||
}
|
||||
}
|
||||
|
||||
private void sendRegistryRequest() {
|
||||
final IqPacket register = new IqPacket(IqPacket.TYPE.GET);
|
||||
register.query("jabber:iq:register");
|
||||
|
@ -835,7 +822,7 @@ public class XmppConnection implements Runnable {
|
|||
final Element password = new Element("password").setContent(account.getPassword());
|
||||
register.query("jabber:iq:register").addChild(username);
|
||||
register.query().addChild(password);
|
||||
sendIqPacket(register, createPacketReceiveHandler());
|
||||
sendIqPacket(register, registrationResponseListener);
|
||||
} else if (packet.getType() == IqPacket.TYPE.RESULT
|
||||
&& (packet.query().hasChild("x", "jabber:x:data"))) {
|
||||
final Data data = Data.parse(packet.query().findChild("x", "jabber:x:data"));
|
||||
|
|
Loading…
Reference in a new issue