migrated some otr stuff to new jid classes

This commit is contained in:
iNPUTmice 2014-11-09 17:46:00 +01:00
parent c310ada8b3
commit 69ef17efc0
2 changed files with 82 additions and 79 deletions

View file

@ -1,5 +1,8 @@
package eu.siacs.conversations.entities; package eu.siacs.conversations.entities;
import android.content.ContentValues;
import android.database.Cursor;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
@ -8,9 +11,6 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
import android.content.ContentValues;
import android.database.Cursor;
public class Message extends AbstractEntity { public class Message extends AbstractEntity {
public static final String TABLENAME = "messages"; public static final String TABLENAME = "messages";
@ -45,7 +45,7 @@ public class Message extends AbstractEntity {
public static String STATUS = "status"; public static String STATUS = "status";
public static String TYPE = "type"; public static String TYPE = "type";
public static String REMOTE_MSG_ID = "remoteMsgId"; public static String REMOTE_MSG_ID = "remoteMsgId";
public boolean markable = false;
protected String conversationUuid; protected String conversationUuid;
protected Jid counterpart; protected Jid counterpart;
protected String trueCounterpart; protected String trueCounterpart;
@ -57,11 +57,8 @@ public class Message extends AbstractEntity {
protected int type; protected int type;
protected boolean read = true; protected boolean read = true;
protected String remoteMsgId = null; protected String remoteMsgId = null;
protected Conversation conversation = null; protected Conversation conversation = null;
protected Downloadable downloadable = null; protected Downloadable downloadable = null;
public boolean markable = false;
private Message mNextMessage = null; private Message mNextMessage = null;
private Message mPreviousMessage = null; private Message mPreviousMessage = null;
@ -100,71 +97,6 @@ public class Message extends AbstractEntity {
this.remoteMsgId = remoteMsgId; this.remoteMsgId = remoteMsgId;
} }
@Override
public ContentValues getContentValues() {
ContentValues values = new ContentValues();
values.put(UUID, uuid);
values.put(CONVERSATION, conversationUuid);
values.put(COUNTERPART, counterpart.toString());
values.put(TRUE_COUNTERPART, trueCounterpart);
values.put(BODY, body);
values.put(TIME_SENT, timeSent);
values.put(ENCRYPTION, encryption);
values.put(STATUS, status);
values.put(TYPE, type);
values.put(REMOTE_MSG_ID, remoteMsgId);
return values;
}
public String getConversationUuid() {
return conversationUuid;
}
public Conversation getConversation() {
return this.conversation;
}
public Jid getCounterpart() {
return counterpart;
}
public Contact getContact() {
if (this.conversation.getMode() == Conversation.MODE_SINGLE) {
return this.conversation.getContact();
} else {
if (this.trueCounterpart == null) {
return null;
} else {
return this.conversation.getAccount().getRoster()
.getContactFromRoster(this.trueCounterpart);
}
}
}
public String getBody() {
return body;
}
public long getTimeSent() {
return timeSent;
}
public int getEncryption() {
return encryption;
}
public int getStatus() {
return status;
}
public String getRemoteMsgId() {
return this.remoteMsgId;
}
public void setRemoteMsgId(String id) {
this.remoteMsgId = id;
}
public static Message fromCursor(Cursor cursor) { public static Message fromCursor(Cursor cursor) {
Jid jid; Jid jid;
try { try {
@ -184,14 +116,102 @@ public class Message extends AbstractEntity {
cursor.getString(cursor.getColumnIndex(REMOTE_MSG_ID))); cursor.getString(cursor.getColumnIndex(REMOTE_MSG_ID)));
} }
public static Message createStatusMessage(Conversation conversation) {
Message message = new Message();
message.setType(Message.TYPE_STATUS);
message.setConversation(conversation);
return message;
}
@Override
public ContentValues getContentValues() {
ContentValues values = new ContentValues();
values.put(UUID, uuid);
values.put(CONVERSATION, conversationUuid);
if (counterpart == null) {
values.putNull(COUNTERPART);
} else {
values.put(COUNTERPART, counterpart.toString());
}
values.put(TRUE_COUNTERPART, trueCounterpart);
values.put(BODY, body);
values.put(TIME_SENT, timeSent);
values.put(ENCRYPTION, encryption);
values.put(STATUS, status);
values.put(TYPE, type);
values.put(REMOTE_MSG_ID, remoteMsgId);
return values;
}
public String getConversationUuid() {
return conversationUuid;
}
public Conversation getConversation() {
return this.conversation;
}
public void setConversation(Conversation conv) { public void setConversation(Conversation conv) {
this.conversation = conv; this.conversation = conv;
} }
public Jid getCounterpart() {
return counterpart;
}
public void setCounterpart(final Jid counterpart) {
this.counterpart = counterpart;
}
public Contact getContact() {
if (this.conversation.getMode() == Conversation.MODE_SINGLE) {
return this.conversation.getContact();
} else {
if (this.trueCounterpart == null) {
return null;
} else {
return this.conversation.getAccount().getRoster()
.getContactFromRoster(this.trueCounterpart);
}
}
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public long getTimeSent() {
return timeSent;
}
public int getEncryption() {
return encryption;
}
public void setEncryption(int encryption) {
this.encryption = encryption;
}
public int getStatus() {
return status;
}
public void setStatus(int status) { public void setStatus(int status) {
this.status = status; this.status = status;
} }
public String getRemoteMsgId() {
return this.remoteMsgId;
}
public void setRemoteMsgId(String id) {
this.remoteMsgId = id;
}
public boolean isRead() { public boolean isRead() {
return this.read; return this.read;
} }
@ -208,14 +228,6 @@ public class Message extends AbstractEntity {
this.timeSent = time; this.timeSent = time;
} }
public void setEncryption(int encryption) {
this.encryption = encryption;
}
public void setBody(String body) {
this.body = body;
}
public String getEncryptedBody() { public String getEncryptedBody() {
return this.encryptedBody; return this.encryptedBody;
} }
@ -224,35 +236,24 @@ public class Message extends AbstractEntity {
this.encryptedBody = body; this.encryptedBody = body;
} }
public void setType(int type) {
this.type = type;
}
public int getType() { public int getType() {
return this.type; return this.type;
} }
public void setType(int type) {
this.type = type;
}
public void setTrueCounterpart(String trueCounterpart) { public void setTrueCounterpart(String trueCounterpart) {
this.trueCounterpart = trueCounterpart; this.trueCounterpart = trueCounterpart;
} }
public void setDownloadable(Downloadable downloadable) {
this.downloadable = downloadable;
}
public Downloadable getDownloadable() { public Downloadable getDownloadable() {
return this.downloadable; return this.downloadable;
} }
public static Message createStatusMessage(Conversation conversation) { public void setDownloadable(Downloadable downloadable) {
Message message = new Message(); this.downloadable = downloadable;
message.setType(Message.TYPE_STATUS);
message.setConversation(conversation);
return message;
}
public void setCounterpart(final Jid counterpart) {
this.counterpart = counterpart;
} }
public boolean equals(Message message) { public boolean equals(Message message) {
@ -394,7 +395,7 @@ public class Message extends AbstractEntity {
public ImageParams getImageParams() { public ImageParams getImageParams() {
ImageParams params = getLegacyImageParams(); ImageParams params = getLegacyImageParams();
if (params!=null) { if (params != null) {
return params; return params;
} }
params = new ImageParams(); params = new ImageParams();

View file

@ -585,19 +585,21 @@ public class XmppConnectionService extends Service {
if (!conv.hasValidOtrSession()&& (message.getCounterpart() != null)) { if (!conv.hasValidOtrSession()&& (message.getCounterpart() != null)) {
conv.startOtrSession(this, message.getCounterpart().getResourcepart(), true); conv.startOtrSession(this, message.getCounterpart().getResourcepart(), true);
message.setStatus(Message.STATUS_WAITING); message.setStatus(Message.STATUS_WAITING);
} else if (conv.hasValidOtrSession() } else if (conv.hasValidOtrSession()) {
&& conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
SessionID id = conv.getOtrSession().getSessionID(); SessionID id = conv.getOtrSession().getSessionID();
try { try {
message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID())); message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
message.setCounterpart(null); message.setCounterpart(null);
} }
if (conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
packet = mMessageGenerator.generateOtrChat(message); packet = mMessageGenerator.generateOtrChat(message);
send = true; send = true;
} else {
} else if (message.getCounterpart() == null) { message.setStatus(Message.STATUS_WAITING);
conv.startOtrIfNeeded(); conv.startOtrIfNeeded();
}
} else {
message.setStatus(Message.STATUS_WAITING); message.setStatus(Message.STATUS_WAITING);
} }
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { } else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {