mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 03:32:15 -05:00
more otr fixes
This commit is contained in:
parent
17960c0526
commit
ee1c9e611b
@ -218,22 +218,32 @@ public class Conversation extends AbstractEntity {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public void startOtrSession(Context context, String presence) {
|
||||
SessionID sessionId = new SessionID(this.getContactJid(), presence,
|
||||
"xmpp");
|
||||
this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine(
|
||||
context));
|
||||
try {
|
||||
this.otrSession.startSession();
|
||||
} catch (OtrException e) {
|
||||
Log.d("xmppServic", "couldnt start otr");
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
public void resetOtrSession() {
|
||||
this.otrSession = null;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
conversation.resetOtrSession();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user