aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/entities/Message.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Message.java151
1 files changed, 83 insertions, 68 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
index 36ab036e..86adb4af 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Message.java
@@ -9,8 +9,11 @@ import java.net.URL;
import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession;
import de.thedevstack.conversationsplus.dto.LoadAvatarFor;
import de.thedevstack.conversationsplus.enums.FileStatus;
+import de.thedevstack.conversationsplus.enums.MessageConfirmation;
+import de.thedevstack.conversationsplus.enums.MessageDirection;
+import de.thedevstack.conversationsplus.enums.MessageStatus;
import de.thedevstack.conversationsplus.utils.FileUtils;
-import de.thedevstack.conversationsplus.utils.MessageUtil;
+import de.thedevstack.conversationsplus.utils.MessageParserUtil;
import de.thedevstack.conversationsplus.utils.MimeUtils;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
@@ -19,16 +22,6 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
public static final String TABLENAME = "messages";
- public static final int STATUS_RECEIVED = 0;
- public static final int STATUS_UNSEND = 1;
- public static final int STATUS_SEND = 2;
- public static final int STATUS_SEND_FAILED = 3;
- public static final int STATUS_WAITING = 5;
- public static final int STATUS_OFFERED = 6;
- public static final int STATUS_SEND_RECEIVED = 7;
- public static final int STATUS_SEND_DISPLAYED = 8;
- public static final int STATUS_SEND_CANCELED = 9; // FIXME This bullshit is needed until status is handled more properly
-
public static final int ENCRYPTION_NONE = 0;
public static final int ENCRYPTION_PGP = 1;
public static final int ENCRYPTION_OTR = 2;
@@ -69,11 +62,13 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
protected String encryptedBody;
protected long timeSent;
protected int encryption;
- protected int status;
protected int type;
+ /**
+ * Indicates that a message was received via
+ * Message Carbons (XEP-0280)
+ */
protected boolean carbon = false;
protected boolean oob = false;
- protected String edited = null;
protected String relativeFilePath;
protected boolean read = true;
protected String remoteMsgId = null;
@@ -87,16 +82,29 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
private boolean httpUploaded;
private FileParams fileParams;
+ /**
+ * The direction of the message,
+ * incoming is a msg received from a jid,
+ * outgoing is a msg sent to a jid
+ */
+ private MessageDirection direction;
+ private MessageStatus messageStatus;
+ /**
+ * Indicates that a message was received via
+ * Message Archive Management (XEP-0313)
+ */
+ private boolean mamReceived;
- private Message() {
+ /**
+ * Whether Delivery Receipts (XEP-0184) and/ or Chat Markers (XEP-0333)
+ * need to be requested and processed (outgoing msgs) or sent (incoming msgs)
+ */
+ private MessageConfirmation confirmation;
+ public Message() {
}
public Message(Conversation conversation, String body, int encryption) {
- this(conversation, body, encryption, STATUS_UNSEND);
- }
-
- public Message(Conversation conversation, String body, int encryption, int status) {
this(java.util.UUID.randomUUID().toString(),
conversation.getUuid(),
conversation.getJid() == null ? null : conversation.getJid().toBareJid(),
@@ -104,7 +112,6 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
body,
System.currentTimeMillis(),
encryption,
- status,
TYPE_TEXT,
false,
null,
@@ -112,17 +119,16 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
null,
null,
true,
- null,
false);
this.conversation = conversation;
}
private Message(final String uuid, final String conversationUUid, final Jid counterpart,
final Jid trueCounterpart, final String body, final long timeSent,
- final int encryption, final int status, final int type, final boolean carbon,
+ final int encryption, final int type, final boolean carbon,
final String remoteMsgId, final String relativeFilePath,
final String serverMsgId, final String fingerprint, final boolean read,
- final String edited, final boolean oob) {
+ final boolean oob) {
this.uuid = uuid;
this.conversationUuid = conversationUUid;
this.counterpart = counterpart;
@@ -130,7 +136,6 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
this.body = body;
this.timeSent = timeSent;
this.encryption = encryption;
- this.status = status;
this.type = type;
this.carbon = carbon;
this.remoteMsgId = remoteMsgId;
@@ -138,7 +143,6 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
this.serverMsgId = serverMsgId;
this.axolotlFingerprint = fingerprint;
this.read = read;
- this.edited = edited;
this.oob = oob;
}
@@ -172,7 +176,6 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
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.getInt(cursor.getColumnIndex(CARBON)) > 0,
cursor.getString(cursor.getColumnIndex(REMOTE_MSG_ID)),
@@ -180,18 +183,9 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
cursor.getString(cursor.getColumnIndex(SERVER_MSG_ID)),
cursor.getString(cursor.getColumnIndex(FINGERPRINT)),
cursor.getInt(cursor.getColumnIndex(READ)) > 0,
- cursor.getString(cursor.getColumnIndex(EDITED)),
cursor.getInt(cursor.getColumnIndex(OOB)) > 0);
}
- public static Message createStatusMessage(Conversation conversation, String body) {
- final Message message = new Message();
- message.setType(Message.TYPE_STATUS);
- message.setConversation(conversation);
- message.setBody(body);
- return message;
- }
-
@Override
public ContentValues getContentValues() {
ContentValues values = new ContentValues();
@@ -210,7 +204,6 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
values.put(BODY, body);
values.put(TIME_SENT, timeSent);
values.put(ENCRYPTION, encryption);
- values.put(STATUS, status);
values.put(TYPE, type);
values.put(CARBON, carbon ? 1 : 0);
values.put(REMOTE_MSG_ID, remoteMsgId);
@@ -218,7 +211,6 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
values.put(SERVER_MSG_ID, serverMsgId);
values.put(FINGERPRINT, axolotlFingerprint);
values.put(READ,read ? 1 : 0);
- values.put(EDITED, edited);
values.put(OOB, oob ? 1 : 0);
return values;
}
@@ -276,14 +268,6 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
this.encryption = encryption;
}
- public int getStatus() {
- return status;
- }
-
- public void setStatus(int status) {
- this.status = status;
- }
-
public String getRelativeFilePath() {
return this.relativeFilePath;
}
@@ -351,10 +335,6 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
this.carbon = carbon;
}
- public boolean edited() {
- return this.edited != null;
- }
-
public void setTrueCounterpart(Jid trueCounterpart) {
this.trueCounterpart = trueCounterpart;
}
@@ -367,6 +347,37 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
this.transferable = transferable;
}
+
+ public boolean isMamReceived() {
+ return mamReceived;
+ }
+
+ public void setMamReceived(boolean mamReceived) {
+ this.mamReceived = mamReceived;
+ }
+
+ public MessageConfirmation getConfirmation() {
+ return confirmation;
+ }
+
+ public void setConfirmation(MessageConfirmation confirmation) {
+ this.confirmation = confirmation;
+ }
+
+ @Override
+ public int hashCode() {
+ if (null != this.getServerMsgId()) {
+ return this.getServerMsgId().hashCode();
+ } else if (null != this.getRemoteMsgId()) {
+ return this.getRemoteMsgId().hashCode();
+ } else if (null != this.getUuid()) {
+ return this.getUuid().hashCode();
+ } else if (null != this.getBody()){
+ return this.getBody().hashCode();
+ }
+ return super.hashCode();
+ }
+
public boolean equals(Message message) {
if (this.getServerMsgId() != null && message.getServerMsgId() != null) {
return this.getServerMsgId().equals(message.getServerMsgId());
@@ -400,12 +411,7 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
public Message next() {
synchronized (this.conversation.messages) {
if (this.mNextMessage == null) {
- int index = this.conversation.messages.indexOf(this);
- if (index < 0 || index >= this.conversation.messages.size() - 1) {
- this.mNextMessage = null;
- } else {
- this.mNextMessage = this.conversation.messages.get(index + 1);
- }
+ this.mNextMessage = this.conversation.messages.higher(this);
}
return this.mNextMessage;
}
@@ -414,12 +420,7 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
public Message prev() {
synchronized (this.conversation.messages) {
if (this.mPreviousMessage == null) {
- int index = this.conversation.messages.indexOf(this);
- if (index <= 0 || index > this.conversation.messages.size()) {
- this.mPreviousMessage = null;
- } else {
- this.mPreviousMessage = this.conversation.messages.get(index - 1);
- }
+ this.mPreviousMessage = this.conversation.messages.lower(this);
}
return this.mPreviousMessage;
}
@@ -439,7 +440,7 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
public boolean trusted() {
Contact contact = this.getContact();
- return (status > STATUS_RECEIVED || (contact != null && contact.trusted()));
+ return contact != null && contact.trusted();
}
public boolean fixCounterpart() {
@@ -466,10 +467,6 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
this.uuid = uuid;
}
- public String getEditedId() {
- return edited;
- }
-
public void setOob(boolean isOob) {
this.oob = isOob;
}
@@ -505,17 +502,19 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
mTreatAsDownloadAble = Decision.NEVER;
}
+ @Deprecated
public void setTreatAsDownloadable(Decision downloadable) {
this.mTreatAsDownloadAble = downloadable;
}
+ @Deprecated
public Decision treatAsDownloadable() {
// only test this ones, body will not change
if (mTreatAsDownloadAble != Decision.NOT_DECIDED) {
return mTreatAsDownloadAble;
}
- MessageUtil.extractFileParamsFromBody(this);
+ MessageParserUtil.extractFileParamsFromBody(this);
return this.mTreatAsDownloadAble;
}
@@ -561,7 +560,7 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
private int getPreviousEncryption() {
for (Message iterator = this.prev(); iterator != null; iterator = iterator.prev()){
- if( iterator.isCarbon() || iterator.getStatus() == STATUS_RECEIVED ) {
+ if( iterator.isCarbon() || MessageDirection.IN == iterator.getDirection()) {
continue;
}
return iterator.getEncryption();
@@ -571,7 +570,7 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
private int getNextEncryption() {
for (Message iterator = this.next(); iterator != null; iterator = iterator.next()){
- if( iterator.isCarbon() || iterator.getStatus() == STATUS_RECEIVED ) {
+ if( iterator.isCarbon() || MessageDirection.IN == iterator.getDirection()) {
continue;
}
return iterator.getEncryption();
@@ -606,6 +605,22 @@ public class Message extends AbstractEntity implements LoadAvatarFor {
this.fileParams = params;
}
+ public MessageDirection getDirection() {
+ return direction;
+ }
+
+ public void setDirection(MessageDirection direction) {
+ this.direction = direction;
+ }
+
+ public MessageStatus getMessageStatus() {
+ return messageStatus;
+ }
+
+ public void setMessageStatus(MessageStatus messageStatus) {
+ this.messageStatus = messageStatus;
+ }
+
private static int getCleanedEncryption(int encryption) {
if (encryption == ENCRYPTION_DECRYPTED || encryption == ENCRYPTION_DECRYPTION_FAILED) {
return ENCRYPTION_PGP;