more otr fixes

This commit is contained in:
Daniel Gultsch 2014-03-21 23:09:14 +01:00
parent 17960c0526
commit ee1c9e611b
3 changed files with 24 additions and 19 deletions

View File

@ -218,18 +218,28 @@ public class Conversation extends AbstractEntity {
this.mode = mode;
}
public void startOtrSession(Context context, String presence) {
public SessionImpl startOtrSession(Context context, String presence, boolean sendStart) {
if (this.otrSession != null) {
return this.otrSession;
} else {
SessionID sessionId = new SessionID(this.getContactJid(), presence,
"xmpp");
this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine(
context));
try {
if (sendStart) {
this.otrSession.startSession();
return this.otrSession;
}
return this.otrSession;
} catch (OtrException e) {
Log.d("xmppServic", "couldnt start otr");
return null;
}
}
}
public SessionImpl getOtrSession() {
return this.otrSession;
}

View File

@ -602,7 +602,7 @@ public class XmppConnectionService extends Service {
if (message.getEncryption() == Message.ENCRYPTION_OTR) {
if (!conv.hasValidOtrSession()) {
// starting otr session. messages will be send later
conv.startOtrSession(getApplicationContext(), presence);
conv.startOtrSession(getApplicationContext(), presence,true);
} else if (conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
// otr session aleary exists, creating message packet
// accordingly

View File

@ -30,7 +30,6 @@ public class MessageParser {
}
public static Message parseOtrChat(MessagePacket packet, Account account, XmppConnectionService service) {
boolean justStarted = false;
boolean properlyAddressed = (packet.getTo().split("/").length == 2) || (account.countPresences() == 1);
String[] fromParts = packet.getFrom().split("/");
Conversation conversation = service.findOrCreateConversation(account, fromParts[0],false);
@ -38,8 +37,7 @@ public class MessageParser {
if (!conversation.hasValidOtrSession()) {
if (properlyAddressed) {
Log.d("xmppService","starting new otr session with "+packet.getFrom()+" because no valid otr session has been found");
conversation.startOtrSession(service.getApplicationContext(), fromParts[1]);
justStarted = true;
conversation.startOtrSession(service.getApplicationContext(), fromParts[1],false);
} else {
Log.d("xmppService",account.getJid()+": ignoring otr session with "+fromParts[0]);
return null;
@ -50,8 +48,7 @@ public class MessageParser {
conversation.resetOtrSession();
if (properlyAddressed) {
Log.d("xmppService","replacing otr session with "+packet.getFrom());
conversation.startOtrSession(service.getApplicationContext(), fromParts[1]);
justStarted = true;
conversation.startOtrSession(service.getApplicationContext(), fromParts[1],false);
} else {
return null;
}
@ -88,9 +85,7 @@ public class MessageParser {
Log.d(LOGTAG,"otr session stoped");
}
} catch (Exception e) {
if (!justStarted) {
conversation.resetOtrSession();
}
return null;
}