diff options
Diffstat (limited to 'src/eu/siacs/conversations/entities/Conversation.java')
-rw-r--r-- | src/eu/siacs/conversations/entities/Conversation.java | 74 |
1 files changed, 48 insertions, 26 deletions
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index 439f9f22..005b83db 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -4,6 +4,7 @@ import java.security.interfaces.DSAPublicKey; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.UIHelper; import net.java.otr4j.OtrException; @@ -16,6 +17,7 @@ import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; +import android.os.SystemClock; public class Conversation extends AbstractEntity { public static final String TABLENAME = "conversations"; @@ -43,6 +45,8 @@ public class Conversation extends AbstractEntity { private long created; private int mode; + private long mutedTill = 0; + private String nextPresence; private transient CopyOnWriteArrayList<Message> messages = null; @@ -88,7 +92,8 @@ public class Conversation extends AbstractEntity { public List<Message> getMessages() { if (messages == null) { - this.messages = new CopyOnWriteArrayList<Message>(); // prevent null pointer + this.messages = new CopyOnWriteArrayList<Message>(); // prevent null + // pointer } // populate with Conversation (this) @@ -140,9 +145,8 @@ public class Conversation extends AbstractEntity { this.messages = msgs; } - public String getName(boolean useSubject) { - if ((getMode() == MODE_MULTI) && (getMucOptions().getSubject() != null) - && useSubject) { + public String getName() { + if (getMode() == MODE_MULTI && getMucOptions().getSubject() != null) { return getMucOptions().getSubject(); } else if (getMode() == MODE_MULTI && bookmark != null && bookmark.getName() != null) { @@ -220,15 +224,15 @@ public class Conversation extends AbstractEntity { this.mode = mode; } - public SessionImpl startOtrSession(Context context, String presence, - boolean sendStart) { + public SessionImpl startOtrSession(XmppConnectionService service, + String presence, boolean sendStart) { if (this.otrSession != null) { return this.otrSession; } else { - SessionID sessionId = new SessionID(this.getContactJid(), presence, - "xmpp"); + SessionID sessionId = new SessionID( + this.getContactJid().split("/")[0], presence, "xmpp"); this.otrSession = new SessionImpl(sessionId, getAccount() - .getOtrEngine(context)); + .getOtrEngine(service)); try { if (sendStart) { this.otrSession.startSession(); @@ -287,7 +291,7 @@ public class Conversation extends AbstractEntity { public String getOtrFingerprint() { if (this.otrFingerprint == null) { try { - if (getOtrSession()== null) { + if (getOtrSession() == null) { return ""; } DSAPublicKey remotePubKey = (DSAPublicKey) getOtrSession() @@ -335,26 +339,36 @@ public class Conversation extends AbstractEntity { if ((latestEncryption == Message.ENCRYPTION_DECRYPTED) || (latestEncryption == Message.ENCRYPTION_DECRYPTION_FAILED)) { return Message.ENCRYPTION_PGP; - } else if (latestEncryption == Message.ENCRYPTION_NONE) { - if (getContact().getPresences().size() == 1) { - if (getContact().getOtrFingerprints().size() >= 1) { - return Message.ENCRYPTION_OTR; - } else { - return latestEncryption; - } - } else { - return latestEncryption; - } } else { return latestEncryption; } } - public int getNextEncryption() { + public int getNextEncryption(boolean force) { if (this.nextMessageEncryption == -1) { - return this.getLatestEncryption(); + int latest = this.getLatestEncryption(); + if (latest == Message.ENCRYPTION_NONE) { + if (force && getMode() == MODE_SINGLE) { + return Message.ENCRYPTION_OTR; + } else if (getContact().getPresences().size() == 1) { + if (getContact().getOtrFingerprints().size() >= 1) { + return Message.ENCRYPTION_OTR; + } else { + return latest; + } + } else { + return latest; + } + } else { + return latest; + } + } + if (this.nextMessageEncryption == Message.ENCRYPTION_NONE && force + && getMode() == MODE_SINGLE) { + return Message.ENCRYPTION_OTR; + } else { + return this.nextMessageEncryption; } - return this.nextMessageEncryption; } public void setNextEncryption(int encryption) { @@ -403,19 +417,27 @@ public class Conversation extends AbstractEntity { } public Bitmap getImage(Context context, int size) { - if (mode==MODE_SINGLE) { + if (mode == MODE_SINGLE) { return getContact().getImage(size, context); } else { return UIHelper.getContactPicture(this, size, context, false); } } - + public boolean hasDuplicateMessage(Message message) { - for(int i = this.getMessages().size() -1; i >= 0; --i) { + for (int i = this.getMessages().size() - 1; i >= 0; --i) { if (this.messages.get(i).equals(message)) { return true; } } return false; } + + public void setMutedTill(long mutedTill) { + this.mutedTill = mutedTill; + } + + public boolean isMuted() { + return SystemClock.elapsedRealtime() < this.mutedTill; + } } |