more otr fixes

This commit is contained in:
iNPUTmice 2014-06-24 16:14:18 +02:00
parent c2ddfded94
commit ea261c1032
2 changed files with 24 additions and 14 deletions

View File

@ -46,17 +46,21 @@ public class MessageGenerator {
return generateOtrChat(message, false);
}
public MessagePacket generateOtrChat(Message message, boolean addDelay) throws OtrException {
public MessagePacket generateOtrChat(Message message, boolean addDelay) {
Session otrSession = message.getConversation().getOtrSession();
if (otrSession==null) {
throw new OtrException(null);
return null;
}
MessagePacket packet = preparePacket(message,addDelay);
packet.addChild("private", "urn:xmpp:carbons:2");
packet.addChild("no-copy", "urn:xmpp:hints");
try {
packet.setBody(otrSession.transformSending(message
.getBody()));
return packet;
} catch (OtrException e) {
return null;
}
}
public MessagePacket generateChat(Message message) {

View File

@ -760,6 +760,7 @@ public class XmppConnectionService extends Service {
private void resendMessage(Message message) {
Account account = message.getConversation().getAccount();
MessagePacket packet = null;
if (message.getEncryption() == Message.ENCRYPTION_OTR) {
Presences presences = message.getConversation().getContact()
.getPresences();
@ -776,18 +777,21 @@ public class XmppConnectionService extends Service {
getApplicationContext(), presence, true);
}
}
} else {
if (message.getConversation().getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
if (message.getType() == Message.TYPE_TEXT) {
packet = mMessageGenerator.generateOtrChat(message,true);
} else if (message.getType() == Message.TYPE_IMAGE) {
mJingleConnectionManager.createNewConnection(message);
}
}
}
} else if (message.getType() == Message.TYPE_TEXT) {
MessagePacket packet = null;
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
packet = mMessageGenerator.generateChat(message,true);
} else if ((message.getEncryption() == Message.ENCRYPTION_DECRYPTED)||(message.getEncryption() == Message.ENCRYPTION_PGP)) {
packet = mMessageGenerator.generatePgpChat(message,true);
}
if (packet != null) {
account.getXmppConnection().sendMessagePacket(packet);
markMessage(message, Message.STATUS_SEND);
}
} else if (message.getType() == Message.TYPE_IMAGE) {
Presences presences = message.getConversation().getContact()
.getPresences();
@ -804,6 +808,10 @@ public class XmppConnectionService extends Service {
}
}
}
if (packet != null) {
account.getXmppConnection().sendMessagePacket(packet);
markMessage(message, Message.STATUS_SEND);
}
}
public void fetchRosterFromServer(Account account) {
@ -1206,13 +1214,11 @@ public class XmppConnectionService extends Service {
&& (msg.getEncryption() == Message.ENCRYPTION_OTR)) {
msg.setPresence(otrSession.getSessionID().getUserID());
if (msg.getType() == Message.TYPE_TEXT) {
try {
MessagePacket outPacket = mMessageGenerator.generateOtrChat(msg,true);
if (outPacket!=null) {
msg.setStatus(Message.STATUS_SEND);
databaseBackend.updateMessage(msg);
account.getXmppConnection().sendMessagePacket(outPacket);
} catch (OtrException e) {
Log.e(LOGTAG,"error creating otr packet");
}
} else if (msg.getType() == Message.TYPE_IMAGE) {
mJingleConnectionManager.createNewConnection(msg);