From c0b3a3ff0c32c8025174ebb92fbcf4a7fc67f497 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 15 Feb 2016 23:15:04 +0100 Subject: basic support for XEP-0308: Last Message Correction. fixes #864 --- .../siacs/conversations/services/XmppConnectionService.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 16d7f139c..10f6b5efd 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -841,8 +841,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa final Conversation conversation = message.getConversation(); account.deactivateGracePeriod(); MessagePacket packet = null; - final boolean addToConversation = conversation.getMode() != Conversation.MODE_MULTI - || account.getServerIdentity() != XmppConnection.Identity.SLACK; + final boolean addToConversation = (conversation.getMode() != Conversation.MODE_MULTI + || account.getServerIdentity() != XmppConnection.Identity.SLACK) + && !message.edited(); boolean saveInDb = addToConversation; message.setStatus(Message.STATUS_WAITING); @@ -966,8 +967,12 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa if (addToConversation) { conversation.add(message); } - if (saveInDb && (message.getEncryption() == Message.ENCRYPTION_NONE || saveEncryptedMessages())) { - databaseBackend.createMessage(message); + if (message.getEncryption() == Message.ENCRYPTION_NONE || saveEncryptedMessages()) { + if (saveInDb) { + databaseBackend.createMessage(message); + } else if (message.edited()) { + databaseBackend.updateMessage(message, message.getEditedId()); + } } updateConversationUi(); } -- cgit v1.2.3 From 0ca4a33bfb76d63a3c2d4447643a5bd90ac5315f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 16 Feb 2016 09:15:41 +0100 Subject: added some OTR logging --- .../eu/siacs/conversations/services/XmppConnectionService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/main/java/eu/siacs/conversations/services') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 10f6b5efd..a8fe7586f 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -288,7 +288,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa List conversations = getConversations(); for (Conversation conversation : conversations) { if (conversation.getAccount() == account && conversation.getMode() == Conversation.MODE_SINGLE) { - conversation.startOtrIfNeeded(); + if (!conversation.startOtrIfNeeded()) { + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": couldn't start OTR with "+conversation.getContact().getJid()+" when needed"); + } sendUnsentMessages(conversation); } } @@ -900,8 +902,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa if (message.fixCounterpart()) { conversation.startOtrSession(message.getCounterpart().getResourcepart(), true); } else { + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": could not fix counterpart for OTR message to contact "+message.getContact().getJid()); break; } + } else { + Log.d(Config.LOGTAG,account.getJid().toBareJid()+" OTR session with "+message.getContact()+" is in wrong state: "+otrSession.getSessionStatus().toString()); } break; case Message.ENCRYPTION_AXOLOTL: @@ -946,6 +951,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa break; case Message.ENCRYPTION_OTR: if (!conversation.hasValidOtrSession() && message.getCounterpart() != null) { + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": create otr session without starting for "+message.getContact().getJid()); conversation.startOtrSession(message.getCounterpart().getResourcepart(), false); } break; -- cgit v1.2.3 From a9b957e8a2b9cb7729ed0d2cc8b5efa1bee50c79 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 16 Feb 2016 09:57:59 +0100 Subject: added setting to opt-out of message correction. renamed preferences and options to settings --- .../java/eu/siacs/conversations/services/XmppConnectionService.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/main/java/eu/siacs/conversations/services') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index a8fe7586f..0c8f0b8b2 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2615,6 +2615,10 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa return getPreferences().getBoolean("confirm_messages", true); } + public boolean allowMessageCorrection() { + return getPreferences().getBoolean("allow_message_correction", true); + } + public boolean sendChatStates() { return getPreferences().getBoolean("chat_states", false); } -- cgit v1.2.3 From 86b1865eec5784795358b3d81eefe39d37ecd55a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 16 Feb 2016 14:22:21 +0100 Subject: fixed regression that caused ui to redraw a lot --- .../siacs/conversations/services/XmppConnectionService.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 0c8f0b8b2..b7ac7571b 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2726,7 +2726,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa return null; } - public void markRead(final Conversation conversation) { + public boolean markRead(final Conversation conversation) { mNotificationService.clear(conversation); final List readMessages = conversation.markRead(); if (readMessages.size() > 0) { @@ -2739,8 +2739,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } }; mDatabaseExecutor.execute(runnable); + updateUnreadCountBadge(); + return true; + } else { + return false; } - updateUnreadCountBadge(); } public synchronized void updateUnreadCountBadge() { @@ -2758,7 +2761,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa public void sendReadMarker(final Conversation conversation) { final Message markable = conversation.getLatestMarkableMessage(); - this.markRead(conversation); + if (this.markRead(conversation)) { + updateConversationUi(); + } if (confirmMessages() && markable != null && markable.getRemoteMsgId() != null) { Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": sending read marker to " + markable.getCounterpart().toString()); Account account = conversation.getAccount(); @@ -2766,7 +2771,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa MessagePacket packet = mMessageGenerator.confirm(account, to, markable.getRemoteMsgId()); this.sendMessagePacket(conversation.getAccount(), packet); } - updateConversationUi(); } public SecureRandom getRNG() { -- cgit v1.2.3 From 3626e4b3a0d3d3da4be1bdf7645045d8cf892b50 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 17 Feb 2016 16:50:48 +0100 Subject: fixed regression that caused messages in muc not being send --- .../siacs/conversations/services/XmppConnectionService.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index b7ac7571b..33f7210f7 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -287,7 +287,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } List conversations = getConversations(); for (Conversation conversation : conversations) { - if (conversation.getAccount() == account && conversation.getMode() == Conversation.MODE_SINGLE) { + if (conversation.getAccount() == account + && !account.pendingConferenceJoins.contains(conversation)) { if (!conversation.startOtrIfNeeded()) { Log.d(Config.LOGTAG,account.getJid().toBareJid()+": couldn't start OTR with "+conversation.getContact().getJid()+" when needed"); } @@ -1757,20 +1758,20 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa List conversations = getConversations(); for (Conversation conversation : conversations) { if (conversation.getMode() == Conversation.MODE_MULTI && conversation.getAccount() == account) { - joinMuc(conversation, true, null); + joinMuc(conversation); } } } public void joinMuc(Conversation conversation) { - joinMuc(conversation, false, null); + joinMuc(conversation, null); } - private void joinMuc(Conversation conversation, boolean now, final OnConferenceJoined onConferenceJoined) { + private void joinMuc(Conversation conversation, final OnConferenceJoined onConferenceJoined) { Account account = conversation.getAccount(); account.pendingConferenceJoins.remove(conversation); account.pendingConferenceLeaves.remove(conversation); - if (account.getStatus() == Account.State.ONLINE || now) { + if (account.getStatus() == Account.State.ONLINE) { conversation.resetMucOptions(); fetchConferenceConfiguration(conversation, new OnConferenceConfigurationFetched() { @@ -1949,7 +1950,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa String name = new BigInteger(75, getRNG()).toString(32); Jid jid = Jid.fromParts(name, server, null); final Conversation conversation = findOrCreateConversation(account, jid, true); - joinMuc(conversation, true, new OnConferenceJoined() { + joinMuc(conversation, new OnConferenceJoined() { @Override public void onConferenceJoined(final Conversation conversation) { Bundle options = new Bundle(); -- cgit v1.2.3 From ac687d6bbd08674d97a52b3548df8fe49bee48d9 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 17 Feb 2016 16:52:57 +0100 Subject: don't log start reason --- src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 1 - 1 file changed, 1 deletion(-) (limited to 'src/main/java/eu/siacs/conversations/services') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 33f7210f7..9b7306378 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -477,7 +477,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa final String action = intent == null ? null : intent.getAction(); boolean interactive = false; if (action != null) { - Log.d(Config.LOGTAG,"start reason: "+action); switch (action) { case ConnectivityManager.CONNECTIVITY_ACTION: if (hasInternetConnection() && Config.RESET_ATTEMPT_COUNT_ON_NETWORK_CHANGE) { -- cgit v1.2.3 From 3bde4dbedb80a8e1de89c09f58d842d7382598e8 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 20 Feb 2016 00:01:39 +0100 Subject: change uuid when replacing messages --- .../java/eu/siacs/conversations/services/XmppConnectionService.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/main/java/eu/siacs/conversations/services') diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 9b7306378..b836e780a 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2159,6 +2159,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa updateConversationUi(); } + public void updateMessage(Message message, String uuid) { + databaseBackend.updateMessage(message, uuid); + updateConversationUi(); + } + protected void syncDirtyContacts(Account account) { for (Contact contact : account.getRoster().getContacts()) { if (contact.getOption(Contact.Options.DIRTY_PUSH)) { -- cgit v1.2.3