From 7e4e7426eeaf2f958820845e48c0d24a92f9bc07 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 4 Jun 2014 18:44:15 +0200 Subject: received and displayed messages (xep 333) are now marked properly --- .../siacs/conversations/entities/Conversation.java | 65 +++++++++++++++------- src/eu/siacs/conversations/entities/Message.java | 2 + 2 files changed, 47 insertions(+), 20 deletions(-) (limited to 'src/eu/siacs/conversations/entities') diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index a96996600..f5542925b 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -4,6 +4,8 @@ import java.security.interfaces.DSAPublicKey; import java.util.ArrayList; import java.util.List; +import eu.siacs.conversations.services.XmppConnectionService; + import net.java.otr4j.OtrException; import net.java.otr4j.crypto.OtrCryptoEngineImpl; import net.java.otr4j.crypto.OtrCryptoException; @@ -44,7 +46,7 @@ public class Conversation extends AbstractEntity { private int status; private long created; private int mode; - + private String nextPresence; private transient List messages = null; @@ -59,6 +61,8 @@ public class Conversation extends AbstractEntity { private transient MucOptions mucOptions = null; + private transient String latestMarkableMessageId; + public Conversation(String name, Account account, String contactJid, int mode) { this(java.util.UUID.randomUUID().toString(), name, null, account @@ -100,15 +104,26 @@ public class Conversation extends AbstractEntity { } public void markRead() { - if (this.messages == null) + if (this.messages == null) { return; + } for (int i = this.messages.size() - 1; i >= 0; --i) { - if (messages.get(i).isRead()) - return; + if (messages.get(i).isRead()) { + break; + } this.messages.get(i).markRead(); } } + public void markRead(XmppConnectionService service) { + markRead(); + if (service.confirmMessages() && this.latestMarkableMessageId != null) { + service.sendConfirmMessage(getAccount(), getContactJid(), + this.latestMarkableMessageId); + this.latestMarkableMessageId = null; + } + } + public Message getLatestMessage() { if ((this.messages == null) || (this.messages.size() == 0)) { Message message = new Message(this, "", Message.ENCRYPTION_NONE); @@ -126,7 +141,8 @@ public class Conversation extends AbstractEntity { } public String getName(boolean useSubject) { - if ((getMode() == MODE_MULTI) && (getMucOptions().getSubject() != null) && useSubject) { + if ((getMode() == MODE_MULTI) && (getMucOptions().getSubject() != null) + && useSubject) { return getMucOptions().getSubject(); } else { return this.getContact().getDisplayName(); @@ -208,14 +224,15 @@ public class Conversation extends AbstractEntity { this.mode = mode; } - public SessionImpl startOtrSession(Context context, String presence, boolean sendStart) { + public SessionImpl startOtrSession(Context context, String presence, + boolean sendStart) { if (this.otrSession != null) { return this.otrSession; } else { SessionID sessionId = new SessionID(this.getContactJid(), presence, "xmpp"); - this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine( - context)); + this.otrSession = new SessionImpl(sessionId, getAccount() + .getOtrEngine(context)); try { if (sendStart) { this.otrSession.startSession(); @@ -226,13 +243,13 @@ public class Conversation extends AbstractEntity { return null; } } - + } public SessionImpl getOtrSession() { return this.otrSession; } - + public void resetOtrSession() { this.otrSession = null; } @@ -240,7 +257,8 @@ public class Conversation extends AbstractEntity { public void endOtrIfNeeded() { if (this.otrSession != null) { if (this.otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) { - Log.d("xmppService","ending otr session with "+getContactJid()); + Log.d("xmppService", "ending otr session with " + + getContactJid()); try { this.otrSession.endSession(); this.resetOtrSession(); @@ -289,44 +307,51 @@ public class Conversation extends AbstractEntity { public void setContactJid(String jid) { this.contactJid = jid; } - + public void setNextPresence(String presence) { this.nextPresence = presence; } - + public String getNextPresence() { return this.nextPresence; } - + public int getLatestEncryption() { int latestEncryption = this.getLatestMessage().getEncryption(); - if ((latestEncryption == Message.ENCRYPTION_DECRYPTED) || (latestEncryption == Message.ENCRYPTION_DECRYPTION_FAILED)) { + if ((latestEncryption == Message.ENCRYPTION_DECRYPTED) + || (latestEncryption == Message.ENCRYPTION_DECRYPTION_FAILED)) { return Message.ENCRYPTION_PGP; } else { return latestEncryption; } } - + public int getNextEncryption() { if (this.nextMessageEncryption == -1) { return this.getLatestEncryption(); } return this.nextMessageEncryption; } - + public void setNextEncryption(int encryption) { this.nextMessageEncryption = encryption; } - + public String getNextMessage() { - if (this.nextMessage==null) { + if (this.nextMessage == null) { return ""; } else { return this.nextMessage; } } - + public void setNextMessage(String message) { this.nextMessage = message; } + + public void setLatestMarkableMessageId(String id) { + if (id != null) { + this.latestMarkableMessageId = id; + } + } } diff --git a/src/eu/siacs/conversations/entities/Message.java b/src/eu/siacs/conversations/entities/Message.java index 950e349e0..b468fef76 100644 --- a/src/eu/siacs/conversations/entities/Message.java +++ b/src/eu/siacs/conversations/entities/Message.java @@ -20,6 +20,8 @@ public class Message extends AbstractEntity { public static final int STATUS_SEND_FAILED = 3; public static final int STATUS_SEND_REJECTED = 4; 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 ENCRYPTION_NONE = 0; public static final int ENCRYPTION_PGP = 1; -- cgit v1.2.3