diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-06-24 09:40:53 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-06-24 09:40:53 +0200 |
commit | 8e897c3d69d65155a2fa7a4ce75bfc5bc13d7233 (patch) | |
tree | e12795cc9f61bb711d6de65736226535d576091b /src/main/java/de/pixart | |
parent | 3af45f570aafbcaeffd93b45a5b4e7a2bdcfeeb8 (diff) |
offer to open website if ibb offers oob redirect
Diffstat (limited to '')
3 files changed, 55 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Account.java b/src/main/java/de/pixart/messenger/entities/Account.java index 437dfa47a..872035af0 100644 --- a/src/main/java/de/pixart/messenger/entities/Account.java +++ b/src/main/java/de/pixart/messenger/entities/Account.java @@ -117,6 +117,7 @@ public class Account extends AbstractEntity { UNAUTHORIZED(true), SERVER_NOT_FOUND(true), REGISTRATION_FAILED(true), + REGISTRATION_WEB(true), REGISTRATION_CONFLICT(true), REGISTRATION_SUCCESSFUL, REGISTRATION_NOT_SUPPORTED(true), @@ -166,6 +167,8 @@ public class Account extends AbstractEntity { return R.string.account_status_no_internet; case REGISTRATION_FAILED: return R.string.account_status_regis_fail; + case REGISTRATION_WEB: + return R.string.account_status_regis_web; case REGISTRATION_CONFLICT: return R.string.account_status_regis_conflict; case REGISTRATION_SUCCESSFUL: diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 320823120..e64322ac9 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -129,6 +129,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat public void onClick(final View v) { final String password = mPassword.getText().toString(); final String passwordConfirm = mPasswordConfirm.getText().toString(); + final boolean wasDisabled = mAccount != null && mAccount.getStatus() == Account.State.DISABLED; if (!mInitMode && passwordChangedInMagicCreateMode()) { gotoChangePassword(password); @@ -150,6 +151,19 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat mAccountJid.requestFocus(); return; } + + XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection(); + String url = connection != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB ? connection.getWebRegistrationUrl() : null; + if (url != null && registerNewAccount && !wasDisabled) { + try { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); + return; + } catch (ActivityNotFoundException e) { + Toast.makeText(EditAccountActivity.this, R.string.application_found_to_open_website, Toast.LENGTH_SHORT); + return; + } + } + final Jid jid; try { if (mUsernameMode) { @@ -444,7 +458,13 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.mSaveButton.setText(R.string.connect); } } else { - this.mSaveButton.setText(R.string.next); + XmppConnection connection = mAccount == null ? null : mAccount.getXmppConnection(); + String url = connection != null && mAccount.getStatus() == Account.State.REGISTRATION_WEB ? connection.getWebRegistrationUrl() : null; + if (url != null && mRegisterNew.isChecked()) { + this.mSaveButton.setText(R.string.open_website); + } else { + this.mSaveButton.setText(R.string.next); + } } } } diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index 09b90b3ba..f3ce20da3 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -41,6 +41,7 @@ import java.util.Map.Entry; import java.util.Random; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import java.util.regex.Matcher; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.KeyManager; @@ -70,6 +71,7 @@ import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.ui.EditAccountActivity; import de.pixart.messenger.utils.DNSHelper; import de.pixart.messenger.utils.Namespace; +import de.pixart.messenger.utils.Patterns; import de.pixart.messenger.utils.SSLSocketHelper; import de.pixart.messenger.utils.SocksSocketFactory; import de.pixart.messenger.xml.Element; @@ -141,6 +143,7 @@ public class XmppConnection implements Runnable { private EditAccountActivity mEditAccountActivity = null; private SaslMechanism saslMechanism; + private String webRegistrationUrl = null; private class MyKeyManager implements X509KeyManager { @Override @@ -467,8 +470,7 @@ public class XmppConnection implements Runnable { } } } else { - Log.d(Config.LOGTAG,account.getJid().toBareJid()+": not force closing socket and releasing wake lock because thread was interrupted"); - + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": not force closing socket and releasing wake lock (is held=" + wakeLock.isHeld() + ") because thread was interrupted"); } } } @@ -1006,19 +1008,38 @@ public class XmppConnection implements Runnable { } if (failed) { - final Element instructions = packet.query().findChild("instructions"); - setAccountCreationFailed((instructions != null) ? instructions.getContent() : ""); + final Element query = packet.query(); + final String instructions = query.findChildContent("instructions"); + final Element oob = query.findChild("x", Namespace.OOB); + final String url = oob == null ? null : oob.findChildContent("url"); + if (url == null && instructions != null) { + Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(instructions); + if (matcher.find()) { + setAccountCreationFailed(instructions.substring(matcher.start(), matcher.end())); + } else { + setAccountCreationFailed(null); + } + } else { + setAccountCreationFailed(url); + } } } }); } - private void setAccountCreationFailed(String instructions) { - changeStatus(Account.State.REGISTRATION_FAILED); + private void setAccountCreationFailed(String url) { + if (url != null && (url.toLowerCase().startsWith("http://") || url.toLowerCase().startsWith("https://"))) { + changeStatus(Account.State.REGISTRATION_WEB); + this.webRegistrationUrl = url; + } else { + changeStatus(Account.State.REGISTRATION_FAILED); + } disconnect(true); - Log.d(Config.LOGTAG, account.getJid().toBareJid() - + ": could not register. instructions are" - + instructions); + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not register. url=" + url); + } + + public String getWebRegistrationUrl() { + return this.webRegistrationUrl; } public void resetEverything() { @@ -1026,6 +1047,7 @@ public class XmppConnection implements Runnable { resetStreamId(); clearIqCallbacks(); mStanzaQueue.clear(); + this.webRegistrationUrl = null; synchronized (this.disco) { disco.clear(); } |