mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-24 17:52:17 -05:00
attempt to fix the delay problem
This commit is contained in:
parent
dcf9117451
commit
e79f82ca72
@ -892,7 +892,7 @@ public class AxolotlService {
|
|||||||
new Conversation.OnMessageFound() {
|
new Conversation.OnMessageFound() {
|
||||||
@Override
|
@Override
|
||||||
public void onMessageFound(Message message) {
|
public void onMessageFound(Message message) {
|
||||||
processSending(message);
|
processSending(message,false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1053,7 +1053,7 @@ public class AxolotlService {
|
|||||||
return axolotlMessage;
|
return axolotlMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processSending(final Message message) {
|
private void processSending(final Message message, final boolean delay) {
|
||||||
executor.execute(new Runnable() {
|
executor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -1065,17 +1065,17 @@ public class AxolotlService {
|
|||||||
} 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(), packet);
|
||||||
mXmppConnectionService.resendMessage(message);
|
mXmppConnectionService.resendMessage(message,delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void prepareMessage(final Message message) {
|
public void prepareMessage(final Message message,final boolean delay) {
|
||||||
if (!messageCache.containsKey(message.getUuid())) {
|
if (!messageCache.containsKey(message.getUuid())) {
|
||||||
boolean newSessions = createSessionsIfNeeded(message.getConversation(), true);
|
boolean newSessions = createSessionsIfNeeded(message.getConversation(), true);
|
||||||
if (!newSessions) {
|
if (!newSessions) {
|
||||||
this.processSending(message);
|
this.processSending(message,delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class MessageGenerator extends AbstractGenerator {
|
|||||||
super(service);
|
super(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MessagePacket preparePacket(Message message, boolean addDelay) {
|
private MessagePacket preparePacket(Message message) {
|
||||||
Conversation conversation = message.getConversation();
|
Conversation conversation = message.getConversation();
|
||||||
Account account = conversation.getAccount();
|
Account account = conversation.getAccount();
|
||||||
MessagePacket packet = new MessagePacket();
|
MessagePacket packet = new MessagePacket();
|
||||||
@ -50,13 +50,10 @@ public class MessageGenerator extends AbstractGenerator {
|
|||||||
}
|
}
|
||||||
packet.setFrom(account.getJid());
|
packet.setFrom(account.getJid());
|
||||||
packet.setId(message.getUuid());
|
packet.setId(message.getUuid());
|
||||||
if (addDelay) {
|
|
||||||
addDelay(packet, message.getTimeSent());
|
|
||||||
}
|
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDelay(MessagePacket packet, long timestamp) {
|
public void addDelay(MessagePacket packet, long timestamp) {
|
||||||
final SimpleDateFormat mDateFormat = new SimpleDateFormat(
|
final SimpleDateFormat mDateFormat = new SimpleDateFormat(
|
||||||
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
|
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
|
||||||
mDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
mDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
@ -66,11 +63,7 @@ public class MessageGenerator extends AbstractGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MessagePacket generateAxolotlChat(Message message) {
|
public MessagePacket generateAxolotlChat(Message message) {
|
||||||
return generateAxolotlChat(message, false);
|
MessagePacket packet = preparePacket(message);
|
||||||
}
|
|
||||||
|
|
||||||
public MessagePacket generateAxolotlChat(Message message, boolean addDelay) {
|
|
||||||
MessagePacket packet = preparePacket(message, addDelay);
|
|
||||||
AxolotlService service = message.getConversation().getAccount().getAxolotlService();
|
AxolotlService service = message.getConversation().getAccount().getAxolotlService();
|
||||||
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(message.getConversation().getAccount())+"Submitting message to axolotl service for send processing...");
|
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(message.getConversation().getAccount())+"Submitting message to axolotl service for send processing...");
|
||||||
XmppAxolotlMessage axolotlMessage = service.encrypt(message);
|
XmppAxolotlMessage axolotlMessage = service.encrypt(message);
|
||||||
@ -82,15 +75,11 @@ public class MessageGenerator extends AbstractGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MessagePacket generateOtrChat(Message message) {
|
public MessagePacket generateOtrChat(Message message) {
|
||||||
return generateOtrChat(message, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessagePacket generateOtrChat(Message message, boolean addDelay) {
|
|
||||||
Session otrSession = message.getConversation().getOtrSession();
|
Session otrSession = message.getConversation().getOtrSession();
|
||||||
if (otrSession == null) {
|
if (otrSession == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
MessagePacket packet = preparePacket(message, addDelay);
|
MessagePacket packet = preparePacket(message);
|
||||||
packet.addChild("private", "urn:xmpp:carbons:2");
|
packet.addChild("private", "urn:xmpp:carbons:2");
|
||||||
packet.addChild("no-copy", "urn:xmpp:hints");
|
packet.addChild("no-copy", "urn:xmpp:hints");
|
||||||
packet.addChild("no-permanent-store", "urn:xmpp:hints");
|
packet.addChild("no-permanent-store", "urn:xmpp:hints");
|
||||||
@ -109,11 +98,7 @@ public class MessageGenerator extends AbstractGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MessagePacket generateChat(Message message) {
|
public MessagePacket generateChat(Message message) {
|
||||||
return generateChat(message, false);
|
MessagePacket packet = preparePacket(message);
|
||||||
}
|
|
||||||
|
|
||||||
public MessagePacket generateChat(Message message, boolean addDelay) {
|
|
||||||
MessagePacket packet = preparePacket(message, addDelay);
|
|
||||||
if (message.hasFileOnRemoteHost()) {
|
if (message.hasFileOnRemoteHost()) {
|
||||||
packet.setBody(message.getFileParams().url.toString());
|
packet.setBody(message.getFileParams().url.toString());
|
||||||
} else {
|
} else {
|
||||||
@ -123,11 +108,7 @@ public class MessageGenerator extends AbstractGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MessagePacket generatePgpChat(Message message) {
|
public MessagePacket generatePgpChat(Message message) {
|
||||||
return generatePgpChat(message, false);
|
MessagePacket packet = preparePacket(message);
|
||||||
}
|
|
||||||
|
|
||||||
public MessagePacket generatePgpChat(Message message, boolean addDelay) {
|
|
||||||
MessagePacket packet = preparePacket(message, addDelay);
|
|
||||||
packet.setBody("This is an XEP-0027 encrypted message");
|
packet.setBody("This is an XEP-0027 encrypted message");
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
||||||
packet.addChild("x", "jabber:x:encrypted").setContent(message.getEncryptedBody());
|
packet.addChild("x", "jabber:x:encrypted").setContent(message.getEncryptedBody());
|
||||||
@ -151,8 +132,7 @@ public class MessageGenerator extends AbstractGenerator {
|
|||||||
packet.setType(MessagePacket.TYPE_NORMAL);
|
packet.setType(MessagePacket.TYPE_NORMAL);
|
||||||
packet.setTo(to);
|
packet.setTo(to);
|
||||||
packet.setFrom(account.getJid());
|
packet.setFrom(account.getJid());
|
||||||
Element received = packet.addChild("displayed",
|
Element received = packet.addChild("displayed","urn:xmpp:chat-markers:0");
|
||||||
"urn:xmpp:chat-markers:0");
|
|
||||||
received.setAttribute("id", id);
|
received.setAttribute("id", id);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,9 @@ public class HttpConnectionManager extends AbstractConnectionManager {
|
|||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpUploadConnection createNewUploadConnection(Message message) {
|
public HttpUploadConnection createNewUploadConnection(Message message, boolean delay) {
|
||||||
HttpUploadConnection connection = new HttpUploadConnection(this);
|
HttpUploadConnection connection = new HttpUploadConnection(this);
|
||||||
connection.init(message);
|
connection.init(message,delay);
|
||||||
this.uploadConnections.add(connection);
|
this.uploadConnections.add(connection);
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ public class HttpUploadConnection implements Transferable {
|
|||||||
private XmppConnectionService mXmppConnectionService;
|
private XmppConnectionService mXmppConnectionService;
|
||||||
|
|
||||||
private boolean canceled = false;
|
private boolean canceled = false;
|
||||||
|
private boolean delayed = false;
|
||||||
private Account account;
|
private Account account;
|
||||||
private DownloadableFile file;
|
private DownloadableFile file;
|
||||||
private Message message;
|
private Message message;
|
||||||
@ -80,13 +81,14 @@ public class HttpUploadConnection implements Transferable {
|
|||||||
mXmppConnectionService.markMessage(message,Message.STATUS_SEND_FAILED);
|
mXmppConnectionService.markMessage(message,Message.STATUS_SEND_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(Message message) {
|
public void init(Message message, boolean delay) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
message.setTransferable(this);
|
message.setTransferable(this);
|
||||||
mXmppConnectionService.markMessage(message,Message.STATUS_UNSEND);
|
mXmppConnectionService.markMessage(message,Message.STATUS_UNSEND);
|
||||||
this.account = message.getConversation().getAccount();
|
this.account = message.getConversation().getAccount();
|
||||||
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
|
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
|
||||||
this.file.setExpectedSize(this.file.getSize());
|
this.file.setExpectedSize(this.file.getSize());
|
||||||
|
this.delayed = delay;
|
||||||
|
|
||||||
if (Config.ENCRYPT_ON_HTTP_UPLOADED
|
if (Config.ENCRYPT_ON_HTTP_UPLOADED
|
||||||
|| message.getEncryption() == Message.ENCRYPTION_AXOLOTL
|
|| message.getEncryption() == Message.ENCRYPTION_AXOLOTL
|
||||||
@ -172,7 +174,7 @@ public class HttpUploadConnection implements Transferable {
|
|||||||
mXmppConnectionService.getPgpEngine().encrypt(message, new UiCallback<Message>() {
|
mXmppConnectionService.getPgpEngine().encrypt(message, new UiCallback<Message>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(Message message) {
|
public void success(Message message) {
|
||||||
mXmppConnectionService.resendMessage(message);
|
mXmppConnectionService.resendMessage(message,delayed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -186,7 +188,7 @@ public class HttpUploadConnection implements Transferable {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
mXmppConnectionService.resendMessage(message);
|
mXmppConnectionService.resendMessage(message,delayed);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fail();
|
fail();
|
||||||
|
@ -677,22 +677,22 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendFileMessage(final Message message) {
|
private void sendFileMessage(final Message message, final boolean delay) {
|
||||||
Log.d(Config.LOGTAG, "send file message");
|
Log.d(Config.LOGTAG, "send file message");
|
||||||
final Account account = message.getConversation().getAccount();
|
final Account account = message.getConversation().getAccount();
|
||||||
final XmppConnection connection = account.getXmppConnection();
|
final XmppConnection connection = account.getXmppConnection();
|
||||||
if (connection != null && connection.getFeatures().httpUpload()) {
|
if (connection != null && connection.getFeatures().httpUpload()) {
|
||||||
mHttpConnectionManager.createNewUploadConnection(message);
|
mHttpConnectionManager.createNewUploadConnection(message, delay);
|
||||||
} else {
|
} else {
|
||||||
mJingleConnectionManager.createNewConnection(message);
|
mJingleConnectionManager.createNewConnection(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(final Message message) {
|
public void sendMessage(final Message message) {
|
||||||
sendMessage(message, false);
|
sendMessage(message, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(final Message message, final boolean resend) {
|
private void sendMessage(final Message message, final boolean resend, final boolean delay) {
|
||||||
final Account account = message.getConversation().getAccount();
|
final Account account = message.getConversation().getAccount();
|
||||||
final Conversation conversation = message.getConversation();
|
final Conversation conversation = message.getConversation();
|
||||||
account.deactivateGracePeriod();
|
account.deactivateGracePeriod();
|
||||||
@ -716,24 +716,24 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
case Message.ENCRYPTION_NONE:
|
case Message.ENCRYPTION_NONE:
|
||||||
if (message.needsUploading()) {
|
if (message.needsUploading()) {
|
||||||
if (account.httpUploadAvailable() || message.fixCounterpart()) {
|
if (account.httpUploadAvailable() || message.fixCounterpart()) {
|
||||||
this.sendFileMessage(message);
|
this.sendFileMessage(message,delay);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
packet = mMessageGenerator.generateChat(message,resend);
|
packet = mMessageGenerator.generateChat(message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Message.ENCRYPTION_PGP:
|
case Message.ENCRYPTION_PGP:
|
||||||
case Message.ENCRYPTION_DECRYPTED:
|
case Message.ENCRYPTION_DECRYPTED:
|
||||||
if (message.needsUploading()) {
|
if (message.needsUploading()) {
|
||||||
if (account.httpUploadAvailable() || message.fixCounterpart()) {
|
if (account.httpUploadAvailable() || message.fixCounterpart()) {
|
||||||
this.sendFileMessage(message);
|
this.sendFileMessage(message,delay);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
packet = mMessageGenerator.generatePgpChat(message,resend);
|
packet = mMessageGenerator.generatePgpChat(message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Message.ENCRYPTION_OTR:
|
case Message.ENCRYPTION_OTR:
|
||||||
@ -747,7 +747,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
if (message.needsUploading()) {
|
if (message.needsUploading()) {
|
||||||
mJingleConnectionManager.createNewConnection(message);
|
mJingleConnectionManager.createNewConnection(message);
|
||||||
} else {
|
} else {
|
||||||
packet = mMessageGenerator.generateOtrChat(message,resend);
|
packet = mMessageGenerator.generateOtrChat(message);
|
||||||
}
|
}
|
||||||
} else if (otrSession == null) {
|
} else if (otrSession == null) {
|
||||||
if (message.fixCounterpart()) {
|
if (message.fixCounterpart()) {
|
||||||
@ -760,14 +760,14 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
case Message.ENCRYPTION_AXOLOTL:
|
case Message.ENCRYPTION_AXOLOTL:
|
||||||
if (message.needsUploading()) {
|
if (message.needsUploading()) {
|
||||||
if (account.httpUploadAvailable() || message.fixCounterpart()) {
|
if (account.httpUploadAvailable() || message.fixCounterpart()) {
|
||||||
this.sendFileMessage(message);
|
this.sendFileMessage(message,delay);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
packet = account.getAxolotlService().fetchPacketFromCache(message);
|
packet = account.getAxolotlService().fetchPacketFromCache(message);
|
||||||
if (packet == null) {
|
if (packet == null) {
|
||||||
account.getAxolotlService().prepareMessage(message);
|
account.getAxolotlService().prepareMessage(message,delay);
|
||||||
message.setAxolotlFingerprint(account.getAxolotlService().getOwnPublicKey().getFingerprint().replaceAll("\\s", ""));
|
message.setAxolotlFingerprint(account.getAxolotlService().getOwnPublicKey().getFingerprint().replaceAll("\\s", ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -822,6 +822,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
updateConversationUi();
|
updateConversationUi();
|
||||||
}
|
}
|
||||||
if (packet != null) {
|
if (packet != null) {
|
||||||
|
if (delay) {
|
||||||
|
mMessageGenerator.addDelay(packet,message.getTimeSent());
|
||||||
|
}
|
||||||
if (conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
|
if (conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
|
||||||
if (this.sendChatStates()) {
|
if (this.sendChatStates()) {
|
||||||
packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
|
packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
|
||||||
@ -836,13 +839,13 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessageFound(Message message) {
|
public void onMessageFound(Message message) {
|
||||||
resendMessage(message);
|
resendMessage(message,true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resendMessage(final Message message) {
|
public void resendMessage(final Message message, final boolean delay) {
|
||||||
sendMessage(message, true);
|
sendMessage(message, true, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fetchRosterFromServer(final Account account) {
|
public void fetchRosterFromServer(final Account account) {
|
||||||
@ -1846,8 +1849,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
if (message.needsUploading()) {
|
if (message.needsUploading()) {
|
||||||
mJingleConnectionManager.createNewConnection(message);
|
mJingleConnectionManager.createNewConnection(message);
|
||||||
} else {
|
} else {
|
||||||
MessagePacket outPacket = mMessageGenerator.generateOtrChat(message, true);
|
MessagePacket outPacket = mMessageGenerator.generateOtrChat(message);
|
||||||
if (outPacket != null) {
|
if (outPacket != null) {
|
||||||
|
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);
|
||||||
@ -2526,7 +2530,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
}
|
}
|
||||||
for (final Message msg : messages) {
|
for (final Message msg : messages) {
|
||||||
markMessage(msg, Message.STATUS_WAITING);
|
markMessage(msg, Message.STATUS_WAITING);
|
||||||
this.resendMessage(msg);
|
this.resendMessage(msg,true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user