diff options
Diffstat (limited to 'src/eu/siacs/conversations/entities/Conversation.java')
-rw-r--r-- | src/eu/siacs/conversations/entities/Conversation.java | 65 |
1 files changed, 45 insertions, 20 deletions
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index a9699660..f5542925 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<Message> 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; + } + } } |