offer to open website if ibb offers oob redirect. fixes #2503

This commit is contained in:
Daniel Gultsch 2017-06-19 20:02:41 +02:00
parent 95405fde5f
commit 5d9d725446
4 changed files with 58 additions and 9 deletions

View file

@ -115,6 +115,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),
@ -164,6 +165,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:

View file

@ -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) {
@ -437,7 +451,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);
}
}
}
}

View file

@ -40,6 +40,7 @@ import java.util.List;
import java.util.Map.Entry;
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;
@ -67,6 +68,7 @@ import eu.siacs.conversations.generator.IqGenerator;
import eu.siacs.conversations.services.NotificationService;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.DNSHelper;
import eu.siacs.conversations.utils.Patterns;
import eu.siacs.conversations.utils.SSLSocketHelper;
import eu.siacs.conversations.utils.SocksSocketFactory;
import eu.siacs.conversations.xml.Element;
@ -137,6 +139,7 @@ public class XmppConnection implements Runnable {
private final XmppConnectionService mXmppConnectionService;
private SaslMechanism saslMechanism;
private String webRegistrationUrl = null;
private class MyKeyManager implements X509KeyManager {
@Override
@ -438,7 +441,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");
}
}
}
@ -976,19 +979,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() {
@ -996,6 +1018,7 @@ public class XmppConnection implements Runnable {
resetStreamId();
clearIqCallbacks();
mStanzaQueue.clear();
this.webRegistrationUrl = null;
synchronized (this.disco) {
disco.clear();
}

View file

@ -749,4 +749,7 @@
<string name="retry_decryption">Retry decryption</string>
<string name="session_failure">Session failure</string>
<string name="sasl_downgrade">Downgraded SASL mechanism</string>
<string name="account_status_regis_web">Server requires registration on website</string>
<string name="open_website">Open website</string>
<string name="application_found_to_open_website">No application found to open website</string>
</resources>