diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services/XmppConnectionService.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 104 |
1 files changed, 74 insertions, 30 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 3bf1e745..774842a7 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -132,8 +132,8 @@ public class XmppConnectionService extends Service { public static final String ACTION_REPLY_TO_CONVERSATION = "reply_to_conversations"; public static final String ACTION_CLEAR_NOTIFICATION = "clear_notification"; public static final String ACTION_DISABLE_FOREGROUND = "disable_foreground"; + public static final String ACTION_DISMISS_ERROR_NOTIFICATIONS = "dismiss_error"; public static final String ACTION_TRY_AGAIN = "try_again"; - public static final String ACTION_DISABLE_ACCOUNT = "disable_account"; public static final String ACTION_IDLE_PING = "idle_ping"; private static final String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts"; public static final String ACTION_GCM_TOKEN_REFRESH = "gcm_token_refresh"; @@ -294,6 +294,9 @@ public class XmppConnectionService extends Service { mOnAccountUpdate.onAccountUpdate(); } if (account.getStatus() == Account.State.ONLINE) { + if (account.setShowErrorNotification(true)) { + databaseBackend.updateAccount(account); + } mMessageArchiveService.executePendingQueries(account); if (connection != null && connection.getFeatures().csi()) { if (checkListeners()) { @@ -323,7 +326,7 @@ public class XmppConnectionService extends Service { } account.pendingConferenceJoins.clear(); scheduleWakeUpCall(Config.PUSH_MODE ? Config.PING_MIN_INTERVAL : Config.PING_MAX_INTERVAL, account.getUuid().hashCode()); - } else if (account.getStatus() == Account.State.OFFLINE) { + } else if (account.getStatus() == Account.State.OFFLINE || account.getStatus() == Account.State.DISABLED) { resetSendingToWaiting(account); final boolean disabled = account.isOptionSet(Account.OPTION_DISABLED); final boolean listeners = checkListeners(); @@ -340,6 +343,7 @@ public class XmppConnectionService extends Service { reconnectAccount(account, true, false); } else if ((account.getStatus() != Account.State.CONNECTING) && (account.getStatus() != Account.State.NO_INTERNET)) { + resetSendingToWaiting(account); if (connection != null) { int next = connection.getTimeToNextAttempt(); Log.d(Config.LOGTAG, account.getJid().toBareJid() @@ -526,6 +530,7 @@ public class XmppConnectionService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { final String action = intent == null ? null : intent.getAction(); + String pushedAccountHash = null; boolean interactive = false; if (action != null) { final Conversation c = findConversationByUuid(intent.getStringExtra("uuid")); @@ -554,28 +559,20 @@ public class XmppConnectionService extends Service { getPreferences().edit().putBoolean("keep_foreground_service", false).commit(); toggleForegroundService(); break; + case ACTION_DISMISS_ERROR_NOTIFICATIONS: + dismissErrorNotifications(); + break; case ACTION_TRY_AGAIN: resetAllAttemptCounts(false); interactive = true; break; - case ACTION_DISABLE_ACCOUNT: - try { - String jid = intent.getStringExtra("account"); - Account account = jid == null ? null : findAccountByJid(Jid.fromString(jid)); - if (account != null) { - account.setOption(Account.OPTION_DISABLED, true); - updateAccount(account); - } - } catch (final InvalidJidException ignored) { - break; - } - break; case ACTION_REPLY_TO_CONVERSATION: Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null && c != null) { - - String body = remoteInput.getString("text_reply"); - directReply(c,body); + final CharSequence body = remoteInput.getCharSequence("text_reply"); + if (body != null && body.length() > 0) { + directReply(c, body.toString(),intent.getBooleanExtra("dismiss_notification",false)); + } } break; case AudioManager.RINGER_MODE_CHANGED_ACTION: @@ -601,6 +598,7 @@ public class XmppConnectionService extends Service { break; case ACTION_GCM_MESSAGE_RECEIVED: Log.d(Config.LOGTAG,"gcm push message arrived in service. extras="+intent.getExtras()); + pushedAccountHash = intent.getStringExtra("account"); break; } } @@ -639,7 +637,7 @@ public class XmppConnectionService extends Service { } } else { pingCandidates.add(account); - if (msToNextPing <= 0) { + if (msToNextPing <= 0 || CryptoHelper.getAccountFingerprint(account).equals(pushedAccountHash)) { pingNow = true; } else { this.scheduleWakeUpCall((int) (msToNextPing / 1000), account.getUuid().hashCode()); @@ -707,7 +705,7 @@ public class XmppConnectionService extends Service { } } - private void directReply(Conversation conversation, String body) { + private void directReply(Conversation conversation, String body, final boolean dismissAfterReply) { Message message = new Message(conversation,body,conversation.getNextEncryption()); message.markUnread(); if (message.getEncryption() == Message.ENCRYPTION_PGP) { @@ -716,7 +714,11 @@ public class XmppConnectionService extends Service { public void success(Message message) { message.setEncryption(Message.ENCRYPTION_DECRYPTED); sendMessage(message); - mNotificationService.pushFromDirectReply(message); + if (dismissAfterReply) { + markRead(message.getConversation(),true); + } else { + mNotificationService.pushFromDirectReply(message); + } } @Override @@ -731,7 +733,11 @@ public class XmppConnectionService extends Service { }); } else { sendMessage(message); - mNotificationService.pushFromDirectReply(message); + if (dismissAfterReply) { + markRead(conversation,true); + } else { + mNotificationService.pushFromDirectReply(message); + } } } @@ -802,6 +808,21 @@ public class XmppConnectionService extends Service { connection.resetAttemptCount(); } } + if (account.setShowErrorNotification(true)) { + databaseBackend.updateAccount(account); + } + } + mNotificationService.updateErrorNotification(); + } + + private void dismissErrorNotifications() { + for (final Account account : this.accounts) { + if (account.hasErrorStatus()) { + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": dismissing error notification"); + if (account.setShowErrorNotification(false)) { + databaseBackend.updateAccount(account); + } + } } } @@ -976,8 +997,16 @@ public class XmppConnectionService extends Service { public XmppConnection createConnection(final Account account) { final SharedPreferences sharedPref = getPreferences(); - account.setResource(sharedPref.getString("resource", getString(R.string.default_resource)) - .toLowerCase(Locale.getDefault())); + String resource; + try { + resource = sharedPref.getString("resource", getString(R.string.default_resource)).toLowerCase(Locale.ENGLISH); + if (resource.trim().isEmpty()) { + throw new Exception(); + } + } catch (Exception e) { + resource = "conversations"; + } + account.setResource(resource); final XmppConnection connection = new XmppConnection(account, this); connection.setOnMessagePacketReceivedListener(this.mMessageParser); connection.setOnStatusChangedListener(this.statusListener); @@ -1018,6 +1047,10 @@ public class XmppConnectionService extends Service { private void sendMessage(final Message message, final boolean resend, final boolean delay) { final Account account = message.getConversation().getAccount(); + if (account.setShowErrorNotification(true)) { + databaseBackend.updateAccount(account); + mNotificationService.updateErrorNotification(); + } final Conversation conversation = message.getConversation(); account.deactivateGracePeriod(); MessagePacket packet = null; @@ -1110,7 +1143,8 @@ public class XmppConnectionService extends Service { } if (packet != null) { - if (account.getXmppConnection().getFeatures().sm() || conversation.getMode() == Conversation.MODE_MULTI) { + if (account.getXmppConnection().getFeatures().sm() + || (conversation.getMode() == Conversation.MODE_MULTI && message.getCounterpart().isBareJid())) { message.setStatus(Message.STATUS_UNSEND); } else { message.setStatus(Message.STATUS_SEND); @@ -1152,7 +1186,8 @@ public class XmppConnectionService extends Service { if (resend) { if (packet != null && addToConversation) { - if (account.getXmppConnection().getFeatures().sm() || conversation.getMode() == Conversation.MODE_MULTI) { + if (account.getXmppConnection().getFeatures().sm() + || (conversation.getMode() == Conversation.MODE_MULTI && message.getCounterpart().isBareJid())) { markMessage(message, Message.STATUS_UNSEND); } else { markMessage(message, Message.STATUS_SEND); @@ -1288,6 +1323,13 @@ public class XmppConnectionService extends Service { for (Conversation conversation : conversations) { conversation.addAll(0, databaseBackend.getMessages(conversation, Config.PAGE_SIZE)); checkDeletedFiles(conversation); + conversation.findUnsentTextMessages(new Conversation.OnMessageFound() { + + @Override + public void onMessageFound(Message message) { + markMessage(message, Message.STATUS_WAITING); + } + }); conversation.findUnreadMessages(new Conversation.OnMessageFound() { @Override public void onMessageFound(Message message) { @@ -1508,7 +1550,6 @@ public class XmppConnectionService extends Service { conversation.setMode(Conversation.MODE_SINGLE); conversation.setContactJid(jid.toBareJid()); } - conversation.setNextEncryption(-1); conversation.addAll(0, databaseBackend.getMessages(conversation, Config.PAGE_SIZE)); this.databaseBackend.updateConversation(conversation); } else { @@ -1549,7 +1590,6 @@ public class XmppConnectionService extends Service { public void archiveConversation(Conversation conversation) { getNotificationService().clear(conversation); conversation.setStatus(Conversation.STATUS_ARCHIVED); - conversation.setNextEncryption(-1); synchronized (this.conversations) { if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getAccount().getStatus() == Account.State.ONLINE) { @@ -1644,6 +1684,7 @@ public class XmppConnectionService extends Service { public boolean updateAccount(final Account account) { if (databaseBackend.updateAccount(account)) { + account.setShowErrorNotification(true); this.statusListener.onStatusChanged(account); databaseBackend.updateAccount(account); reconnectAccountInBackground(account); @@ -3091,7 +3132,10 @@ public class XmppConnectionService extends Service { if (this.markRead(conversation)) { updateConversationUi(); } - if (confirmMessages() && markable != null && markable.getRemoteMsgId() != null) { + if (confirmMessages() + && markable != null + && markable.trusted() + && markable.getRemoteMsgId() != null) { Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": sending read marker to " + markable.getCounterpart().toString()); Account account = conversation.getAccount(); final Jid to = markable.getCounterpart(); @@ -3346,10 +3390,10 @@ public class XmppConnectionService extends Service { mDatabaseExecutor.execute(runnable); } - public void sendBlockRequest(final Blockable blockable) { + public void sendBlockRequest(final Blockable blockable, boolean reportSpam) { if (blockable != null && blockable.getBlockedJid() != null) { final Jid jid = blockable.getBlockedJid(); - this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid), new OnIqPacketReceived() { + this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid, reportSpam), new OnIqPacketReceived() { @Override public void onIqPacketReceived(final Account account, final IqPacket packet) { |