mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 03:32:15 -05:00
Refactor axolotl send processing/caching flow
This commit is contained in:
parent
8be0e8a27d
commit
d2845e9ac1
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user