more otr fixes
This commit is contained in:
parent
c2ddfded94
commit
ea261c1032
|
@ -46,17 +46,21 @@ public class MessageGenerator {
|
||||||
return generateOtrChat(message, false);
|
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();
|
Session otrSession = message.getConversation().getOtrSession();
|
||||||
if (otrSession==null) {
|
if (otrSession==null) {
|
||||||
throw new OtrException(null);
|
return null;
|
||||||
}
|
}
|
||||||
MessagePacket packet = preparePacket(message,addDelay);
|
MessagePacket packet = preparePacket(message,addDelay);
|
||||||
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.setBody(otrSession.transformSending(message
|
try {
|
||||||
.getBody()));
|
packet.setBody(otrSession.transformSending(message
|
||||||
return packet;
|
.getBody()));
|
||||||
|
return packet;
|
||||||
|
} catch (OtrException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessagePacket generateChat(Message message) {
|
public MessagePacket generateChat(Message message) {
|
||||||
|
|
|
@ -760,6 +760,7 @@ public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
private void resendMessage(Message message) {
|
private void resendMessage(Message message) {
|
||||||
Account account = message.getConversation().getAccount();
|
Account account = message.getConversation().getAccount();
|
||||||
|
MessagePacket packet = null;
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_OTR) {
|
if (message.getEncryption() == Message.ENCRYPTION_OTR) {
|
||||||
Presences presences = message.getConversation().getContact()
|
Presences presences = message.getConversation().getContact()
|
||||||
.getPresences();
|
.getPresences();
|
||||||
|
@ -776,18 +777,21 @@ public class XmppConnectionService extends Service {
|
||||||
getApplicationContext(), presence, true);
|
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) {
|
} else if (message.getType() == Message.TYPE_TEXT) {
|
||||||
MessagePacket packet = null;
|
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
|
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
|
||||||
packet = mMessageGenerator.generateChat(message,true);
|
packet = mMessageGenerator.generateChat(message,true);
|
||||||
} else if ((message.getEncryption() == Message.ENCRYPTION_DECRYPTED)||(message.getEncryption() == Message.ENCRYPTION_PGP)) {
|
} else if ((message.getEncryption() == Message.ENCRYPTION_DECRYPTED)||(message.getEncryption() == Message.ENCRYPTION_PGP)) {
|
||||||
packet = mMessageGenerator.generatePgpChat(message,true);
|
packet = mMessageGenerator.generatePgpChat(message,true);
|
||||||
}
|
}
|
||||||
if (packet != null) {
|
|
||||||
account.getXmppConnection().sendMessagePacket(packet);
|
|
||||||
markMessage(message, Message.STATUS_SEND);
|
|
||||||
}
|
|
||||||
} else if (message.getType() == Message.TYPE_IMAGE) {
|
} else if (message.getType() == Message.TYPE_IMAGE) {
|
||||||
Presences presences = message.getConversation().getContact()
|
Presences presences = message.getConversation().getContact()
|
||||||
.getPresences();
|
.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) {
|
public void fetchRosterFromServer(Account account) {
|
||||||
|
@ -1206,13 +1214,11 @@ public class XmppConnectionService extends Service {
|
||||||
&& (msg.getEncryption() == Message.ENCRYPTION_OTR)) {
|
&& (msg.getEncryption() == Message.ENCRYPTION_OTR)) {
|
||||||
msg.setPresence(otrSession.getSessionID().getUserID());
|
msg.setPresence(otrSession.getSessionID().getUserID());
|
||||||
if (msg.getType() == Message.TYPE_TEXT) {
|
if (msg.getType() == Message.TYPE_TEXT) {
|
||||||
try {
|
MessagePacket outPacket = mMessageGenerator.generateOtrChat(msg,true);
|
||||||
MessagePacket outPacket = mMessageGenerator.generateOtrChat(msg,true);
|
if (outPacket!=null) {
|
||||||
msg.setStatus(Message.STATUS_SEND);
|
msg.setStatus(Message.STATUS_SEND);
|
||||||
databaseBackend.updateMessage(msg);
|
databaseBackend.updateMessage(msg);
|
||||||
account.getXmppConnection().sendMessagePacket(outPacket);
|
account.getXmppConnection().sendMessagePacket(outPacket);
|
||||||
} catch (OtrException e) {
|
|
||||||
Log.e(LOGTAG,"error creating otr packet");
|
|
||||||
}
|
}
|
||||||
} else if (msg.getType() == Message.TYPE_IMAGE) {
|
} else if (msg.getType() == Message.TYPE_IMAGE) {
|
||||||
mJingleConnectionManager.createNewConnection(msg);
|
mJingleConnectionManager.createNewConnection(msg);
|
||||||
|
|
Loading…
Reference in a new issue