diff options
Diffstat (limited to 'src/main/java')
5 files changed, 57 insertions, 18 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java index 7085c7ba..b77d85c4 100644 --- a/src/main/java/eu/siacs/conversations/entities/Account.java +++ b/src/main/java/eu/siacs/conversations/entities/Account.java @@ -111,7 +111,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; @@ -169,6 +170,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/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 56739f40..3c00fd59 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -803,19 +803,18 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } public long getLastMessageTransmitted() { - long last_clear = getLastClearHistory(); - if (last_clear != 0) { - return last_clear; - } + final long last_clear = getLastClearHistory(); + long last_received = 0; synchronized (this.messages) { for(int i = this.messages.size() - 1; i >= 0; --i) { Message message = this.messages.get(i); if (message.getStatus() == Message.STATUS_RECEIVED || message.isCarbon()) { - return message.getTimeSent(); + last_received = message.getTimeSent(); + break; } } } - return 0; + return Math.max(last_clear,last_received); } public void setMutedTill(long value) { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 426c6f1a..2f5262de 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -193,15 +193,12 @@ public class XmppConnectionService extends Service { sendUnsentMessages(conversation); } } else { - if (contact.getPresences().size() >= 1) { - if (conversation.hasValidOtrSession()) { - String otrResource = conversation.getOtrSession().getSessionID().getUserID(); - if (!(Arrays.asList(contact.getPresences().toResourceArray()).contains(otrResource))) { - conversation.endOtrIfNeeded(); - } + //check if the resource we are haveing a conversation with is still online + if (conversation.hasValidOtrSession()) { + String otrResource = conversation.getOtrSession().getSessionID().getUserID(); + if (!(Arrays.asList(contact.getPresences().toResourceArray()).contains(otrResource))) { + conversation.endOtrIfNeeded(); } - } else { - conversation.endOtrIfNeeded(); } } } @@ -784,7 +781,12 @@ public class XmppConnectionService extends Service { restoreFromDatabase(); getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver); - this.fileObserver.startWatching(); + new Thread(new Runnable() { + @Override + public void run() { + fileObserver.startWatching(); + } + }).start(); if (Config.supportOpenPgp()) { this.pgpServiceConnection = new OpenPgpServiceConnection(getApplicationContext(), "org.sufficientlysecure.keychain", new OpenPgpServiceConnection.OnBound() { @Override diff --git a/src/main/java/eu/siacs/conversations/utils/ConversationsFileObserver.java b/src/main/java/eu/siacs/conversations/utils/ConversationsFileObserver.java index e6993bfe..ab4dead8 100644 --- a/src/main/java/eu/siacs/conversations/utils/ConversationsFileObserver.java +++ b/src/main/java/eu/siacs/conversations/utils/ConversationsFileObserver.java @@ -37,7 +37,10 @@ public abstract class ConversationsFileObserver { } for(File file : files) { if (file.isDirectory() && !file.getName().equals(".") && !file.getName().equals("..")) { - stack.push(file.getPath()); + final String currentPath = file.getAbsolutePath(); + if (depth(file) <= 8 && !stack.contains(currentPath) && !observing(currentPath)) { + stack.push(currentPath); + } } } } @@ -46,6 +49,23 @@ public abstract class ConversationsFileObserver { } } + private static int depth(File file) { + int depth = 0; + while((file = file.getParentFile()) != null) { + depth++; + } + return depth; + } + + private boolean observing(String path) { + for(SingleFileObserver observer : mObservers) { + if(path.equals(observer.path)) { + return true; + } + } + return false; + } + public synchronized void stopWatching() { for(FileObserver observer : mObservers) { observer.stopWatching(); diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 89ffa05d..6e36a546 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -384,6 +384,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) { @@ -505,7 +507,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"); @@ -1535,6 +1546,10 @@ public class XmppConnection implements Runnable { } + private class PaymentRequiredException extends IOException { + + } + public enum Identity { FACEBOOK, SLACK, |