aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/entities/Conversation.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/entities/Conversation.java')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Conversation.java74
1 files changed, 40 insertions, 34 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java
index 9d4c36db5..fdffeccba 100644
--- a/src/main/java/eu/siacs/conversations/entities/Conversation.java
+++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java
@@ -1,13 +1,8 @@
package eu.siacs.conversations.entities;
-import java.security.interfaces.DSAPublicKey;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import eu.siacs.conversations.services.XmppConnectionService;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.os.SystemClock;
import net.java.otr4j.OtrException;
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
@@ -15,9 +10,17 @@ import net.java.otr4j.crypto.OtrCryptoException;
import net.java.otr4j.session.SessionID;
import net.java.otr4j.session.SessionImpl;
import net.java.otr4j.session.SessionStatus;
-import android.content.ContentValues;
-import android.database.Cursor;
-import android.os.SystemClock;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.security.interfaces.DSAPublicKey;
+import java.util.ArrayList;
+import java.util.List;
+
+import eu.siacs.conversations.services.XmppConnectionService;
+import eu.siacs.conversations.xmpp.jid.InvalidJidException;
+import eu.siacs.conversations.xmpp.jid.Jid;
public class Conversation extends AbstractEntity {
public static final String TABLENAME = "conversations";
@@ -45,7 +48,7 @@ public class Conversation extends AbstractEntity {
private String name;
private String contactUuid;
private String accountUuid;
- private String contactJid;
+ private Jid contactJid;
private int status;
private long created;
private int mode;
@@ -54,7 +57,7 @@ public class Conversation extends AbstractEntity {
private String nextPresence;
- protected ArrayList<Message> messages = new ArrayList<Message>();
+ protected ArrayList<Message> messages = new ArrayList<>();
protected Account account = null;
private transient SessionImpl otrSession;
@@ -71,17 +74,17 @@ public class Conversation extends AbstractEntity {
private Bookmark bookmark;
- public Conversation(String name, Account account, String contactJid,
- int mode) {
+ public Conversation(final String name, final Account account, final Jid contactJid,
+ final int mode) {
this(java.util.UUID.randomUUID().toString(), name, null, account
.getUuid(), contactJid, System.currentTimeMillis(),
STATUS_AVAILABLE, mode, "");
this.account = account;
}
- public Conversation(String uuid, String name, String contactUuid,
- String accountUuid, String contactJid, long created, int status,
- int mode, String attributes) {
+ public Conversation(final String uuid, final String name, final String contactUuid,
+ final String accountUuid, final Jid contactJid, final long created, final int status,
+ final int mode, final String attributes) {
this.uuid = uuid;
this.name = name;
this.contactUuid = contactUuid;
@@ -91,10 +94,7 @@ public class Conversation extends AbstractEntity {
this.status = status;
this.mode = mode;
try {
- if (attributes == null) {
- attributes = new String();
- }
- this.attributes = new JSONObject(attributes);
+ this.attributes = new JSONObject(attributes == null ? "" : attributes);
} catch (JSONException e) {
this.attributes = new JSONObject();
}
@@ -105,10 +105,8 @@ public class Conversation extends AbstractEntity {
}
public boolean isRead() {
- if ((this.messages == null) || (this.messages.size() == 0))
- return true;
- return this.messages.get(this.messages.size() - 1).isRead();
- }
+ return (this.messages == null) || (this.messages.size() == 0) || this.messages.get(this.messages.size() - 1).isRead();
+ }
public void markRead() {
if (this.messages == null) {
@@ -186,7 +184,7 @@ public class Conversation extends AbstractEntity {
this.account = account;
}
- public String getContactJid() {
+ public Jid getContactJid() {
return this.contactJid;
}
@@ -204,7 +202,7 @@ public class Conversation extends AbstractEntity {
values.put(NAME, name);
values.put(CONTACT, contactUuid);
values.put(ACCOUNT, accountUuid);
- values.put(CONTACTJID, contactJid);
+ values.put(CONTACTJID, contactJid.toString());
values.put(CREATED, created);
values.put(STATUS, status);
values.put(MODE, mode);
@@ -213,11 +211,18 @@ public class Conversation extends AbstractEntity {
}
public static Conversation fromCursor(Cursor cursor) {
- return new Conversation(cursor.getString(cursor.getColumnIndex(UUID)),
+ Jid jid;
+ try {
+ jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(CONTACTJID)));
+ } catch (final InvalidJidException e) {
+ // Borked DB..
+ jid = null;
+ }
+ return new Conversation(cursor.getString(cursor.getColumnIndex(UUID)),
cursor.getString(cursor.getColumnIndex(NAME)),
cursor.getString(cursor.getColumnIndex(CONTACT)),
cursor.getString(cursor.getColumnIndex(ACCOUNT)),
- cursor.getString(cursor.getColumnIndex(CONTACTJID)),
+ jid,
cursor.getLong(cursor.getColumnIndex(CREATED)),
cursor.getInt(cursor.getColumnIndex(STATUS)),
cursor.getInt(cursor.getColumnIndex(MODE)),
@@ -241,8 +246,9 @@ public class Conversation extends AbstractEntity {
if (this.otrSession != null) {
return this.otrSession;
} else {
- SessionID sessionId = new SessionID(this.getContactJid().split("/",
- 2)[0], presence, "xmpp");
+ final SessionID sessionId = new SessionID(this.getContactJid().toBareJid().toString(),
+ presence,
+ "xmpp");
this.otrSession = new SessionImpl(sessionId, getAccount()
.getOtrEngine(service));
try {
@@ -317,7 +323,7 @@ public class Conversation extends AbstractEntity {
builder.insert(26, " ");
builder.insert(35, " ");
this.otrFingerprint = builder.toString();
- } catch (OtrCryptoException e) {
+ } catch (final OtrCryptoException ignored) {
}
}
@@ -335,7 +341,7 @@ public class Conversation extends AbstractEntity {
this.mucOptions = null;
}
- public void setContactJid(String jid) {
+ public void setContactJid(final Jid jid) {
this.contactJid = jid;
}