diff options
3 files changed, 16 insertions, 17 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index 72d1d14a0..882ead3c1 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -68,7 +68,7 @@ public class AxolotlService { private final SQLiteAxolotlStore axolotlStore; private final SessionMap sessions; private final Map<Jid, Set<Integer>> deviceIds; - private final Map<String, MessagePacket> messageCache; + private final Map<String, XmppAxolotlMessage> messageCache; private final FetchStatusMap fetchStatusMap; private final SerialSingleThreadExecutor executor; @@ -1085,14 +1085,13 @@ public class AxolotlService { executor.execute(new Runnable() { @Override public void run() { - MessagePacket packet = mXmppConnectionService.getMessageGenerator() - .generateAxolotlChat(message); - if (packet == null) { + XmppAxolotlMessage axolotlMessage = encrypt(message); + if (axolotlMessage == null) { mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED); //mXmppConnectionService.updateConversationUi(); } else { Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account)+"Generated message, caching: " + message.getUuid()); - messageCache.put(message.getUuid(), packet); + messageCache.put(message.getUuid(), axolotlMessage); mXmppConnectionService.resendMessage(message,delay); } } @@ -1108,15 +1107,15 @@ public class AxolotlService { } } - public MessagePacket fetchPacketFromCache(Message message) { - MessagePacket packet = messageCache.get(message.getUuid()); - if (packet != null) { + public XmppAxolotlMessage fetchAxolotlMessageFromCache(Message message) { + XmppAxolotlMessage axolotlMessage = messageCache.get(message.getUuid()); + if (axolotlMessage != null) { Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account)+"Cache hit: " + message.getUuid()); messageCache.remove(message.getUuid()); } else { Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account)+"Cache miss: " + message.getUuid()); } - return packet; + return axolotlMessage; } public XmppAxolotlMessage.XmppAxolotlPlaintextMessage processReceiving(XmppAxolotlMessage message) { diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java index d3c35789e..fed92a27c 100644 --- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java @@ -62,11 +62,8 @@ public class MessageGenerator extends AbstractGenerator { delay.setAttribute("stamp", mDateFormat.format(date)); } - public MessagePacket generateAxolotlChat(Message message) { + public MessagePacket generateAxolotlChat(Message message, XmppAxolotlMessage axolotlMessage) { MessagePacket packet = preparePacket(message); - AxolotlService service = message.getConversation().getAccount().getAxolotlService(); - Log.d(Config.LOGTAG, AxolotlService.getLogprefix(message.getConversation().getAccount())+"Submitting message to axolotl service for send processing..."); - XmppAxolotlMessage axolotlMessage = service.encrypt(message); if (axolotlMessage == null) { return null; } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index e43b25368..e7df9e6a9 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -52,6 +52,7 @@ import de.duenndns.ssl.MemorizingTrustManager; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.PgpEngine; +import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Blockable; import eu.siacs.conversations.entities.Bookmark; @@ -765,10 +766,12 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa break; } } else { - packet = account.getAxolotlService().fetchPacketFromCache(message); - if (packet == null) { + XmppAxolotlMessage axolotlMessage = account.getAxolotlService().fetchAxolotlMessageFromCache(message); + if (axolotlMessage == null) { account.getAxolotlService().prepareMessage(message,delay); message.setAxolotlFingerprint(account.getAxolotlService().getOwnPublicKey().getFingerprint().replaceAll("\\s", "")); + } else { + packet = mMessageGenerator.generateAxolotlChat(message, axolotlMessage); } } break; @@ -839,7 +842,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa @Override public void onMessageFound(Message message) { - resendMessage(message,true); + resendMessage(message, true); } }); } @@ -1851,7 +1854,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } else { MessagePacket outPacket = mMessageGenerator.generateOtrChat(message); if (outPacket != null) { - mMessageGenerator.addDelay(outPacket,message.getTimeSent()); + mMessageGenerator.addDelay(outPacket, message.getTimeSent()); message.setStatus(Message.STATUS_SEND); databaseBackend.updateMessage(message); sendMessagePacket(account, outPacket); |