aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu')
-rw-r--r--src/eu/siacs/conversations/entities/Conversation.java30
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java2
-rw-r--r--src/eu/siacs/conversations/utils/MessageParser.java11
3 files changed, 24 insertions, 19 deletions
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java
index a13d4ea6..79757f1e 100644
--- a/src/eu/siacs/conversations/entities/Conversation.java
+++ b/src/eu/siacs/conversations/entities/Conversation.java
@@ -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;
}
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index 8bc1b389..72abcf5f 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -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
diff --git a/src/eu/siacs/conversations/utils/MessageParser.java b/src/eu/siacs/conversations/utils/MessageParser.java
index 58235678..6d644f03 100644
--- a/src/eu/siacs/conversations/utils/MessageParser.java
+++ b/src/eu/siacs/conversations/utils/MessageParser.java
@@ -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;
}