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; addToConversation = true;
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) { } else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
message.getConversation().endOtrIfNeeded(); message.getConversation().endOtrIfNeeded();
packet = new MessagePacket(); packet = prepareMessagePacket(account, message, null);
packet.setType(MessagePacket.TYPE_CHAT);
packet.setFrom(message.getConversation().getAccount()
.getFullJid());
packet.setTo(message.getCounterpart());
packet.setBody("This is an XEP-0027 encryted message"); packet.setBody("This is an XEP-0027 encryted message");
packet.addChild("x", "jabber:x:encrypted").setContent( packet.addChild("x", "jabber:x:encrypted").setContent(
message.getEncryptedBody()); message.getEncryptedBody());
@ -800,9 +796,18 @@ public class XmppConnectionService extends Service {
} }
} }
} else { } else {
// account is offline if (message.getEncryption() == Message.ENCRYPTION_PGP) {
saveInDb = true; String pgpBody = message.getEncryptedBody();
addToConversation = true; 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) { if (saveInDb) {
@ -822,24 +827,37 @@ public class XmppConnectionService extends Service {
private void sendUnsendMessages(Conversation conversation) { private void sendUnsendMessages(Conversation conversation) {
for (int i = 0; i < conversation.getMessages().size(); ++i) { for (int i = 0; i < conversation.getMessages().size(); ++i) {
if ((conversation.getMessages().get(i).getStatus() == Message.STATUS_UNSEND) if (conversation.getMessages().get(i).getStatus() == Message.STATUS_UNSEND) {
&& (conversation.getMessages().get(i).getEncryption() == Message.ENCRYPTION_NONE)) { resendMessage(conversation.getMessages().get(i));
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--;
}
} }
} }
} }
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, public MessagePacket prepareMessagePacket(Account account, Message message,
Session otrSession) { Session otrSession) {

View File

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