From da1edafd495b82a0a9b176f7718cd3fe7b334521 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 16 Aug 2016 10:39:59 +0200 Subject: add payment required error --- src/main/java/de/pixart/messenger/entities/Account.java | 5 ++++- .../java/de/pixart/messenger/xmpp/XmppConnection.java | 17 ++++++++++++++++- src/main/res/values/strings.xml | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/pixart/messenger/entities/Account.java b/src/main/java/de/pixart/messenger/entities/Account.java index 8c9ed51f2..333bb58c9 100644 --- a/src/main/java/de/pixart/messenger/entities/Account.java +++ b/src/main/java/de/pixart/messenger/entities/Account.java @@ -110,7 +110,8 @@ public class Account extends AbstractEntity { REGISTRATION_PLEASE_WAIT(true), STREAM_ERROR(true), POLICY_VIOLATION(true), - REGISTRATION_PASSWORD_TOO_WEAK(true); + REGISTRATION_PASSWORD_TOO_WEAK(true), + PAYMENT_REQUIRED(true); private final boolean isError; @@ -168,6 +169,8 @@ public class Account extends AbstractEntity { return R.string.registration_password_too_weak; case STREAM_ERROR: return R.string.account_status_stream_error; + case PAYMENT_REQUIRED: + return R.string.payment_required; default: return R.string.account_status_unknown; } diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index 9af0a0eb3..081f8975c 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -397,6 +397,8 @@ public class XmppConnection implements Runnable { this.changeStatus(Account.State.SECURITY_ERROR); } catch (final UnauthorizedException e) { this.changeStatus(Account.State.UNAUTHORIZED); + } catch (final PaymentRequiredException e) { + this.changeStatus(Account.State.PAYMENT_REQUIRED); } catch (final UnknownHostException | ConnectException e) { this.changeStatus(Account.State.SERVER_NOT_FOUND); } catch (final SocksSocketFactory.SocksProxyNotFoundException e) { @@ -518,7 +520,16 @@ public class XmppConnection implements Runnable { } break; } else if (nextTag.isStart("failure")) { - throw new UnauthorizedException(); + final Element failure = tagReader.readElement(nextTag); + final String accountDisabled = failure.findChildContent("account-disabled"); + if (accountDisabled != null + && accountDisabled.contains("renew") + && Config.MAGIC_CREATE_DOMAIN != null + && accountDisabled.contains(Config.MAGIC_CREATE_DOMAIN)) { + throw new PaymentRequiredException(); + } else { + throw new UnauthorizedException(); + } } else if (nextTag.isStart("challenge")) { final String challenge = tagReader.readElement(nextTag).getContent(); final Element response = new Element("response"); @@ -1548,6 +1559,10 @@ public class XmppConnection implements Runnable { } + private class PaymentRequiredException extends IOException { + + } + public enum Identity { FACEBOOK, SLACK, diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index b2aaaf2c9..baec6bad6 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -685,4 +685,5 @@ Backup will be imported, this may take awhile. Enable an export of chat logs as human readable text files Export human readable chat logs + Payment required -- cgit v1.2.3