migrated some otr stuff to new jid classes
This commit is contained in:
parent
c310ada8b3
commit
69ef17efc0
|
@ -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;
|
||||||
|
|
||||||
|
@ -78,7 +75,7 @@ public class Message extends AbstractEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message(final Conversation conversation, final Jid counterpart, final String body,
|
public Message(final Conversation conversation, final Jid counterpart, final String body,
|
||||||
final int encryption, final int status) {
|
final int encryption, final int status) {
|
||||||
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
|
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
|
||||||
counterpart, null, body, System.currentTimeMillis(),
|
counterpart, null, body, System.currentTimeMillis(),
|
||||||
encryption, status, TYPE_TEXT, null);
|
encryption, status, TYPE_TEXT, null);
|
||||||
|
@ -86,8 +83,8 @@ public class Message extends AbstractEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message(final String uuid, final String conversationUUid, final Jid counterpart,
|
public Message(final String uuid, final String conversationUUid, final Jid counterpart,
|
||||||
final String trueCounterpart, final String body, final long timeSent,
|
final String trueCounterpart, final String body, final long timeSent,
|
||||||
final int encryption, final int status, final int type, final String remoteMsgId) {
|
final int encryption, final int status, final int type, final String remoteMsgId) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.conversationUuid = conversationUUid;
|
this.conversationUuid = conversationUUid;
|
||||||
this.counterpart = counterpart;
|
this.counterpart = counterpart;
|
||||||
|
@ -100,12 +97,42 @@ public class Message extends AbstractEntity {
|
||||||
this.remoteMsgId = remoteMsgId;
|
this.remoteMsgId = remoteMsgId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Message fromCursor(Cursor cursor) {
|
||||||
|
Jid jid;
|
||||||
|
try {
|
||||||
|
jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(COUNTERPART)));
|
||||||
|
} catch (InvalidJidException e) {
|
||||||
|
jid = null;
|
||||||
|
}
|
||||||
|
return new Message(cursor.getString(cursor.getColumnIndex(UUID)),
|
||||||
|
cursor.getString(cursor.getColumnIndex(CONVERSATION)),
|
||||||
|
jid,
|
||||||
|
cursor.getString(cursor.getColumnIndex(TRUE_COUNTERPART)),
|
||||||
|
cursor.getString(cursor.getColumnIndex(BODY)),
|
||||||
|
cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
|
||||||
|
cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
|
||||||
|
cursor.getInt(cursor.getColumnIndex(STATUS)),
|
||||||
|
cursor.getInt(cursor.getColumnIndex(TYPE)),
|
||||||
|
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
|
@Override
|
||||||
public ContentValues getContentValues() {
|
public ContentValues getContentValues() {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(UUID, uuid);
|
values.put(UUID, uuid);
|
||||||
values.put(CONVERSATION, conversationUuid);
|
values.put(CONVERSATION, conversationUuid);
|
||||||
values.put(COUNTERPART, counterpart.toString());
|
if (counterpart == null) {
|
||||||
|
values.putNull(COUNTERPART);
|
||||||
|
} else {
|
||||||
|
values.put(COUNTERPART, counterpart.toString());
|
||||||
|
}
|
||||||
values.put(TRUE_COUNTERPART, trueCounterpart);
|
values.put(TRUE_COUNTERPART, trueCounterpart);
|
||||||
values.put(BODY, body);
|
values.put(BODY, body);
|
||||||
values.put(TIME_SENT, timeSent);
|
values.put(TIME_SENT, timeSent);
|
||||||
|
@ -124,10 +151,18 @@ public class Message extends AbstractEntity {
|
||||||
return this.conversation;
|
return this.conversation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setConversation(Conversation conv) {
|
||||||
|
this.conversation = conv;
|
||||||
|
}
|
||||||
|
|
||||||
public Jid getCounterpart() {
|
public Jid getCounterpart() {
|
||||||
return counterpart;
|
return counterpart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCounterpart(final Jid counterpart) {
|
||||||
|
this.counterpart = counterpart;
|
||||||
|
}
|
||||||
|
|
||||||
public Contact getContact() {
|
public Contact getContact() {
|
||||||
if (this.conversation.getMode() == Conversation.MODE_SINGLE) {
|
if (this.conversation.getMode() == Conversation.MODE_SINGLE) {
|
||||||
return this.conversation.getContact();
|
return this.conversation.getContact();
|
||||||
|
@ -145,6 +180,10 @@ public class Message extends AbstractEntity {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setBody(String body) {
|
||||||
|
this.body = body;
|
||||||
|
}
|
||||||
|
|
||||||
public long getTimeSent() {
|
public long getTimeSent() {
|
||||||
return timeSent;
|
return timeSent;
|
||||||
}
|
}
|
||||||
|
@ -153,10 +192,18 @@ public class Message extends AbstractEntity {
|
||||||
return encryption;
|
return encryption;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEncryption(int encryption) {
|
||||||
|
this.encryption = encryption;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStatus() {
|
public int getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
public String getRemoteMsgId() {
|
public String getRemoteMsgId() {
|
||||||
return this.remoteMsgId;
|
return this.remoteMsgId;
|
||||||
}
|
}
|
||||||
|
@ -165,33 +212,6 @@ public class Message extends AbstractEntity {
|
||||||
this.remoteMsgId = id;
|
this.remoteMsgId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Message fromCursor(Cursor cursor) {
|
|
||||||
Jid jid;
|
|
||||||
try {
|
|
||||||
jid = Jid.fromString(cursor.getString(cursor.getColumnIndex(COUNTERPART)));
|
|
||||||
} catch (InvalidJidException e) {
|
|
||||||
jid = null;
|
|
||||||
}
|
|
||||||
return new Message(cursor.getString(cursor.getColumnIndex(UUID)),
|
|
||||||
cursor.getString(cursor.getColumnIndex(CONVERSATION)),
|
|
||||||
jid,
|
|
||||||
cursor.getString(cursor.getColumnIndex(TRUE_COUNTERPART)),
|
|
||||||
cursor.getString(cursor.getColumnIndex(BODY)),
|
|
||||||
cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
|
|
||||||
cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
|
|
||||||
cursor.getInt(cursor.getColumnIndex(STATUS)),
|
|
||||||
cursor.getInt(cursor.getColumnIndex(TYPE)),
|
|
||||||
cursor.getString(cursor.getColumnIndex(REMOTE_MSG_ID)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConversation(Conversation conv) {
|
|
||||||
this.conversation = conv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(int status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -314,7 +315,7 @@ public class Message extends AbstractEntity {
|
||||||
.getStatus() == Message.STATUS_SEND_RECEIVED) && (message
|
.getStatus() == Message.STATUS_SEND_RECEIVED) && (message
|
||||||
.getStatus() == Message.STATUS_UNSEND
|
.getStatus() == Message.STATUS_UNSEND
|
||||||
|| message.getStatus() == Message.STATUS_SEND || message
|
|| message.getStatus() == Message.STATUS_SEND || message
|
||||||
.getStatus() == Message.STATUS_SEND_DISPLAYED))))
|
.getStatus() == Message.STATUS_SEND_DISPLAYED))))
|
||||||
&& !message.bodyContainsDownloadable()
|
&& !message.bodyContainsDownloadable()
|
||||||
&& !this.bodyContainsDownloadable());
|
&& !this.bodyContainsDownloadable());
|
||||||
}
|
}
|
||||||
|
@ -347,9 +348,9 @@ public class Message extends AbstractEntity {
|
||||||
|
|
||||||
public boolean wasMergedIntoPrevious() {
|
public boolean wasMergedIntoPrevious() {
|
||||||
Message prev = this.prev();
|
Message prev = this.prev();
|
||||||
return prev != null && prev.mergeable(this);
|
return prev != null && prev.mergeable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean trusted() {
|
public boolean trusted() {
|
||||||
Contact contact = this.getContact();
|
Contact contact = this.getContact();
|
||||||
return (status > STATUS_RECEIVED || (contact != null && contact.trusted()));
|
return (status > STATUS_RECEIVED || (contact != null && contact.trusted()));
|
||||||
|
@ -375,14 +376,14 @@ public class Message extends AbstractEntity {
|
||||||
String[] extensionParts = filename.split("\\.");
|
String[] extensionParts = filename.split("\\.");
|
||||||
if (extensionParts.length == 2
|
if (extensionParts.length == 2
|
||||||
&& Arrays.asList(Downloadable.VALID_EXTENSIONS).contains(
|
&& Arrays.asList(Downloadable.VALID_EXTENSIONS).contains(
|
||||||
extensionParts[extensionParts.length - 1])) {
|
extensionParts[extensionParts.length - 1])) {
|
||||||
return true;
|
return true;
|
||||||
} else if (extensionParts.length == 3
|
} else if (extensionParts.length == 3
|
||||||
&& Arrays
|
&& Arrays
|
||||||
.asList(Downloadable.VALID_CRYPTO_EXTENSIONS)
|
.asList(Downloadable.VALID_CRYPTO_EXTENSIONS)
|
||||||
.contains(extensionParts[extensionParts.length - 1])
|
.contains(extensionParts[extensionParts.length - 1])
|
||||||
&& Arrays.asList(Downloadable.VALID_EXTENSIONS).contains(
|
&& Arrays.asList(Downloadable.VALID_EXTENSIONS).contains(
|
||||||
extensionParts[extensionParts.length - 2])) {
|
extensionParts[extensionParts.length - 2])) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -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();
|
||||||
|
@ -457,7 +458,7 @@ public class Message extends AbstractEntity {
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageParams getLegacyImageParams() {
|
public ImageParams getLegacyImageParams() {
|
||||||
ImageParams params = new ImageParams();
|
ImageParams params = new ImageParams();
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
packet = mMessageGenerator.generateOtrChat(message);
|
if (conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) {
|
||||||
send = true;
|
packet = mMessageGenerator.generateOtrChat(message);
|
||||||
|
send = true;
|
||||||
} else if (message.getCounterpart() == null) {
|
} else {
|
||||||
conv.startOtrIfNeeded();
|
message.setStatus(Message.STATUS_WAITING);
|
||||||
|
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) {
|
||||||
|
|
Loading…
Reference in New Issue