This commit is contained in:
Daniel Gultsch 2014-03-12 19:56:06 +01:00
parent 848fb2ec24
commit c67238562a
2 changed files with 11 additions and 16 deletions

View file

@ -232,13 +232,17 @@ public class Conversation extends AbstractEntity {
this.otrSession = null; this.otrSession = null;
} }
public void endOtrIfNeeded() throws OtrException { public void endOtrIfNeeded() {
if (this.otrSession!=null) { if (this.otrSession!=null) {
if (this.otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) { if (this.otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) {
try {
this.otrSession.endSession(); this.otrSession.endSession();
}
}
this.resetOtrSession(); this.resetOtrSession();
} catch (OtrException e) {
this.resetOtrSession();
}
}
}
} }
public boolean hasValidOtrSession() { public boolean hasValidOtrSession() {

View file

@ -567,6 +567,7 @@ public class XmppConnectionService extends Service {
saveInDb = true; saveInDb = true;
addToConversation = true; addToConversation = true;
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) { } else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
message.getConversation().endOtrIfNeeded();
long keyId = message.getConversation().getContact() long keyId = message.getConversation().getContact()
.getPgpKeyId(); .getPgpKeyId();
packet = new MessagePacket(); packet = new MessagePacket();
@ -586,6 +587,7 @@ public class XmppConnectionService extends Service {
saveInDb = true; saveInDb = true;
addToConversation = true; addToConversation = true;
} else { } else {
message.getConversation().endOtrIfNeeded();
// don't encrypt // don't encrypt
if (message.getConversation().getMode() == Conversation.MODE_SINGLE) { if (message.getConversation().getMode() == Conversation.MODE_SINGLE) {
message.setStatus(Message.STATUS_SEND); message.setStatus(Message.STATUS_SEND);
@ -873,13 +875,7 @@ public class XmppConnectionService extends Service {
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
leaveMuc(conversation); leaveMuc(conversation);
} else { } else {
try {
conversation.endOtrIfNeeded(); conversation.endOtrIfNeeded();
} catch (OtrException e) {
Log.d(LOGTAG,
"error ending otr session for "
+ conversation.getName());
}
} }
this.databaseBackend.updateConversation(conversation); this.databaseBackend.updateConversation(conversation);
this.conversations.remove(conversation); this.conversations.remove(conversation);
@ -1068,12 +1064,7 @@ public class XmppConnectionService extends Service {
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
leaveMuc(conversation); leaveMuc(conversation);
} else { } else {
try {
conversation.endOtrIfNeeded(); conversation.endOtrIfNeeded();
} catch (OtrException e) {
Log.d(LOGTAG, "error ending otr session for "
+ conversation.getName());
}
} }
} }
} }