more otr fixes
This commit is contained in:
parent
17960c0526
commit
ee1c9e611b
|
@ -218,22 +218,32 @@ 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) {
|
||||||
SessionID sessionId = new SessionID(this.getContactJid(), presence,
|
if (this.otrSession != null) {
|
||||||
"xmpp");
|
return this.otrSession;
|
||||||
this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine(
|
} else {
|
||||||
context));
|
SessionID sessionId = new SessionID(this.getContactJid(), presence,
|
||||||
try {
|
"xmpp");
|
||||||
this.otrSession.startSession();
|
this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine(
|
||||||
} catch (OtrException e) {
|
context));
|
||||||
Log.d("xmppServic", "couldnt start otr");
|
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() {
|
public SessionImpl getOtrSession() {
|
||||||
return this.otrSession;
|
return this.otrSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetOtrSession() {
|
public void resetOtrSession() {
|
||||||
this.otrSession = null;
|
this.otrSession = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue