mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-11 11:45:01 -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 SQLiteAxolotlStore axolotlStore;
|
||||||
private final SessionMap sessions;
|
private final SessionMap sessions;
|
||||||
private final Map<Jid, Set<Integer>> deviceIds;
|
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 FetchStatusMap fetchStatusMap;
|
||||||
private final SerialSingleThreadExecutor executor;
|
private final SerialSingleThreadExecutor executor;
|
||||||
|
|
||||||
@ -1085,14 +1085,13 @@ public class AxolotlService {
|
|||||||
executor.execute(new Runnable() {
|
executor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MessagePacket packet = mXmppConnectionService.getMessageGenerator()
|
XmppAxolotlMessage axolotlMessage = encrypt(message);
|
||||||
.generateAxolotlChat(message);
|
if (axolotlMessage == null) {
|
||||||
if (packet == null) {
|
|
||||||
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED);
|
mXmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED);
|
||||||
//mXmppConnectionService.updateConversationUi();
|
//mXmppConnectionService.updateConversationUi();
|
||||||
} else {
|
} else {
|
||||||
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account)+"Generated message, caching: " + message.getUuid());
|
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);
|
mXmppConnectionService.resendMessage(message,delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1108,15 +1107,15 @@ public class AxolotlService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessagePacket fetchPacketFromCache(Message message) {
|
public XmppAxolotlMessage fetchAxolotlMessageFromCache(Message message) {
|
||||||
MessagePacket packet = messageCache.get(message.getUuid());
|
XmppAxolotlMessage axolotlMessage = messageCache.get(message.getUuid());
|
||||||
if (packet != null) {
|
if (axolotlMessage != null) {
|
||||||
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account)+"Cache hit: " + message.getUuid());
|
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account)+"Cache hit: " + message.getUuid());
|
||||||
messageCache.remove(message.getUuid());
|
messageCache.remove(message.getUuid());
|
||||||
} else {
|
} else {
|
||||||
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account)+"Cache miss: " + message.getUuid());
|
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account)+"Cache miss: " + message.getUuid());
|
||||||
}
|
}
|
||||||
return packet;
|
return axolotlMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XmppAxolotlMessage.XmppAxolotlPlaintextMessage processReceiving(XmppAxolotlMessage message) {
|
public XmppAxolotlMessage.XmppAxolotlPlaintextMessage processReceiving(XmppAxolotlMessage message) {
|
||||||
|
@ -62,11 +62,8 @@ public class MessageGenerator extends AbstractGenerator {
|
|||||||
delay.setAttribute("stamp", mDateFormat.format(date));
|
delay.setAttribute("stamp", mDateFormat.format(date));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessagePacket generateAxolotlChat(Message message) {
|
public MessagePacket generateAxolotlChat(Message message, XmppAxolotlMessage axolotlMessage) {
|
||||||
MessagePacket packet = preparePacket(message);
|
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) {
|
if (axolotlMessage == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ import de.duenndns.ssl.MemorizingTrustManager;
|
|||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.crypto.PgpEngine;
|
import eu.siacs.conversations.crypto.PgpEngine;
|
||||||
|
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Blockable;
|
import eu.siacs.conversations.entities.Blockable;
|
||||||
import eu.siacs.conversations.entities.Bookmark;
|
import eu.siacs.conversations.entities.Bookmark;
|
||||||
@ -765,10 +766,12 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
packet = account.getAxolotlService().fetchPacketFromCache(message);
|
XmppAxolotlMessage axolotlMessage = account.getAxolotlService().fetchAxolotlMessageFromCache(message);
|
||||||
if (packet == null) {
|
if (axolotlMessage == null) {
|
||||||
account.getAxolotlService().prepareMessage(message,delay);
|
account.getAxolotlService().prepareMessage(message,delay);
|
||||||
message.setAxolotlFingerprint(account.getAxolotlService().getOwnPublicKey().getFingerprint().replaceAll("\\s", ""));
|
message.setAxolotlFingerprint(account.getAxolotlService().getOwnPublicKey().getFingerprint().replaceAll("\\s", ""));
|
||||||
|
} else {
|
||||||
|
packet = mMessageGenerator.generateAxolotlChat(message, axolotlMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -839,7 +842,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessageFound(Message message) {
|
public void onMessageFound(Message message) {
|
||||||
resendMessage(message,true);
|
resendMessage(message, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1851,7 +1854,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
} else {
|
} else {
|
||||||
MessagePacket outPacket = mMessageGenerator.generateOtrChat(message);
|
MessagePacket outPacket = mMessageGenerator.generateOtrChat(message);
|
||||||
if (outPacket != null) {
|
if (outPacket != null) {
|
||||||
mMessageGenerator.addDelay(outPacket,message.getTimeSent());
|
mMessageGenerator.addDelay(outPacket, message.getTimeSent());
|
||||||
message.setStatus(Message.STATUS_SEND);
|
message.setStatus(Message.STATUS_SEND);
|
||||||
databaseBackend.updateMessage(message);
|
databaseBackend.updateMessage(message);
|
||||||
sendMessagePacket(account, outPacket);
|
sendMessagePacket(account, outPacket);
|
||||||
|
Loading…
Reference in New Issue
Block a user