diff options
author | Andreas Straub <andy@strb.org> | 2015-07-20 23:13:28 +0200 |
---|---|---|
committer | Andreas Straub <andy@strb.org> | 2015-07-20 23:13:28 +0200 |
commit | d2845e9ac1040a269401ef9d59e27bac9e7b7d5a (patch) | |
tree | 4b7f769f361e46a9a183da62077c815644703213 /src | |
parent | 8be0e8a27ddd4d55a48a38efc5434a581be6f1b3 (diff) |
Refactor axolotl send processing/caching flow
Diffstat (limited to 'src')
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 72d1d14a..882ead3c 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 d3c35789..fed92a27 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 e43b2536..e7df9e6a 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); |