diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2014-03-14 22:40:56 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2014-03-14 22:40:56 +0100 |
commit | b1a3d09ca6a4be59b57e2f7b1cdc8a245d60a858 (patch) | |
tree | ca6d7f5eafd7bbe3deff4e9ad7a1f4a9a0a77bf3 /src/eu/siacs/conversations/entities | |
parent | 4e4a767743a62d1f88814e5cf024bf983772df2c (diff) |
use conference subject to identiy room
Diffstat (limited to 'src/eu/siacs/conversations/entities')
-rw-r--r-- | src/eu/siacs/conversations/entities/Conversation.java | 117 | ||||
-rw-r--r-- | src/eu/siacs/conversations/entities/MucOptions.java | 9 |
2 files changed, 72 insertions, 54 deletions
diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index aad072cf..b4ec210c 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -4,9 +4,6 @@ import java.security.interfaces.DSAPublicKey; import java.util.ArrayList; import java.util.List; -import eu.siacs.conversations.crypto.OtrEngine; -import eu.siacs.conversations.xmpp.XmppConnection; - import net.java.otr4j.OtrException; import net.java.otr4j.crypto.OtrCryptoEngineImpl; import net.java.otr4j.crypto.OtrCryptoException; @@ -23,13 +20,13 @@ import android.util.Log; public class Conversation extends AbstractEntity { private static final long serialVersionUID = -6727528868973996739L; - + public static final String TABLENAME = "conversations"; - + public static final int STATUS_AVAILABLE = 0; public static final int STATUS_ARCHIVED = 1; public static final int STATUS_DELETED = 2; - + public static final int MODE_MULTI = 1; public static final int MODE_SINGLE = 0; @@ -52,24 +49,26 @@ public class Conversation extends AbstractEntity { private transient List<Message> messages = null; private transient Account account = null; private transient Contact contact; - + private transient SessionImpl otrSession; - + private transient String otrFingerprint = null; - + public int nextMessageEncryption = Message.ENCRYPTION_NONE; private transient MucOptions mucOptions = null; - public Conversation(String name, Account account, - String contactJid, int mode) { - this(java.util.UUID.randomUUID().toString(), name, null, account.getUuid(), contactJid, System - .currentTimeMillis(), STATUS_AVAILABLE,mode); + public Conversation(String name, Account account, String contactJid, + int mode) { + this(java.util.UUID.randomUUID().toString(), name, null, account + .getUuid(), contactJid, System.currentTimeMillis(), + STATUS_AVAILABLE, mode); this.account = account; } public Conversation(String uuid, String name, String contactUuid, - String accountUuid, String contactJid, long created, int status, int mode) { + String accountUuid, String contactJid, long created, int status, + int mode) { this.uuid = uuid; this.name = name; this.contactUuid = contactUuid; @@ -81,33 +80,37 @@ public class Conversation extends AbstractEntity { } public List<Message> getMessages() { - if (messages == null) this.messages = new ArrayList<Message>(); //prevent null pointer - - //populate with Conversation (this) - - for(Message msg : messages) { + if (messages == null) + this.messages = new ArrayList<Message>(); // prevent null pointer + + // populate with Conversation (this) + + for (Message msg : messages) { msg.setConversation(this); } - + return messages; } - + public boolean isRead() { - if ((this.messages == null)||(this.messages.size() == 0)) return true; + if ((this.messages == null) || (this.messages.size() == 0)) + return true; return this.messages.get(this.messages.size() - 1).isRead(); } - + public void markRead() { - if (this.messages == null) return; - for(int i = this.messages.size() -1; i >= 0; --i) { - if (messages.get(i).isRead()) return; + if (this.messages == null) + return; + for (int i = this.messages.size() - 1; i >= 0; --i) { + if (messages.get(i).isRead()) + return; this.messages.get(i).markRead(); } } - + public Message getLatestMessage() { - if ((this.messages == null)||(this.messages.size()==0)) { - Message message = new Message(this,"",Message.ENCRYPTION_NONE); + if ((this.messages == null) || (this.messages.size() == 0)) { + Message message = new Message(this, "", Message.ENCRYPTION_NONE); message.setTime(getCreated()); return message; } else { @@ -119,8 +122,10 @@ public class Conversation extends AbstractEntity { this.messages = msgs; } - public String getName() { - if (this.contact!=null) { + public String getName(boolean useSubject) { + if ((getMode() == MODE_MULTI) && (getMucOptions().getSubject() != null) && useSubject) { + return getMucOptions().getSubject(); + } else if (this.contact != null) { return this.contact.getDisplayName(); } else { return this.name; @@ -128,7 +133,7 @@ public class Conversation extends AbstractEntity { } public String getProfilePhotoString() { - if (this.contact==null) { + if (this.contact == null) { return null; } else { return this.contact.getProfilePhoto(); @@ -138,18 +143,18 @@ public class Conversation extends AbstractEntity { public String getAccountUuid() { return this.accountUuid; } - + public Account getAccount() { return this.account; } - + public Contact getContact() { return this.contact; } - + public void setContact(Contact contact) { this.contact = contact; - if (contact!=null) { + if (contact != null) { this.contactUuid = contact.getUuid(); } } @@ -157,7 +162,7 @@ public class Conversation extends AbstractEntity { public void setAccount(Account account) { this.account = account; } - + public String getContactJid() { return this.contactJid; } @@ -172,7 +177,7 @@ public class Conversation extends AbstractEntity { public int getStatus() { return this.status; } - + public long getCreated() { return this.created; } @@ -186,7 +191,7 @@ public class Conversation extends AbstractEntity { values.put(CONTACTJID, contactJid); values.put(CREATED, created); values.put(STATUS, status); - values.put(MODE,mode); + values.put(MODE, mode); return values; } @@ -212,18 +217,20 @@ public class Conversation extends AbstractEntity { public void setMode(int mode) { this.mode = mode; } - + public void startOtrSession(Context context, String presence) { - Log.d("xmppService","starting otr session with "+presence); - SessionID sessionId = new SessionID(this.getContactJid(),presence,"xmpp"); - this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine(context)); + Log.d("xmppService", "starting otr session with " + presence); + SessionID sessionId = new SessionID(this.getContactJid(), presence, + "xmpp"); + this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine( + context)); try { this.otrSession.startSession(); } catch (OtrException e) { - Log.d("xmppServic","couldnt start otr"); + Log.d("xmppServic", "couldnt start otr"); } } - + public SessionImpl getOtrSession() { return this.otrSession; } @@ -231,9 +238,9 @@ public class Conversation extends AbstractEntity { public void resetOtrSession() { this.otrSession = null; } - + public void endOtrIfNeeded() { - if (this.otrSession!=null) { + if (this.otrSession != null) { if (this.otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) { try { this.otrSession.endSession(); @@ -257,32 +264,34 @@ public class Conversation extends AbstractEntity { return true; } } - + public String getOtrFingerprint() { if (this.otrFingerprint == null) { try { - DSAPublicKey remotePubKey = (DSAPublicKey) getOtrSession().getRemotePublicKey(); - StringBuilder builder = new StringBuilder(new OtrCryptoEngineImpl().getFingerprint(remotePubKey)); + DSAPublicKey remotePubKey = (DSAPublicKey) getOtrSession() + .getRemotePublicKey(); + StringBuilder builder = new StringBuilder( + new OtrCryptoEngineImpl().getFingerprint(remotePubKey)); builder.insert(8, " "); builder.insert(17, " "); builder.insert(26, " "); builder.insert(35, " "); this.otrFingerprint = builder.toString(); } catch (OtrCryptoException e) { - + } } return this.otrFingerprint; } - + public MucOptions getMucOptions() { if (this.mucOptions == null) { this.mucOptions = new MucOptions(); } this.mucOptions.setConversation(this); - return this.mucOptions ; + return this.mucOptions; } - + public void resetMucOptions() { this.mucOptions = null; } diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java index 9bc6fb21..16d9c6a8 100644 --- a/src/eu/siacs/conversations/entities/MucOptions.java +++ b/src/eu/siacs/conversations/entities/MucOptions.java @@ -77,6 +77,7 @@ public class MucOptions { private int error = 0; private OnRenameListener renameListener = null; private User self = new User(); + private String subject = null; public void deleteUser(String name) { @@ -186,4 +187,12 @@ public class MucOptions { public User getSelf() { return self; } + + public void setSubject(String content) { + this.subject = content; + } + + public String getSubject() { + return this.subject; + } }
\ No newline at end of file |