aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/entities/Conversation.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-13 23:40:08 +0100
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-13 23:40:08 +0100
commit42c4c1789a75c87b67c38ef9ca3f57ddd10f0548 (patch)
treec5bf69cb73c3e4c3be0439c175774561f8b0a5e7 /src/de/gultsch/chat/entities/Conversation.java
parente63109215e9dda9152f0bc92bf230b652413a677 (diff)
basic otr support
Diffstat (limited to '')
-rw-r--r--src/de/gultsch/chat/entities/Conversation.java54
1 files changed, 43 insertions, 11 deletions
diff --git a/src/de/gultsch/chat/entities/Conversation.java b/src/de/gultsch/chat/entities/Conversation.java
index fba5464a..7339aadb 100644
--- a/src/de/gultsch/chat/entities/Conversation.java
+++ b/src/de/gultsch/chat/entities/Conversation.java
@@ -3,7 +3,16 @@ package de.gultsch.chat.entities;
import java.util.ArrayList;
import java.util.List;
+import de.gultsch.chat.crypto.OtrEngine;
+import de.gultsch.chat.xmpp.XmppConnection;
+
+import net.java.otr4j.OtrException;
+import net.java.otr4j.session.SessionID;
+import net.java.otr4j.session.SessionImpl;
+import net.java.otr4j.session.SessionStatus;
+
import android.content.ContentValues;
+import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
@@ -40,6 +49,9 @@ public class Conversation extends AbstractEntity {
private transient List<Message> messages = null;
private transient Account account = null;
private transient Contact contact;
+
+ private transient SessionImpl otrSession;
+ private transient String foreignOtrPresence;
public Conversation(String name, Account account,
String contactJid, int mode) {
@@ -85,19 +97,13 @@ public class Conversation extends AbstractEntity {
}
}
- public String getLatestMessage() {
- if ((this.messages == null)||(this.messages.size()==0)) {
- return null;
- } else {
- return this.messages.get(this.messages.size() - 1).getBody();
- }
- }
-
- public long getLatestMessageDate() {
+ public Message getLatestMessage() {
if ((this.messages == null)||(this.messages.size()==0)) {
- return this.getCreated();
+ Message message = new Message(this,"",Message.ENCRYPTION_NONE);
+ message.setTime(0);
+ return message;
} else {
- return this.messages.get(this.messages.size() - 1).getTimeSent();
+ return this.messages.get(this.messages.size() - 1);
}
}
@@ -198,4 +204,30 @@ public class Conversation extends AbstractEntity {
public void setMode(int mode) {
this.mode = mode;
}
+
+ public void startOtrSession(Context context, String presence) {
+ Log.d("xmppService","starting otr session with "+presence);
+ SessionID sessionId = new SessionID(this.getContactJid(),presence,"xmpp");
+ this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine(context));
+ }
+
+ public SessionImpl getOtrSession() {
+ return this.otrSession;
+ }
+
+ public void resetOtrSession() {
+ this.otrSession = null;
+ }
+
+ public void endOtrIfNeeded() throws OtrException {
+ if (this.otrSession!=null) {
+ if (this.otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) {
+ this.otrSession.endSession();
+ }
+ }
+ }
+
+ public boolean hasOtrSession() {
+ return (this.otrSession!=null);
+ }
}