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; 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, SessionID sessionId = new SessionID(this.getContactJid(), presence,
"xmpp"); "xmpp");
this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine( this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine(
context)); context));
try { try {
if (sendStart) {
this.otrSession.startSession(); this.otrSession.startSession();
return this.otrSession;
}
return this.otrSession;
} catch (OtrException e) { } catch (OtrException e) {
Log.d("xmppServic", "couldnt start otr"); Log.d("xmppServic", "couldnt start otr");
return null;
} }
} }
}
public SessionImpl getOtrSession() { public SessionImpl getOtrSession() {
return this.otrSession; return this.otrSession;
} }

View File

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

View File

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