offline sending of pgp fixed

This commit is contained in:
Daniel Gultsch 2014-05-16 13:42:20 +02:00
parent c8f8bab2a1
commit aa68045c58
2 changed files with 43 additions and 25 deletions

View file

@ -774,11 +774,7 @@ public class XmppConnectionService extends Service {
addToConversation = true;
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
message.getConversation().endOtrIfNeeded();
packet = new MessagePacket();
packet.setType(MessagePacket.TYPE_CHAT);
packet.setFrom(message.getConversation().getAccount()
.getFullJid());
packet.setTo(message.getCounterpart());
packet = prepareMessagePacket(account, message, null);
packet.setBody("This is an XEP-0027 encryted message");
packet.addChild("x", "jabber:x:encrypted").setContent(
message.getEncryptedBody());
@ -800,9 +796,18 @@ public class XmppConnectionService extends Service {
}
}
} else {
// account is offline
saveInDb = true;
addToConversation = true;
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
String pgpBody = message.getEncryptedBody();
String decryptedBody = message.getBody();
message.setBody(pgpBody);
databaseBackend.createMessage(message);
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
message.setBody(decryptedBody);
addToConversation = true;
} else {
saveInDb = true;
addToConversation = true;
}
}
if (saveInDb) {
@ -822,25 +827,38 @@ public class XmppConnectionService extends Service {
private void sendUnsendMessages(Conversation conversation) {
for (int i = 0; i < conversation.getMessages().size(); ++i) {
if ((conversation.getMessages().get(i).getStatus() == Message.STATUS_UNSEND)
&& (conversation.getMessages().get(i).getEncryption() == Message.ENCRYPTION_NONE)) {
Message message = conversation.getMessages().get(i);
MessagePacket packet = prepareMessagePacket(
conversation.getAccount(), message, null);
conversation.getAccount().getXmppConnection()
.sendMessagePacket(packet);
message.setStatus(Message.STATUS_SEND);
if (conversation.getMode() == Conversation.MODE_SINGLE) {
databaseBackend.updateMessage(message);
} else {
databaseBackend.deleteMessage(message);
conversation.getMessages().remove(i);
i--;
}
if (conversation.getMessages().get(i).getStatus() == Message.STATUS_UNSEND) {
resendMessage(conversation.getMessages().get(i));
}
}
}
private void resendMessage(Message message) {
Account account = message.getConversation().getAccount();
MessagePacket packet = null;
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
packet = prepareMessagePacket(account, message,null);
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
packet = prepareMessagePacket(account, message, null);
packet.setBody("This is an XEP-0027 encryted message");
if (message.getEncryptedBody()==null) {
markMessage(message, Message.STATUS_SEND_FAILED);
return;
}
packet.addChild("x", "jabber:x:encrypted").setContent(
message.getEncryptedBody());
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
packet = prepareMessagePacket(account, message, null);
packet.setBody("This is an XEP-0027 encryted message");
packet.addChild("x", "jabber:x:encrypted").setContent(
message.getBody());
}
if (packet!=null) {
account.getXmppConnection().sendMessagePacket(packet);
markMessage(message, Message.STATUS_SEND);
}
}
public MessagePacket prepareMessagePacket(Account account, Message message,
Session otrSession) {
MessagePacket packet = new MessagePacket();

View file

@ -111,7 +111,7 @@ public class XmppConnection implements Runnable {
protected void changeStatus(int nextStatus) {
if (account.getStatus() != nextStatus) {
if ((nextStatus == Account.STATUS_OFFLINE)&&(account.getStatus() != Account.STATUS_CONNECTING)&&(account.getStatus() != Account.STATUS_ONLINE)) {
if ((nextStatus == Account.STATUS_OFFLINE)&&(account.getStatus() != Account.STATUS_CONNECTING)&&(account.getStatus() != Account.STATUS_ONLINE)&&(account.getStatus() != Account.STATUS_DISABLED)) {
return;
}
account.setStatus(nextStatus);
@ -257,10 +257,10 @@ public class XmppConnection implements Runnable {
RequestPacket r = new RequestPacket(smVersion);
tagWriter.writeStanzaAsync(r);
} else if (nextTag.isStart("resumed")) {
Log.d(LOGTAG,account.getJid()+": session resumed");
tagReader.readElement(nextTag);
sendPing();
changeStatus(Account.STATUS_ONLINE);
Log.d(LOGTAG,account.getJid()+": session resumed");
} else if (nextTag.isStart("r")) {
tagReader.readElement(nextTag);
AckPacket ack = new AckPacket(this.stanzasReceived,smVersion);